Skip to content

Commit 47f3319

Browse files
committed
Improve rest/spread emit for symbols
Previously, symbols were not handled.
1 parent b9fa06f commit 47f3319

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/compiler/emitter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {
3838
s = arguments[i];
3939
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
4040
t[p] = s[p];
41+
if (typeof Object.getOwnPropertySymbols === "function")
42+
for (var i = 0, s = Object.getOwnPropertySymbols(s); i < s.length; i++)
43+
t[i] = s[i];
4144
}
4245
return t;
4346
};`;
@@ -47,6 +50,9 @@ var __rest = (this && this.__rest) || function (s, e) {
4750
var t = {};
4851
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4952
t[p] = s[p];
53+
if (typeof Object.getOwnPropertySymbols === "function")
54+
for (var i = 0, s = Object.getOwnPropertySymbols(s); i < s.length; i++) if (e.indexOf(s[i]) > 0)
55+
t[i] = s[i];
5056
return t;
5157
};`;
5258

src/compiler/transformers/destructuring.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,14 @@ namespace ts {
428428
}
429429
if (isComputedPropertyName(getPropertyName(element))) {
430430
// get the temp name and put that in there instead, like `_tmp + ""`
431-
propertyNames.push(createBinary(computedTempVariables.shift(), SyntaxKind.PlusToken, createLiteral("")));
431+
const temp = computedTempVariables.shift();
432+
propertyNames.push(createConditional(createBinary(createTypeOf(temp),
433+
SyntaxKind.EqualsEqualsEqualsToken,
434+
createLiteral("symbol")),
435+
createToken(SyntaxKind.QuestionToken),
436+
temp,
437+
createToken(SyntaxKind.ColonToken),
438+
createBinary(temp, SyntaxKind.PlusToken, createLiteral(""))));
432439
}
433440
else {
434441
const propName = getTextOfPropertyName(getPropertyName(element));

0 commit comments

Comments
 (0)