Closed
Description
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"]);