Skip to content

Object shorthand-with-default {a = 5} is rejected by the object-literal parser (blocks that form of assignment destructuring) #780

@nickna

Description

@nickna

Summary

The object-literal parser rejects a shorthand property with a default:

let a;
({ a = 5 } = {});      // Parse Error: Expect '}' after object literal.

This is the object-pattern cover-grammar form. Other object assignment-destructuring forms parse and work after #754: shorthand {a}, rename {a: x}, rename+default {a: x = 5}, nested {a: [x]}, rest {...r}, computed {[k]: v}, string-key {"a-b": v}.

Cause

ParseObjectLiteral does not accept = after a shorthand identifier key ({ a = 5 } is only valid as a destructuring pattern, not as an object literal expression). With no cover grammar, the LHS never parses, so the = dispatch in Parser.Expressions.cs is never reached.

Fix shape

Allow shorthand-with-default in the object-literal parser (storing it as { a: (a = 5) } shape, value = Expr.Assign) so it round-trips to the #754 assignment-destructuring lowering (which already handles a {a: x = 5} rename+default). The pure-expression use of {a = 5} remains a semantic error, as in tsc.

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