Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support computed properties downlevel #1840

Closed
JsonFreeman opened this issue Jan 28, 2015 · 2 comments
Closed

Support computed properties downlevel #1840

JsonFreeman opened this issue Jan 28, 2015 · 2 comments
Assignees
Labels
Fixed A PR has been merged for this issue In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@JsonFreeman
Copy link
Contributor

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.

@JsonFreeman JsonFreeman added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Jan 28, 2015
@mhegazy mhegazy added this to the TypeScript 1.5 milestone Jan 30, 2015
@DanielRosenwasser
Copy link
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);

@JsonFreeman
Copy link
Contributor Author

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

@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Feb 23, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants