Skip to content

Commit f5bcaa3

Browse files
ahejlsbergmhegazy
authored andcommitted
Emit [...a] as a.slice() to ensure a is copied
1 parent 79ab85e commit f5bcaa3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/compiler/emitter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
13661366
return true;
13671367
}
13681368

1369-
function emitListWithSpread(elements: Expression[], multiLine: boolean, trailingComma: boolean) {
1369+
function emitListWithSpread(elements: Expression[], alwaysCopy: boolean, multiLine: boolean, trailingComma: boolean) {
13701370
let pos = 0;
13711371
let group = 0;
13721372
let length = elements.length;
@@ -1383,6 +1383,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
13831383
e = (<SpreadElementExpression>e).expression;
13841384
emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e));
13851385
pos++;
1386+
if (pos === length && group === 0 && alwaysCopy) {
1387+
write(".slice()");
1388+
}
13861389
}
13871390
else {
13881391
let i = pos;
@@ -1422,7 +1425,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14221425
write("]");
14231426
}
14241427
else {
1425-
emitListWithSpread(elements, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0,
1428+
emitListWithSpread(elements, /*alwaysCopy*/ true, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0,
14261429
/*trailingComma*/ elements.hasTrailingComma);
14271430
}
14281431
}
@@ -1847,7 +1850,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
18471850
write("void 0");
18481851
}
18491852
write(", ");
1850-
emitListWithSpread(node.arguments, /*multiLine*/ false, /*trailingComma*/ false);
1853+
emitListWithSpread(node.arguments, /*alwaysCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false);
18511854
write(")");
18521855
}
18531856

0 commit comments

Comments
 (0)