Improve rest/spread emit for symbols

Previously, symbols were not handled.
This commit is contained in:
Nathan Shively-Sanders 2016-11-15 10:58:33 -08:00
parent b9fa06f90b
commit 47f331926e
2 changed files with 14 additions and 1 deletions

View File

@ -38,6 +38,9 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
if (typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, s = Object.getOwnPropertySymbols(s); i < s.length; i++)
t[i] = s[i];
}
return t;
};`;
@ -47,6 +50,9 @@ 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) < 0)
t[p] = s[p];
if (typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, s = Object.getOwnPropertySymbols(s); i < s.length; i++) if (e.indexOf(s[i]) > 0)
t[i] = s[i];
return t;
};`;

View File

@ -428,7 +428,14 @@ namespace ts {
}
if (isComputedPropertyName(getPropertyName(element))) {
// get the temp name and put that in there instead, like `_tmp + ""`
propertyNames.push(createBinary(computedTempVariables.shift(), SyntaxKind.PlusToken, createLiteral("")));
const temp = computedTempVariables.shift();
propertyNames.push(createConditional(createBinary(createTypeOf(temp),
SyntaxKind.EqualsEqualsEqualsToken,
createLiteral("symbol")),
createToken(SyntaxKind.QuestionToken),
temp,
createToken(SyntaxKind.ColonToken),
createBinary(temp, SyntaxKind.PlusToken, createLiteral(""))));
}
else {
const propName = getTextOfPropertyName(getPropertyName(element));