Skip to content

Object rest issue with computed property names #12228

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

Closed
rbuckton opened this issue Nov 14, 2016 · 1 comment
Closed

Object rest issue with computed property names #12228

rbuckton opened this issue Nov 14, 2016 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@rbuckton
Copy link
Contributor

TypeScript Version: 2.2.0-dev.20161114

When emitting Object Rest in --target es5 with a binding or assignment pattern containing a computed property name, we emit "undefined" instead of the value of the computed property name converted to a string. As a result, the e.indexOf(p) check results in a false negative in the __rest helper. NOTE: we must ensure the value of the computed property we pass to __rest is converted to a string otherwise e.indexOf(p) will still result in a false negative.

Also, !e.indexOf(p) is wrong, see #12227 for details.

Code

const x = 1;
const { [x]: a, ...b } = { 1: "a", 2: "b" };

Expected emit:

var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !~e.indexOf(p))
        t[p] = s[p];
    return t;
};
var x = 1;
var _a = { 1: "a", 2: "b" }, _b = x, a = _a[_b], b = __rest(_a, [_b + ""]);

Actual emit:

var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !e.indexOf(p))
        t[p] = s[p];
    return t;
};
var x = 1;
var _a = { 1: "a", 2: "b" }, _b = x, a = _a[_b], b = __rest(_a, ["undefined"]);
@mhegazy mhegazy added the Bug A bug in TypeScript label Nov 14, 2016
@sandersn sandersn added this to the TypeScript 2.1.3 milestone Nov 14, 2016
@sandersn
Copy link
Member

Fix is up at #12248

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Nov 15, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants