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
ES6 feature: Let and Const Declaration #1065
Comments
Note that Esprima is always able to parse |
@ikarienator Just to confirm, there is also this grammar:
Does this mean that the code like |
That example is valid but does not fall into that production. It falls into: for ( ForDeclaration[?Yield] in Expression[In, ?Yield] ) Statement[?Yield, ?Return] The lookahead is for disambiguous. |
Ah you're right. And technically it's not even a |
This is mostly renaming so that the terms are aligned with the spec: ConstLetDeclaration -> LexicalDeclaration SourceElement -> StatementListItem sourceElement -> statement, sourceElements -> body Refs jquery#1065
Also, to make it explicit, constructing a lexical declaration (const or let) is separated from the common variable declaration (var). Refs jquery#1065
How about |
Weirdly enough, it is allowed. The semantics is that it can only be assigned once. I think the spec should clarify it more on in what occasion it could be used. https://people.mozilla.org/~jorendorff/es6-draft.html#sec-for-statement-runtime-semantics-labelledevaluation |
Let's keep it invalid for now, until there is a better clarification. Now with that, please review this PR #1076 @ikarienator 😉 |
No clarification needed. It should definitely be allowed. |
I meant the clarification on the use case. The definition is clear.
|
This is mostly renaming so that the terms are aligned with the spec: ConstLetDeclaration -> LexicalDeclaration SourceElement -> StatementListItem sourceElement -> statement, sourceElements -> body Refs jquery#1065
Also, to make it explicit, constructing a lexical declaration (const or let) is separated from the common variable declaration (var). Refs jquery#1065
Tasks in this ticket have been implemented. Further enhancements and more early errors will be filed separately. |
Syntax:
Per Rev 32 (Feb 2, 2015) of the draft spec, the relevant grammar is on Section 13.2.1 on Let and Const Declarations:
Referred to by:
Declaration:
StatementListItem:
Iteration:
whereas:
Early errors:
const x;
(from Esprima 1.x)for (let x,y in z){}
for (const x,y in z){}
for (let i = 1 in x){}
for (const i = 1 in x){}
Spec:
13.2.1 Let and Const Declarations.
Relevant AST interfaces (from https://github.com/estree/estree):
See also
Note that V8 doesn't yet support various early errors for lexical declarations. In the mean time, we may need to use the generic
Unexpected token...
message for such an error.The text was updated successfully, but these errors were encountered: