In ES6, what is the meaning of the parameter [Yield], [In] in a grammar production

Brendan Eich brendan at
Mon Mar 9 20:05:42 UTC 2015

Coolwust wrote:
> I have one more question, why `yield` and `in` keywords are so 
> special? When can I treat `yield` and `in` as the non-reserved-word?

You can't treat `in` as an unreserved identifier, in any event. It has 
been reserved since JS1 in 1995, de-jure in ECMA-262 Edition 1 (ES1).

These are different, their histories differ. ES6 (after ES4 but without 
opt-in versioning) supports `yield` in generator functions but not 
elsewhere, because extant code on the Web over the last almost-20-years 
uses `yield` as an identifier in plain functions and/or global code.

`in` needs special treatment due to the ES3 grammatical ambiguity that 
would otherwise allow two ways of parsing the left sentential form `for 
(var x = y in z ...` (where the ... is meta). ECMA-262 aspires to 
specify an LR(1) grammar with lookahead restrictions and error 
correction procedures such as ASI. Allowing `in` expressions in variable 
intiialisers at the front of `for` loops would make the grammar not 
LR(k) for any k. (The potential ambiguity arose first in ES3 because 
that was when the `in` operator was added.)


More information about the es-discuss mailing list