Skip to content

FR: Allow property setting shorthand (for objects literals) with 'multiple dots' access #301

@ymeine

Description

@ymeine

Hi all,

I like the property setting shorthand feature for object literals, which is (to remind you):

{
    a
    b
    c.x
    c.y
}

compiling to

{
  a: a,
  b: b,
  x: c.x,
  y: c.y
}

However, I've been surprised not being able to do something like:

{
    a.b.c
    x.y.z
}

to compile to

{
    c: a.b.c,
    z: x.y.z
}

as this however seems intuitive: simply take the last part of the property access as the property name, like (whatever-I-do-to-reach-the-value).property, giving property: (whatever-I-do-to-reach-the-value).property.

With a real example:

{
    JSON.parse input .property
}

would give:

{
    property: JSON.parse(input).property
}

FYI, the first non-working example I gave you (with simple multiple dots access) triggers the following error: Parse error on line 2: Unexpected 'DOT'

While the last one gives: Parse error on line 2: Unexpected 'CALL('

Best regards

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