Allen Wirfs-Brock (2013-11-26T01:01:28.000Z)
On Nov 25, 2013, at 4:21 PM, Kevin Smith wrote:

> 
> This makes for wtfjs additions, but they all seem non-wtf on reflection (or did to us when Waldemar threw them up on a whiteboard last week). By non-wtf, I mean anyone who groks that yield is reserved only in function* can work them out.
> 
> The star after function really helps. ES5's "use strict" directive prologue in the body applying to its left (even in ES5 -- duplicate formals are a strict error) is goofy.
> 
> Agree on all counts, but not quite understanding yet.
> 
> 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.

Allen

[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-let-and-const-declarations-static-semantics-early-errors 




> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131125/a7dbd1a0/attachment.html>
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