Skip to content

Support computed properties downlevel #1840

Closed

Description

We can emit computed properties in ES5, using the following scheme:

var x = {
    a: 0,
    ["b"]: 0,
    ["c"]() {},
    get ["d"]() { return 0 },
    set ["d"](x) {},
    e: 0
};

emits as:

var x = {
    a: 0
};
x["b"]: 0;
x["c"] = function() {};
Object.defineProperty(x, "d" ...);
Object.defineProperty(x, "d" ...);
x.e = 0;

In any other expression context, we would emit a temp variable like we do for destructuring.

Activity

  1. added
    Suggestion
    In Discussion
    on Jan 28, 2015
  2. DanielRosenwasser commented on Jan 30, 2015

    @DanielRosenwasser
    Member

    I dunno about that emit - what about this?

    var x = { ["abc"]: 10 },
        y = (x = undefined, 10);

    I think we'll have to do something like the following:

    var x = (x = { }, x["abc"] = 10, x),
        y = (x = undefined, 10);
  3. JsonFreeman commented on Jan 30, 2015

    @JsonFreeman
    ContributorAuthor

    Yeah, when there are multiple variable declarations in the same variable statement, we would have to do that.

  4. added
    Fixed
    on Feb 23, 2015
  5. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

FixedIn DiscussionSuggestion

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions