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

Function isContextSensitive

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

Source from the content-addressed store, hash-verified

63757 // Returns true if the given expression contains (at any level of nesting) a function or arrow expression
63758 // that is subject to contextual typing.
63759 function isContextSensitive(node) {
63760 ts.Debug.assert(node.kind !== 169 /* SyntaxKind.MethodDeclaration */ || ts.isObjectLiteralMethod(node));
63761 switch (node.kind) {
63762 case 213 /* SyntaxKind.FunctionExpression */:
63763 case 214 /* SyntaxKind.ArrowFunction */:
63764 case 169 /* SyntaxKind.MethodDeclaration */:
63765 case 256 /* SyntaxKind.FunctionDeclaration */: // Function declarations can have context when annotated with a jsdoc @type
63766 return isContextSensitiveFunctionLikeDeclaration(node);
63767 case 205 /* SyntaxKind.ObjectLiteralExpression */:
63768 return ts.some(node.properties, isContextSensitive);
63769 case 204 /* SyntaxKind.ArrayLiteralExpression */:
63770 return ts.some(node.elements, isContextSensitive);
63771 case 222 /* SyntaxKind.ConditionalExpression */:
63772 return isContextSensitive(node.whenTrue) ||
63773 isContextSensitive(node.whenFalse);
63774 case 221 /* SyntaxKind.BinaryExpression */:
63775 return (node.operatorToken.kind === 56 /* SyntaxKind.BarBarToken */ || node.operatorToken.kind === 60 /* SyntaxKind.QuestionQuestionToken */) &&
63776 (isContextSensitive(node.left) || isContextSensitive(node.right));
63777 case 296 /* SyntaxKind.PropertyAssignment */:
63778 return isContextSensitive(node.initializer);
63779 case 212 /* SyntaxKind.ParenthesizedExpression */:
63780 return isContextSensitive(node.expression);
63781 case 286 /* SyntaxKind.JsxAttributes */:
63782 return ts.some(node.properties, isContextSensitive) || ts.isJsxOpeningElement(node.parent) && ts.some(node.parent.parent.children, isContextSensitive);
63783 case 285 /* SyntaxKind.JsxAttribute */: {
63784 // If there is no initializer, JSX attribute has a boolean value of true which is not context sensitive.
63785 var initializer = node.initializer;
63786 return !!initializer && isContextSensitive(initializer);
63787 }
63788 case 288 /* SyntaxKind.JsxExpression */: {
63789 // It is possible to that node.expression is undefined (e.g <div x={} />)
63790 var expression = node.expression;
63791 return !!expression && isContextSensitive(expression);
63792 }
63793 }
63794 return false;
63795 }
63796 function isContextSensitiveFunctionLikeDeclaration(node) {
63797 return (!ts.isFunctionDeclaration(node) || ts.isInJSFile(node) && !!getTypeForDeclarationFromJSDocComment(node)) &&
63798 (ts.hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node));

Calls 3

assertMethod · 0.80
someMethod · 0.80

Tested by

no test coverage detected