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

Function getContextualTypeForBinaryOperand

test/fixtures/snapshot/typescript.js:72607–72632  ·  view source on GitHub ↗
(node, contextFlags)

Source from the content-addressed store, hash-verified

72605 return undefined;
72606 }
72607 function getContextualTypeForBinaryOperand(node, contextFlags) {
72608 var binaryExpression = node.parent;
72609 var left = binaryExpression.left, operatorToken = binaryExpression.operatorToken, right = binaryExpression.right;
72610 switch (operatorToken.kind) {
72611 case 63 /* SyntaxKind.EqualsToken */:
72612 case 76 /* SyntaxKind.AmpersandAmpersandEqualsToken */:
72613 case 75 /* SyntaxKind.BarBarEqualsToken */:
72614 case 77 /* SyntaxKind.QuestionQuestionEqualsToken */:
72615 return node === right ? getContextualTypeForAssignmentDeclaration(binaryExpression) : undefined;
72616 case 56 /* SyntaxKind.BarBarToken */:
72617 case 60 /* SyntaxKind.QuestionQuestionToken */:
72618 // When an || expression has a contextual type, the operands are contextually typed by that type, except
72619 // when that type originates in a binding pattern, the right operand is contextually typed by the type of
72620 // the left operand. When an || expression has no contextual type, the right operand is contextually typed
72621 // by the type of the left operand, except for the special case of Javascript declarations of the form
72622 // `namespace.prop = namespace.prop || {}`.
72623 var type = getContextualType(binaryExpression, contextFlags);
72624 return node === right && (type && type.pattern || !type && !ts.isDefaultedExpandoInitializer(binaryExpression)) ?
72625 getTypeOfExpression(left) : type;
72626 case 55 /* SyntaxKind.AmpersandAmpersandToken */:
72627 case 27 /* SyntaxKind.CommaToken */:
72628 return node === right ? getContextualType(binaryExpression, contextFlags) : undefined;
72629 default:
72630 return undefined;
72631 }
72632 }
72633 /**
72634 * Try to find a resolved symbol for an expression without also resolving its type, as
72635 * getSymbolAtLocation would (as that could be reentrant into contextual typing)

Callers 1

getContextualTypeFunction · 0.85

Calls 3

getContextualTypeFunction · 0.85
getTypeOfExpressionFunction · 0.85

Tested by

no test coverage detected