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

Function isPartOfTypeNode

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

Source from the content-addressed store, hash-verified

15514 ts.fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*<amd-dependency\s+path\s*=\s*)(('[^']*')|("[^"]*")).*?\/>/;
15515 var defaultLibReferenceRegEx = /^(\/\/\/\s*<reference\s+no-default-lib\s*=\s*)(('[^']*')|("[^"]*"))\s*\/>/;
15516 function isPartOfTypeNode(node) {
15517 if (177 /* SyntaxKind.FirstTypeNode */ <= node.kind && node.kind <= 200 /* SyntaxKind.LastTypeNode */) {
15518 return true;
15519 }
15520 switch (node.kind) {
15521 case 130 /* SyntaxKind.AnyKeyword */:
15522 case 155 /* SyntaxKind.UnknownKeyword */:
15523 case 147 /* SyntaxKind.NumberKeyword */:
15524 case 158 /* SyntaxKind.BigIntKeyword */:
15525 case 150 /* SyntaxKind.StringKeyword */:
15526 case 133 /* SyntaxKind.BooleanKeyword */:
15527 case 151 /* SyntaxKind.SymbolKeyword */:
15528 case 148 /* SyntaxKind.ObjectKeyword */:
15529 case 153 /* SyntaxKind.UndefinedKeyword */:
15530 case 143 /* SyntaxKind.NeverKeyword */:
15531 return true;
15532 case 114 /* SyntaxKind.VoidKeyword */:
15533 return node.parent.kind !== 217 /* SyntaxKind.VoidExpression */;
15534 case 228 /* SyntaxKind.ExpressionWithTypeArguments */:
15535 return ts.isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
15536 case 163 /* SyntaxKind.TypeParameter */:
15537 return node.parent.kind === 195 /* SyntaxKind.MappedType */ || node.parent.kind === 190 /* SyntaxKind.InferType */;
15538 // Identifiers and qualified names may be type nodes, depending on their context. Climb
15539 // above them to find the lowest container
15540 case 79 /* SyntaxKind.Identifier */:
15541 // If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
15542 if (node.parent.kind === 161 /* SyntaxKind.QualifiedName */ && node.parent.right === node) {
15543 node = node.parent;
15544 }
15545 else if (node.parent.kind === 206 /* SyntaxKind.PropertyAccessExpression */ && node.parent.name === node) {
15546 node = node.parent;
15547 }
15548 // At this point, node is either a qualified name or an identifier
15549 ts.Debug.assert(node.kind === 79 /* SyntaxKind.Identifier */ || node.kind === 161 /* SyntaxKind.QualifiedName */ || node.kind === 206 /* SyntaxKind.PropertyAccessExpression */, "'node' was expected to be a qualified name, identifier or property access in 'isPartOfTypeNode'.");
15550 // falls through
15551 case 161 /* SyntaxKind.QualifiedName */:
15552 case 206 /* SyntaxKind.PropertyAccessExpression */:
15553 case 108 /* SyntaxKind.ThisKeyword */: {
15554 var parent = node.parent;
15555 if (parent.kind === 181 /* SyntaxKind.TypeQuery */) {
15556 return false;
15557 }
15558 if (parent.kind === 200 /* SyntaxKind.ImportType */) {
15559 return !parent.isTypeOf;
15560 }
15561 // Do not recursively call isPartOfTypeNode on the parent. In the example:
15562 //
15563 // let a: A.B.C;
15564 //
15565 // Calling isPartOfTypeNode would consider the qualified name A.B a type node.
15566 // Only C and A.B.C are type nodes.
15567 if (177 /* SyntaxKind.FirstTypeNode */ <= parent.kind && parent.kind <= 200 /* SyntaxKind.LastTypeNode */) {
15568 return true;
15569 }
15570 switch (parent.kind) {
15571 case 228 /* SyntaxKind.ExpressionWithTypeArguments */:
15572 return ts.isHeritageClause(parent.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(parent);
15573 case 163 /* SyntaxKind.TypeParameter */:

Callers 2

traverseFunction · 0.85
isInExpressionContextFunction · 0.85

Calls 3

assertMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…