Create a gist now

Instantly share code, notes, and snippets.

Precedence of `yield` in ES6
// Current ES spec grammar
1 + yield //  error
1 + yield 2 //  error
yield + 1 // yield (+1)
yield 1 + yield 2 // error
yield(1) + yield(2) // error
yield 1 + 2 // yield (1+2)
yield * yield // (yield *) yield
yield + yield // error

// C# await grammar
1 + yield //  1 + (yield)
1 + yield 2 //  1 + (yield 2)
yield + 1 // (yield) + 1
yield 1 + yield 2 // (yield 1) + (yield 2)
yield(1) + yield(2) // (yield(1)) + (yield(2))
yield 1 + 2 // (yield 1) + 2
yield * yield // (yield) * (yield)
yield + yield // (yield) + (yield)

I believe the await style precendence is more expected in all but one case. Certainly a ES7 await would align with the C# precendence. But are we sure that ES6 yield shouldn't also match?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment