Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
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.