Merge pull request #16767 from Yogu/patch-2

Add missing visitNode call to object literal members
This commit is contained in:
Ron Buckton 2017-08-23 17:26:31 -07:00 committed by GitHub
commit 40f9ee4b02
5 changed files with 92 additions and 3 deletions

View file

@ -158,8 +158,8 @@ namespace ts {
return visitEachChild(node, visitor, context);
}
function chunkObjectLiteralElements(elements: ReadonlyArray<ObjectLiteralElement>): Expression[] {
let chunkObject: (ShorthandPropertyAssignment | PropertyAssignment)[];
function chunkObjectLiteralElements(elements: ReadonlyArray<ObjectLiteralElementLike>): Expression[] {
let chunkObject: ObjectLiteralElementLike[];
const objects: Expression[] = [];
for (const e of elements) {
if (e.kind === SyntaxKind.SpreadAssignment) {
@ -179,7 +179,7 @@ namespace ts {
chunkObject.push(createPropertyAssignment(p.name, visitNode(p.initializer, visitor, isExpression)));
}
else {
chunkObject.push(e as ShorthandPropertyAssignment);
chunkObject.push(visitNode(e, visitor, isObjectLiteralElementLike));
}
}
}

View file

@ -0,0 +1,26 @@
//// [objectSpreadWithinMethodWithinObjectWithSpread.ts]
const obj = {};
const a = {
...obj,
prop() {
return {
...obj,
metadata: 213
};
}
};
//// [objectSpreadWithinMethodWithinObjectWithSpread.js]
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var obj = {};
var a = __assign({}, obj, { prop: function () {
return __assign({}, obj, { metadata: 213 });
} });

View file

@ -0,0 +1,24 @@
=== tests/cases/compiler/objectSpreadWithinMethodWithinObjectWithSpread.ts ===
const obj = {};
>obj : Symbol(obj, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 0, 5))
const a = {
>a : Symbol(a, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 1, 5))
...obj,
>obj : Symbol(obj, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 0, 5))
prop() {
>prop : Symbol(prop, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 2, 11))
return {
...obj,
>obj : Symbol(obj, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 0, 5))
metadata: 213
>metadata : Symbol(metadata, Decl(objectSpreadWithinMethodWithinObjectWithSpread.ts, 5, 19))
};
}
};

View file

@ -0,0 +1,29 @@
=== tests/cases/compiler/objectSpreadWithinMethodWithinObjectWithSpread.ts ===
const obj = {};
>obj : {}
>{} : {}
const a = {
>a : { prop(): { metadata: number; }; }
>{ ...obj, prop() { return { ...obj, metadata: 213 }; }} : { prop(): { metadata: number; }; }
...obj,
>obj : {}
prop() {
>prop : () => { metadata: number; }
return {
>{ ...obj, metadata: 213 } : { metadata: number; }
...obj,
>obj : {}
metadata: 213
>metadata : number
>213 : 213
};
}
};

View file

@ -0,0 +1,10 @@
const obj = {};
const a = {
...obj,
prop() {
return {
...obj,
metadata: 213
};
}
};