Skip to content

fix(ast): accept every simple target in destructuring assignment patterns - #5596

Closed
andreasrosdal wants to merge 1 commit into
boa-dev:mainfrom
nordstjernen-web:fix/destructuring-assignment-simple-targets
Closed

andreasrosdal wants to merge 1 commit into
boa-dev:mainfrom
nordstjernen-web:fix/destructuring-assignment-simple-targets

Conversation

@andreasrosdal

Copy link
Copy Markdown

It changes the following:

  • ArrayLiteral::to_pattern / ObjectLiteral::to_pattern accept any simple assignment target (via AssignTarget::from_expression_simple), including parenthesized ones: [(a), b] = list, ({ a: (b) } = obj), [...(x)] = list, ({...(o.p)} = obj).
  • eval and arguments are rejected as destructuring targets in strict code ([eval] = list, ({ a: eval } = obj), ({ arguments } = obj), [...eval] = list were accepted).
  • Object patterns accept nested patterns and initializers under computed and numeric keys: ({ [k]: [x] } = obj), ({ 0: x = 1 } = list).
  • An initializer is no longer re-named in to_pattern; it was already named by the assignment parser only when the target is an unparenthesized identifier (IsIdentifierRef), so [(x) = function () {}] = [] no longer names the function x.
  • A parenthesized object/array literal is not a pattern in a for-in/of head: for (([x]) of list); is a SyntaxError.

Spec: AssignmentTargetType and the destructuring assignment early errors. Fixes test262 staging/sm/expressions/destructuring-pattern-parenthesized.js, staging/sm/destructuring/order.js and staging/sm/destructuring/order-super.js. Found while embedding Boa in the Southstar browser.

Tested with a new parser unit test (destructuring_assignment_simple_targets).

🤖 Generated with Claude Code

…erns

A destructuring assignment target that is not an object or array literal
must be a simple assignment target, and a parenthesized identifier or
property access is one. `ArrayLiteral::to_pattern` and
`ObjectLiteral::to_pattern` only knew bare identifiers and property
accesses, so `[(a), b] = list`, `({ a: (b) } = obj)`, `[...(x)] = list`
and `({...(o.p)} = obj)` were rejected. Any other target is now refined
through `AssignTarget::from_expression_simple`, which also rejects `eval`
and `arguments` in strict code (`[eval] = list`, `({ arguments } = obj)`
were accepted). A parenthesized pattern such as `[({a})] = list` stays an
error.

Object patterns also accept nested patterns and initializers under
computed and numeric property names (`({ [k]: [x] } = obj)`,
`({ 0: x = 1 } = list)`). An initializer is named only when its target is
an unparenthesized identifier (IsIdentifierRef), as the assignment parser
already does, so `[(x) = function () {}] = []` no longer names the
function. A parenthesized object or array literal is not a pattern in a
for-in/of head: `for (([x]) of list)` is a syntax error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the Waiting On Review Waiting on reviews from the maintainers label Oct 17, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Oct 17, 2026
@github-actions github-actions Bot added C-Parser Issues surrounding the parser C-Tests Issues and PRs related to the tests. C-AST Issue surrounding the abstract syntax tree labels Oct 17, 2026
@jedel1043 jedel1043 closed this Oct 17, 2026
@github-actions github-actions Bot removed the Waiting On Review Waiting on reviews from the maintainers label Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-AST Issue surrounding the abstract syntax tree C-Parser Issues surrounding the parser C-Tests Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants