You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
in inside an array literal in a for initializer is a syntax error (for (let i = 0, a = [k in o]; β¦))Β #65311
Lines 2 and 6 fail. The same k in o inside an object literal (line 3) or parentheses (line 4) is accepted, as it is in call arguments and template substitutions.
π Expected behavior
No errors. The [~In] of the for head (for ( LexicalDeclaration[~In] Expression[+In]opt ; β¦), for ( Expression[~In]opt ; β¦), https://tc39.es/ecma262/#sec-for-statement) does not reach into array literals: ElementList : AssignmentExpression[+In] (https://tc39.es/ecma262/#sec-array-initializer), the same as for object literal property values. In the for-of case the array literal is an ArrayAssignmentPattern, whose Initializer[+In] also allows in. node accepts the file; for (let i = 0, has = [k in o]; i < 1; i++) console.log(has); prints [ true ].
Additional information about the issue
parseArrayLiteralExpression in internal/parser/parser.go parses its elements in the caller's context, so NodeFlagsDisallowInContext from the for initializer is still set. parseArgumentExpression already clears it for call arguments. Clearing it for the element list fixes both lines:
Activity
MartinJohns commentedon Nov 4, 2026
Why would you ever write code like this?
trackoor commentedon Nov 4, 2026
I found this while checking the parser against our own parser impl & test262. It is an uncommon pattern tho.