Repository navigation
Reject a for-of left-hand side that starts with let - #900
Merged
Merged
Conversation
for (let.x of []) should be a SyntaxError: the grammar has a
[lookahead ∉ { let, async of }] restriction on the LeftHandSideExpression
of a for-of head, so an expression that starts with the let token can't
be followed by "of". Only the declaration form was rejected, e.g.
for (let of []), while for (let.x of []) and for (let().x of []) were
accepted.
Report an error when the expression in a for-of head starts with let.
Parenthesized forms such as for ((let).x of []) and for-in heads such as
for (let.x in {}) are still valid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
for (let.x of [])should throw a SyntaxError. The for-of grammar has a[lookahead ∉ { let, async of }]restriction on theLeftHandSideExpression, so an expression that starts with thelettoken can't be followed byof. goja only rejected the form that's parsed as a declaration (for (let of [])), and acceptedfor (let.x of []),for (let().x of [])andfor (let.x.y of [])in non-strict code, including infor await. V8 throwsSyntaxError: The left-hand side of a for-of loop may not start with 'let'.for all of them.parseForOrForInStatementnow remembers whether the expression in the head starts withlet, and reports the error at thelettoken when it's followed byof. These still parse, matching V8:for ((let).x of []),for ((let) of []),for await ((let).x of [])for (let.x in {}),for (let().x in {}),for (let.x;;);test262 only has
for ( let of [] )for this (head-lhs-let.js, already passing), so the tc39 results don't change. The new cases are inTestParserErr.