Skip to content

Assignment destructuring: nested pattern WITH a default ([[a] = []]) is unsupported #779

@nickna

Description

@nickna

Summary

Introduced alongside #754 (assignment destructuring). A nested array/object pattern that itself carries a default in an assignment destructuring is rejected:

let a;
[[a] = []] = [[1]];        // Parse Error: Nested destructuring with a default is not supported in assignment destructuring.
({ p: { x } = {} } = { p: { x: 1 } });

Simpler forms all work: [[a], b] = [[1], 2] (nested, no default), [a = 5] = [] (leaf default), [obj.x = 5] = arr (member default).

Cause

[a] = [] inside the outer pattern is eagerly parsed by Assignment() as an Expr.DestructuringAssign (the inner is lowered to statements), so when the outer pattern walk in Parser.Destructuring.cs (LowerElementWithDefault) encounters it, the inner pattern's raw target/default are no longer recoverable. SharpTS has no cover grammar, so the inner cannot be reinterpreted as "nested pattern + default".

Fix shape

Either keep an un-lowered raw (target, value) on DestructuringAssign for re-interpretation when it appears as a nested element, or add a cover-grammar reparse for the LHS of =. The walk already handles every other element kind (leaf, member, leaf-default, member-default, nested-no-default, rest, holes).

Scope

Rare in practice. The current behavior is a clear parse error (not a miscompile).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions