New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should arrow functions allow `yield` as identifier name in StrictFormalParameters? #397

Closed
ianwjhalliday opened this Issue Feb 18, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@ianwjhalliday

ianwjhalliday commented Feb 18, 2016

Currently arrow functions pass along the Yield parameter to their parameter list grammar production, making yield a reserved word in that context.

However, function expressions do not pass the Yield parameter along to their FormalParameters production.

Corner case but seems an odd asymmetry.

@michaelficarra

This comment has been minimized.

Show comment
Hide comment
@michaelficarra

michaelficarra Feb 22, 2016

Member

Currently, 14.2.1 defines an early error that disallows _YieldExpression_s in ArrowParameters.

It is a Syntax Error if ArrowParameters Contains YieldExpression is true.

So the only difference this grammar change would make would be allowing yield used as an identifier in ArrowParameters (or conversely disallowing yield used as an identifier in FormalParameters, but that would be web incompatible). 👍 let's drop the flag from ArrowParameters.

Member

michaelficarra commented Feb 22, 2016

Currently, 14.2.1 defines an early error that disallows _YieldExpression_s in ArrowParameters.

It is a Syntax Error if ArrowParameters Contains YieldExpression is true.

So the only difference this grammar change would make would be allowing yield used as an identifier in ArrowParameters (or conversely disallowing yield used as an identifier in FormalParameters, but that would be web incompatible). 👍 let's drop the flag from ArrowParameters.

@anba

This comment has been minimized.

Show comment
Hide comment
@anba

anba Feb 22, 2016

Contributor

Even when [Yield] gets removed, yield still cannot be used as the name of an arrow function default parameter in a generator function context.

function* g() {
  // Default parameters cannot be named "yield", because `yield = 0`
  // is initially parsed as an assignment expression.
  var f = (yield = 0) => {};
}

And removing [Yield] probably also complicates correctly reinterpreting CoverParenthesizedExpressionAndArrowParameterList as ArrowFormalParameters:

function* g() {
  // Lexical token sequence for `yield/a/i` is `YIELD REGEXP`.
  // When CoverParenthesizedExpressionAndArrowParameterList is reinterpreted/reparsed
  // as ArrowFormalParameters, the lexer/parser is not allowed to change this to the
  // token sequence `YIELD DIV IDENT DIV IDENT`.
  var f = (p = yield/a/i) => {};
}
Contributor

anba commented Feb 22, 2016

Even when [Yield] gets removed, yield still cannot be used as the name of an arrow function default parameter in a generator function context.

function* g() {
  // Default parameters cannot be named "yield", because `yield = 0`
  // is initially parsed as an assignment expression.
  var f = (yield = 0) => {};
}

And removing [Yield] probably also complicates correctly reinterpreting CoverParenthesizedExpressionAndArrowParameterList as ArrowFormalParameters:

function* g() {
  // Lexical token sequence for `yield/a/i` is `YIELD REGEXP`.
  // When CoverParenthesizedExpressionAndArrowParameterList is reinterpreted/reparsed
  // as ArrowFormalParameters, the lexer/parser is not allowed to change this to the
  // token sequence `YIELD DIV IDENT DIV IDENT`.
  var f = (p = yield/a/i) => {};
}
@ianwjhalliday

This comment has been minimized.

Show comment
Hide comment
@ianwjhalliday

ianwjhalliday Feb 23, 2016

@anba ah, there's the gotcha with arrow functions! Thanks for pointing that out. I see the need for the asymmetry now.

ianwjhalliday commented Feb 23, 2016

@anba ah, there's the gotcha with arrow functions! Thanks for pointing that out. I see the need for the asymmetry now.

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