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

Function visitLogicalBinaryExpression

test/fixtures/snapshot/typescript.js:102445–102488  ·  view source on GitHub ↗

* Visits a logical binary expression containing `yield`. * * @param node A node to visit.

(node)

Source from the content-addressed store, hash-verified

102443 * @param node A node to visit.
102444 */
102445 function visitLogicalBinaryExpression(node) {
102446 // Logical binary expressions (`&&` and `||`) are shortcutting expressions and need
102447 // to be transformed as such:
102448 //
102449 // [source]
102450 // x = a() && yield;
102451 //
102452 // [intermediate]
102453 // .local _a
102454 // _a = a();
102455 // .brfalse resultLabel, (_a)
102456 // .yield resumeLabel
102457 // .mark resumeLabel
102458 // _a = %sent%;
102459 // .mark resultLabel
102460 // x = _a;
102461 //
102462 // [source]
102463 // x = a() || yield;
102464 //
102465 // [intermediate]
102466 // .local _a
102467 // _a = a();
102468 // .brtrue resultLabel, (_a)
102469 // .yield resumeLabel
102470 // .mark resumeLabel
102471 // _a = %sent%;
102472 // .mark resultLabel
102473 // x = _a;
102474 var resultLabel = defineLabel();
102475 var resultLocal = declareLocal();
102476 emitAssignment(resultLocal, ts.visitNode(node.left, visitor, ts.isExpression), /*location*/ node.left);
102477 if (node.operatorToken.kind === 55 /* SyntaxKind.AmpersandAmpersandToken */) {
102478 // Logical `&&` shortcuts when the left-hand operand is falsey.
102479 emitBreakWhenFalse(resultLabel, resultLocal, /*location*/ node.left);
102480 }
102481 else {
102482 // Logical `||` shortcuts when the left-hand operand is truthy.
102483 emitBreakWhenTrue(resultLabel, resultLocal, /*location*/ node.left);
102484 }
102485 emitAssignment(resultLocal, ts.visitNode(node.right, visitor, ts.isExpression), /*location*/ node.right);
102486 markLabel(resultLabel);
102487 return resultLocal;
102488 }
102489 /**
102490 * Visits a conditional expression containing `yield`.
102491 *

Callers 1

Calls 6

defineLabelFunction · 0.85
declareLocalFunction · 0.85
emitAssignmentFunction · 0.85
emitBreakWhenFalseFunction · 0.85
emitBreakWhenTrueFunction · 0.85
markLabelFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…