Skip to content

Commit 6a82ae4

Browse files
committed
Add SpreadAssignment to visitors
1. visitNode 2. reduceNode 3. emit This fixes an emit bug for setters.
1 parent a84c7ae commit 6a82ae4

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/compiler/emitter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ const _super = (function (geti, seti) {
732732
return emitPropertyAssignment(<PropertyAssignment>node);
733733
case SyntaxKind.ShorthandPropertyAssignment:
734734
return emitShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);
735+
case SyntaxKind.ShorthandPropertyAssignment:
736+
return emitSpreadAssignment(node as SpreadAssignment);
735737

736738
// Enum
737739
case SyntaxKind.EnumMember:
@@ -2102,6 +2104,13 @@ const _super = (function (geti, seti) {
21022104
}
21032105
}
21042106

2107+
function emitSpreadAssignment(node: SpreadAssignment) {
2108+
if (node.expression) {
2109+
write("...");
2110+
emitExpression(node.expression);
2111+
}
2112+
}
2113+
21052114
//
21062115
// Enum
21072116
//

src/compiler/factory.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,14 +1399,27 @@ namespace ts {
13991399
return node;
14001400
}
14011401

1402-
export function updateShorthandPropertyAssignment(node: ShorthandPropertyAssignment, name: Identifier, objectAssignmentInitializer: Expression) {
1402+
export function createSpreadAssignment(expression: Expression, location?: TextRange) {
1403+
const node = <SpreadAssignment>createNode(SyntaxKind.SpreadAssignment, location);
1404+
node.expression = expression !== undefined ? parenthesizeExpressionForList(expression) : undefined;
1405+
return node;
1406+
}
1407+
1408+
export function updateShorthandPropertyAssignment(node: ShorthandPropertyAssignment, name: Identifier, objectAssignmentInitializer: Expression) {
14031409
if (node.name !== name || node.objectAssignmentInitializer !== objectAssignmentInitializer) {
14041410
return updateNode(createShorthandPropertyAssignment(name, objectAssignmentInitializer, node), node);
14051411
}
14061412
return node;
14071413
}
14081414

1409-
// Top-level nodes
1415+
export function updateSpreadAssignment(node: SpreadAssignment, expression: Expression) {
1416+
if (node.expression !== expression) {
1417+
return updateNode(createSpreadAssignment(expression, node), node);
1418+
}
1419+
return node;
1420+
}
1421+
1422+
// Top-level nodes
14101423

14111424
export function updateSourceFileNode(node: SourceFile, statements: Statement[]) {
14121425
if (node.statements !== statements) {

src/compiler/visitor.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ namespace ts {
510510
result = reduceNode((<ShorthandPropertyAssignment>node).objectAssignmentInitializer, f, result);
511511
break;
512512

513+
case SyntaxKind.SpreadAssignment:
514+
result = reduceNode((node as SpreadAssignment).expression, f, result);
515+
break;
516+
513517
// Top-level nodes
514518
case SyntaxKind.SourceFile:
515519
result = reduceLeft((<SourceFile>node).statements, f, result);
@@ -1125,7 +1129,11 @@ namespace ts {
11251129
visitNode((<ShorthandPropertyAssignment>node).name, visitor, isIdentifier),
11261130
visitNode((<ShorthandPropertyAssignment>node).objectAssignmentInitializer, visitor, isExpression));
11271131

1128-
// Top-level nodes
1132+
case SyntaxKind.SpreadAssignment:
1133+
return updateSpreadAssignment(node as SpreadAssignment,
1134+
visitNode((node as SpreadAssignment).expression, visitor, isExpression));
1135+
1136+
// Top-level nodes
11291137
case SyntaxKind.SourceFile:
11301138
context.startLexicalEnvironment();
11311139
return updateSourceFileNode(<SourceFile>node,

tests/baselines/reference/objectSpreadNegative.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ spreadStr.charAt(1); // error, no methods either
123123
var spreadFunc = __assign({}, function () { });
124124
spreadFunc(); // error, no call signature
125125
// write-only properties get skipped
126-
var setterOnly = __assign({ set b(bad: number) { } });
126+
var setterOnly = __assign({ set b(bad) { } });
127127
setterOnly.b = 12; // error, 'b' does not exist
128128
// methods are skipped because they aren't enumerable
129129
var C = (function () {

0 commit comments

Comments
 (0)