For AI agents: the complete documentation index is available at /tc39-atlas/en/llms.txt, the full documentation bundle is available at /tc39-atlas/en/llms-full.txt, and this page is available as Markdown at /tc39-atlas/en/proposals/year/pending/proposal-shorthand-improvements.md.
  • English
  • Object Shorthand Improvements S0

    Proposal details
    Proposal overview

    This proposal aims to extend object shorthand syntax in both object initializers and destructuring assignments to support property accessors. Currently, shorthand assignments only allow identifiers, but this proposal would permit expressions like { o.x } and ({ a.x } = o).

    Note

    The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.

    ECMAScript Shorthand Property Assignment Improvements

    This proposal introduces new forms of shorthand assignments for both object literal initializers and object assignment patterns, allowing the use of property accessors in addition to identifiers for shorthand assignments.

    Status

    Stage: 0
    Champion: Ron Buckton (@rbuckton)

    For more information see the TC39 proposal process.

    Authors

    • Ron Buckton (@rbuckton)

    Proposal

    Object Initializers

    When property accessors are used in an object initializer, the property name of the accessor is used as the property name of the object and the value of property accessor is used as the value of the property in the object. This is illustrated by the following syntactic conversion:

    const a = { o.x };

    is identical in its behavior to:

    const a = { x: o.x };

    In addition to the dot notation for property access, bracket notation can be used as well. As with the dot notation, the expression of the bracket notation is used as the property name of the object. This is illustrated by the following syntactic conversion:

    const a = { o["x"] };

    is (roughly) identical in its behavior to:

    const a = { ["x"]: o["x"] };

    Note that rather than duplicating the expression "x" above, the actual implementation will rely on GetReferencedName.

    Destructuring Assignments

    When property accessors are used in a destructuring assignment, the property name of the accessor is used as the property name for the assignment property, while the property accessor itself is used as the assignment target. This is illustrated by the following syntactic conversion:

    ({ a.x } = o);

    is identical in its behavior to:

    ({ x: a.x } = o);

    In addition to the dot notation, bracket notation can be used here as well. When the bracket notation is used, the expression of the bracket notation is evaluated and used as the property name of the assignment property, while the property accessor itself is used as the assignment target. This is illustrated by the following syntactic conversion:

    ({ a["x"] } = o);

    is (roughly) identical in its behavior to:

    ({ ["x"]: a["x"] } = o);

    Note that rather than duplicating the expression "x" above, the actual implementation will rely on GetReferencedName.

    Grammar

    PropertyDefinition[Yield, Await]:
        MemberExpression[?Yield, ?Await] `.` IdentifierName
        MemberExpression[?Yield, ?Await] `[` Expression `]`
        CallExpression[?Yield, ?Await] `.` IdentifierName
        CallExpression[?Yield, ?Await] `[` Expression `]`
        ...
    
    AssignmentProperty[Yield, Await]:
        MemberExpression[?Yield, ?Await] `.` IdentifierName Initializer[+In, ?Yield, ?Await]?
        MemberExpression[?Yield, ?Await] `[` Expression `]` Initializer[+In, ?Yield, ?Await]?
        CallExpression[?Yield, ?Await] `.` IdentifierName Initializer[+In, ?Yield, ?Await]?
        CallExpression[?Yield, ?Await] `[` Expression `]` Initializer[+In, ?Yield, ?Await]?

    Resources

    TODO

    The following is a high-level list of tasks to progress through each stage of the TC39 proposal process:

    Stage 1 Entrance Criteria

    • Identified a "champion" who will advance the addition.
    • Prose outlining the problem or need and the general shape of a solution.
    • Illustrative examples of usage.
    • High-level API (proposal does not introduce an API).

    Stage 2 Entrance Criteria

    Stage 3 Entrance Criteria

    Stage 4 Entrance Criteria

    • Test262 acceptance tests have been written for mainline usage scenarios and merged.
    • Two compatible implementations which pass the acceptance tests: [1], [2].
    • A pull request has been sent to tc39/ecma262 with the integrated spec text.
    • The ECMAScript editor has signed off on the pull request.