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

Function visitOptionalExpression

test/fixtures/snapshot/typescript.js:97524–97575  ·  view source on GitHub ↗
(node, captureThisArg, isDelete)

Source from the content-addressed store, hash-verified

97522 }
97523 }
97524 function visitOptionalExpression(node, captureThisArg, isDelete) {
97525 var _a = flattenChain(node), expression = _a.expression, chain = _a.chain;
97526 var left = visitNonOptionalExpression(ts.skipPartiallyEmittedExpressions(expression), ts.isCallChain(chain[0]), /*isDelete*/ false);
97527 var leftThisArg = ts.isSyntheticReference(left) ? left.thisArg : undefined;
97528 var capturedLeft = ts.isSyntheticReference(left) ? left.expression : left;
97529 var leftExpression = factory.restoreOuterExpressions(expression, capturedLeft, 8 /* OuterExpressionKinds.PartiallyEmittedExpressions */);
97530 if (!ts.isSimpleCopiableExpression(capturedLeft)) {
97531 capturedLeft = factory.createTempVariable(hoistVariableDeclaration);
97532 leftExpression = factory.createAssignment(capturedLeft, leftExpression);
97533 }
97534 var rightExpression = capturedLeft;
97535 var thisArg;
97536 for (var i = 0; i < chain.length; i++) {
97537 var segment = chain[i];
97538 switch (segment.kind) {
97539 case 206 /* SyntaxKind.PropertyAccessExpression */:
97540 case 207 /* SyntaxKind.ElementAccessExpression */:
97541 if (i === chain.length - 1 && captureThisArg) {
97542 if (!ts.isSimpleCopiableExpression(rightExpression)) {
97543 thisArg = factory.createTempVariable(hoistVariableDeclaration);
97544 rightExpression = factory.createAssignment(thisArg, rightExpression);
97545 }
97546 else {
97547 thisArg = rightExpression;
97548 }
97549 }
97550 rightExpression = segment.kind === 206 /* SyntaxKind.PropertyAccessExpression */
97551 ? factory.createPropertyAccessExpression(rightExpression, ts.visitNode(segment.name, visitor, ts.isIdentifier))
97552 : factory.createElementAccessExpression(rightExpression, ts.visitNode(segment.argumentExpression, visitor, ts.isExpression));
97553 break;
97554 case 208 /* SyntaxKind.CallExpression */:
97555 if (i === 0 && leftThisArg) {
97556 if (!ts.isGeneratedIdentifier(leftThisArg)) {
97557 leftThisArg = factory.cloneNode(leftThisArg);
97558 ts.addEmitFlags(leftThisArg, 1536 /* EmitFlags.NoComments */);
97559 }
97560 rightExpression = factory.createFunctionCallCall(rightExpression, leftThisArg.kind === 106 /* SyntaxKind.SuperKeyword */ ? factory.createThis() : leftThisArg, ts.visitNodes(segment.arguments, visitor, ts.isExpression));
97561 }
97562 else {
97563 rightExpression = factory.createCallExpression(rightExpression,
97564 /*typeArguments*/ undefined, ts.visitNodes(segment.arguments, visitor, ts.isExpression));
97565 }
97566 break;
97567 }
97568 ts.setOriginalNode(rightExpression, segment);
97569 }
97570 var target = isDelete
97571 ? factory.createConditionalExpression(createNotNullCondition(leftExpression, capturedLeft, /*invert*/ true), /*questionToken*/ undefined, factory.createTrue(), /*colonToken*/ undefined, factory.createDeleteExpression(rightExpression))
97572 : factory.createConditionalExpression(createNotNullCondition(leftExpression, capturedLeft, /*invert*/ true), /*questionToken*/ undefined, factory.createVoidZero(), /*colonToken*/ undefined, rightExpression);
97573 ts.setTextRange(target, node);
97574 return thisArg ? factory.createSyntheticReferenceExpression(target, thisArg) : target;
97575 }
97576 function createNotNullCondition(left, right, invert) {
97577 return factory.createBinaryExpression(factory.createBinaryExpression(left, factory.createToken(invert ? 36 /* SyntaxKind.EqualsEqualsEqualsToken */ : 37 /* SyntaxKind.ExclamationEqualsEqualsToken */), factory.createNull()), factory.createToken(invert ? 56 /* SyntaxKind.BarBarToken */ : 55 /* SyntaxKind.AmpersandAmpersandToken */), factory.createBinaryExpression(right, factory.createToken(invert ? 36 /* SyntaxKind.EqualsEqualsEqualsToken */ : 37 /* SyntaxKind.ExclamationEqualsEqualsToken */), factory.createVoidZero()));
97578 }

Calls 3

flattenChainFunction · 0.85
createNotNullConditionFunction · 0.85

Tested by

no test coverage detected