Skip to content

Commit 40f9ee4

Browse files
authored
Merge pull request #16767 from Yogu/patch-2
Add missing visitNode call to object literal members
2 parents 1bae5f2 + 8b4db98 commit 40f9ee4

File tree

5 files changed

+92
-3
lines changed

5 files changed

+92
-3
lines changed

src/compiler/transformers/esnext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ namespace ts {
158158
return visitEachChild(node, visitor, context);
159159
}
160160

161-
function chunkObjectLiteralElements(elements: ReadonlyArray<ObjectLiteralElement>): Expression[] {
162-
let chunkObject: (ShorthandPropertyAssignment | PropertyAssignment)[];
161+
function chunkObjectLiteralElements(elements: ReadonlyArray<ObjectLiteralElementLike>): Expression[] {
162+
let chunkObject: ObjectLiteralElementLike[];
163163
const objects: Expression[] = [];
164164
for (const e of elements) {
165165
if (e.kind === SyntaxKind.SpreadAssignment) {
@@ -179,7 +179,7 @@ namespace ts {
179179
chunkObject.push(createPropertyAssignment(p.name, visitNode(p.initializer, visitor, isExpression)));
180180
}
181181
else {
182-
chunkObject.push(e as ShorthandPropertyAssignment);
182+
chunkObject.push(visitNode(e, visitor, isObjectLiteralElementLike));
183183
}
184184
}
185185
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [objectSpreadWithinMethodWithinObjectWithSpread.ts]
2+
const obj = {};
3+
const a = {
4+
...obj,
5+
prop() {
6+
return {
7+
...obj,
8+
metadata: 213
9+
};
10+
}
11+
};
12+
13+
14+
//// [objectSpreadWithinMethodWithinObjectWithSpread.js]
15+
var __assign = (this && this.__assign) || Object.assign || function(t) {
16+
for (var s, i = 1, n = arguments.length; i < n; i++) {
17+
s = arguments[i];
18+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
19+
t[p] = s[p];
20+
}
21+
return t;
22+
};
23+
var obj = {};
24+
var a = __assign({}, obj, { prop: function () {
25+
return __assign({}, obj, { metadata: 213 });
26+
} });
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/compiler/objectSpreadWithinMethodWithinObjectWithSpread.ts ===
2+
const obj = {};
3+
>obj : Symbol(obj, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 0, 5))
4+
5+
const a = {
6+
>a : Symbol(a, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 1, 5))
7+
8+
...obj,
9+
>obj : Symbol(obj, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 0, 5))
10+
11+
prop() {
12+
>prop : Symbol(prop, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 2, 11))
13+
14+
return {
15+
...obj,
16+
>obj : Symbol(obj, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 0, 5))
17+
18+
metadata: 213
19+
>metadata : Symbol(metadata, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 5, 19))
20+
21+
};
22+
}
23+
};
24+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/objectSpreadWithinMethodWithinObjectWithSpread.ts ===
2+
const obj = {};
3+
>obj : {}
4+
>{} : {}
5+
6+
const a = {
7+
>a : { prop(): { metadata: number; }; }
8+
>{ ...obj, prop() { return { ...obj, metadata: 213 }; }} : { prop(): { metadata: number; }; }
9+
10+
...obj,
11+
>obj : {}
12+
13+
prop() {
14+
>prop : () => { metadata: number; }
15+
16+
return {
17+
>{ ...obj, metadata: 213 } : { metadata: number; }
18+
19+
...obj,
20+
>obj : {}
21+
22+
metadata: 213
23+
>metadata : number
24+
>213 : 213
25+
26+
};
27+
}
28+
};
29+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const obj = {};
2+
const a = {
3+
...obj,
4+
prop() {
5+
return {
6+
...obj,
7+
metadata: 213
8+
};
9+
}
10+
};

0 commit comments

Comments
 (0)