8000 Reject a for-of left-hand side that starts with let by LuisFigueroaG · Pull Request #900 · dop251/goja · GitHub
[go: up one dir, main page]

Skip to content

Reject a for-of left-hand side that starts with let - #900

Merged
dop251 merged 1 commit into
dop251:masterfrom
LuisFigueroaG:fix/for-of-let-lookahead
Nov 27, 2026
Merged

dop251 merged 1 commit into
dop251:masterfrom
LuisFigueroaG:fix/for-of-let-lookahead

Conversation

@LuisFigueroaG
Copy link
Copy Markdown
Contributor

for (let.x of []) should throw a SyntaxError. The for-of grammar has a [lookahead ∉ { let, async of }] restriction on the LeftHandSideExpression, so an expression that starts with the let token can't be followed by of. goja only rejected the form that's parsed as a declaration (for (let of [])), and accepted for (let.x of []), for (let().x of []) and for (let.x.y of []) in non-strict code, including in for await. V8 throws SyntaxError: The left-hand side of a for-of loop may not start with 'let'. for all of them.

parseForOrForInStatement now remembers whether the expression in the head starts with let, and reports the error at the let token when it's followed by of. These still parse, matching V8:

  • parenthesized: for ((let).x of []), for ((let) of []), for await ((let).x of [])
  • for-in and plain for heads: 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 in TestParserErr.

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.
@dop251
dop251 merged commit 516d13c into dop251:master Nov 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0