Skip to content

Commit fab1416

Browse files
committed
Fixes for object spread emit
1. Retain function modifiers. They were previously dropped. 2. Do not emit __assign for object literals with no spreads, just visit children. 3. call aggregateTransformFlags after creating an __assign call.
1 parent 0adc76b commit fab1416

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/compiler/transformers/esnext.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,15 @@ namespace ts {
9292
// { a, ...o, b } => __assign({a}, o, {b});
9393
// If the first element is a spread element, then the first argument to __assign is {}:
9494
// { ...o, a, b, ...o2 } => __assign({}, o, {a, b}, o2)
95-
const objects = chunkObjectLiteralElements(node.properties);
96-
if (objects.length && objects[0].kind !== SyntaxKind.ObjectLiteralExpression) {
97-
objects.unshift(createObjectLiteral());
95+
if (forEach(node.properties, p => p.kind === SyntaxKind.SpreadAssignment)) {
96+
const objects = chunkObjectLiteralElements(node.properties);
97+
if (objects.length && objects[0].kind !== SyntaxKind.ObjectLiteralExpression) {
98+
objects.unshift(createObjectLiteral());
99+
}
100+
101+
return aggregateTransformFlags(createCall(createIdentifier("__assign"), undefined, objects));
98102
}
99-
return createCall(createIdentifier("__assign"), undefined, objects);
103+
return visitEachChild(node, visitor, context);
100104
}
101105

102106
/**
@@ -235,7 +239,7 @@ namespace ts {
235239
visitEachChild(node.body, visitor, context);
236240
const func = setOriginalNode(
237241
createArrowFunction(
238-
/*modifiers*/ undefined,
242+
node.modifiers,
239243
/*typeParameters*/ undefined,
240244
visitNodes(node.parameters, visitor, isParameter),
241245
/*type*/ undefined,
@@ -256,7 +260,7 @@ namespace ts {
256260
visitEachChild(node.body, visitor, context);
257261
return setOriginalNode(
258262
createFunctionExpression(
259-
/*modifiers*/ undefined,
263+
node.modifiers,
260264
node.asteriskToken,
261265
name,
262266
/*typeParameters*/ undefined,

0 commit comments

Comments
 (0)