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

Function isSymbolUsedInConditionBody

test/fixtures/snapshot/typescript.js:82741–82777  ·  view source on GitHub ↗
(expr, body, testedNode, testedSymbol)

Source from the content-addressed store, hash-verified

82739 }
82740 }
82741 function isSymbolUsedInConditionBody(expr, body, testedNode, testedSymbol) {
82742 return !!ts.forEachChild(body, function check(childNode) {
82743 if (ts.isIdentifier(childNode)) {
82744 var childSymbol = getSymbolAtLocation(childNode);
82745 if (childSymbol && childSymbol === testedSymbol) {
82746 // If the test was a simple identifier, the above check is sufficient
82747 if (ts.isIdentifier(expr) || ts.isIdentifier(testedNode) && ts.isBinaryExpression(testedNode.parent)) {
82748 return true;
82749 }
82750 // Otherwise we need to ensure the symbol is called on the same target
82751 var testedExpression = testedNode.parent;
82752 var childExpression = childNode.parent;
82753 while (testedExpression && childExpression) {
82754 if (ts.isIdentifier(testedExpression) && ts.isIdentifier(childExpression) ||
82755 testedExpression.kind === 108 /* SyntaxKind.ThisKeyword */ && childExpression.kind === 108 /* SyntaxKind.ThisKeyword */) {
82756 return getSymbolAtLocation(testedExpression) === getSymbolAtLocation(childExpression);
82757 }
82758 else if (ts.isPropertyAccessExpression(testedExpression) && ts.isPropertyAccessExpression(childExpression)) {
82759 if (getSymbolAtLocation(testedExpression.name) !== getSymbolAtLocation(childExpression.name)) {
82760 return false;
82761 }
82762 childExpression = childExpression.expression;
82763 testedExpression = testedExpression.expression;
82764 }
82765 else if (ts.isCallExpression(testedExpression) && ts.isCallExpression(childExpression)) {
82766 childExpression = childExpression.expression;
82767 testedExpression = testedExpression.expression;
82768 }
82769 else {
82770 return false;
82771 }
82772 }
82773 }
82774 }
82775 return ts.forEachChild(childNode, check);
82776 });
82777 }
82778 function isSymbolUsedInBinaryExpressionChain(node, testedSymbol) {
82779 while (ts.isBinaryExpression(node) && node.operatorToken.kind === 55 /* SyntaxKind.AmpersandAmpersandToken */) {
82780 var isUsed = ts.forEachChild(node.right, function visit(child) {

Callers 1

helperFunction · 0.85

Calls 2

getSymbolAtLocationFunction · 0.85
forEachChildMethod · 0.80

Tested by

no test coverage detected