Allen Wirfs-Brock (2013-11-26T01:01:28.000Z)
domenic at domenicdenicola.com (2013-12-10T01:15:01.628Z)
On Nov 25, 2013, at 4:21 PM, Kevin Smith wrote: > Say I'm parsing this, and the token stream is paused at the "#": > > function(a = # yield > > I assume that we're not un-reserving yield in strict mode. That means that I don't know whether to treat `yield` as an identifier or reserved word until I get to that goofy prologue. > > Previously, I've just naively parsed parameter initializers using the same strictness as the code which contains the function. Here is a simplified explanation of how it actually works in the specification: 1. `yield` is a reserved keyword at the level of the lexical grammar [1]. This applies to both strict and non-strict mode. 2. The GeneratorDeclaration and GeneratorExpression productions includes the [Yield] grammar parameter on their RHS FormalParameter and FunctionBody nonterminals. [2] This parameterization makes 'yield' legal as an AssignmentExpression operator [3]. That use of 'yield' is only enabled within generator definitions and is independent of the strictness. 3. When the [Yield] parameter is not present, the 'yield' keyword is one of the expansions of the IdentifierReference (via UnresolvedIdentifier) [4] and BindingIdentifier[5] productions. This permits 'yield' to be appear outside of Generator definitions in any syntactically allowed identifier position. Again, this is independent of strictness. 4. There are static semantic early error rules [6], [7] that require an error if 'yield' actually shows up in an IdentiferReference or IdentiferBinding expansion within strict code. [1]: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-keywords [2]: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-generator-function-definitions [3]: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-assignment-operators [4]: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-identifier-reference [5]: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-let-and-const-declarations [6]:http://people.mozilla.org/~jorendorff/es6-draft.html#sec-identifier-reference-static-semantics-early-errors [7]: http://people.mozilla.org/~jorendorff/es6-draft.html#sec