The following code ...
Suppose the output is inside a generator function and that something and else defined, etc.
const value = something || yield else();
... produces the following in V8 (Chrome or Nodejs):
const start = initial || yield wait(); ^^^^^ SyntaxError: Unexpected strict mode reserved word
... and this is in Firefox:
SyntaxError: yield is a reserved identifier
I first noticed this in the bluebird coroutine I wrote. The fix is ββto wrap yield wait() in parentheses.
This error occurs during parsing, not at runtime; therefore, my first assumption is that this is because there is syntactic ambiguity. I looked at the yield keyword , which defines it as:
[rv] = yield [expression];
yield takes an expression and returns a value. This does not happen without the || (OR) as const value = yield else(); ; so I looked at the priority of the operator . Operator || (OR) evaluates to 5 before the yield of 2 . Priority looks fine.
It appears that the operator || (OR) requires an expression on both sides, and although I assume yield [expression] is an expression, maybe it is not? Why do I need to wrap this part in parentheses to make it an explicit expression? What could be || yield || yield ambiguous? I'm sure I just missed it; or is there any hidden / deeper reason for this?
This question was also hard to find, so I hope I will not cheat here.
(You can use this Plunker https://plnkr.co/edit/rNidnFuyIOFkRkkcyWRV to make a mistake if you want to see it.)
Thanks!