MCPcopy Index your code
hub / github.com/nodejs/node / visitObjectLiteralExpression

Function visitObjectLiteralExpression

test/fixtures/snapshot/typescript.js:96733–96772  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

96731 return objects;
96732 }
96733 function visitObjectLiteralExpression(node) {
96734 if (node.transformFlags & 32768 /* TransformFlags.ContainsObjectRestOrSpread */) {
96735 // spread elements emit like so:
96736 // non-spread elements are chunked together into object literals, and then all are passed to __assign:
96737 // { a, ...o, b } => __assign(__assign({a}, o), {b});
96738 // If the first element is a spread element, then the first argument to __assign is {}:
96739 // { ...o, a, b, ...o2 } => __assign(__assign(__assign({}, o), {a, b}), o2)
96740 //
96741 // We cannot call __assign with more than two elements, since any element could cause side effects. For
96742 // example:
96743 // var k = { a: 1, b: 2 };
96744 // var o = { a: 3, ...k, b: k.a++ };
96745 // // expected: { a: 1, b: 1 }
96746 // If we translate the above to `__assign({ a: 3 }, k, { b: k.a++ })`, the `k.a++` will evaluate before
96747 // `k` is spread and we end up with `{ a: 2, b: 1 }`.
96748 //
96749 // This also occurs for spread elements, not just property assignments:
96750 // var k = { a: 1, get b() { l = { z: 9 }; return 2; } };
96751 // var l = { c: 3 };
96752 // var o = { ...k, ...l };
96753 // // expected: { a: 1, b: 2, z: 9 }
96754 // If we translate the above to `__assign({}, k, l)`, the `l` will evaluate before `k` is spread and we
96755 // end up with `{ a: 1, b: 2, c: 3 }`
96756 var objects = chunkObjectLiteralElements(node.properties);
96757 if (objects.length && objects[0].kind !== 205 /* SyntaxKind.ObjectLiteralExpression */) {
96758 objects.unshift(factory.createObjectLiteralExpression());
96759 }
96760 var expression = objects[0];
96761 if (objects.length > 1) {
96762 for (var i = 1; i < objects.length; i++) {
96763 expression = emitHelpers().createAssignHelper([expression, objects[i]]);
96764 }
96765 return expression;
96766 }
96767 else {
96768 return emitHelpers().createAssignHelper(objects);
96769 }
96770 }
96771 return ts.visitEachChild(node, visitor, context);
96772 }
96773 function visitExpressionStatement(node) {
96774 return ts.visitEachChild(node, visitorWithUnusedExpressionResult, context);
96775 }

Callers 2

visitorWorkerFunction · 0.85

Calls 8

emitHelpersFunction · 0.85
addObjectLiteralMembersFunction · 0.85
declareLocalFunction · 0.85
emitAssignmentFunction · 0.85
unshiftMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected