MCPcopy Create free account
hub / github.com/nodejs/node / getPossibleTypeArgumentsInfo

Function getPossibleTypeArgumentsInfo

test/fixtures/snapshot/typescript.js:127799–127889  ·  view source on GitHub ↗
(tokenIn, sourceFile)

Source from the content-addressed store, hash-verified

127797 ts.getPossibleGenericSignatures = getPossibleGenericSignatures;
127798 // Get info for an expression like `f <` that may be the start of type arguments.
127799 function getPossibleTypeArgumentsInfo(tokenIn, sourceFile) {
127800 // This is a rare case, but one that saves on a _lot_ of work if true - if the source file has _no_ `<` character,
127801 // then there obviously can't be any type arguments - no expensive brace-matching backwards scanning required
127802 if (sourceFile.text.lastIndexOf("<", tokenIn ? tokenIn.pos : sourceFile.text.length) === -1) {
127803 return undefined;
127804 }
127805 var token = tokenIn;
127806 // This function determines if the node could be type argument position
127807 // Since during editing, when type argument list is not complete,
127808 // the tree could be of any shape depending on the tokens parsed before current node,
127809 // scanning of the previous identifier followed by "<" before current node would give us better result
127810 // Note that we also balance out the already provided type arguments, arrays, object literals while doing so
127811 var remainingLessThanTokens = 0;
127812 var nTypeArguments = 0;
127813 while (token) {
127814 switch (token.kind) {
127815 case 29 /* SyntaxKind.LessThanToken */:
127816 // Found the beginning of the generic argument expression
127817 token = findPrecedingToken(token.getFullStart(), sourceFile);
127818 if (token && token.kind === 28 /* SyntaxKind.QuestionDotToken */) {
127819 token = findPrecedingToken(token.getFullStart(), sourceFile);
127820 }
127821 if (!token || !ts.isIdentifier(token))
127822 return undefined;
127823 if (!remainingLessThanTokens) {
127824 return ts.isDeclarationName(token) ? undefined : { called: token, nTypeArguments: nTypeArguments };
127825 }
127826 remainingLessThanTokens--;
127827 break;
127828 case 49 /* SyntaxKind.GreaterThanGreaterThanGreaterThanToken */:
127829 remainingLessThanTokens = +3;
127830 break;
127831 case 48 /* SyntaxKind.GreaterThanGreaterThanToken */:
127832 remainingLessThanTokens = +2;
127833 break;
127834 case 31 /* SyntaxKind.GreaterThanToken */:
127835 remainingLessThanTokens++;
127836 break;
127837 case 19 /* SyntaxKind.CloseBraceToken */:
127838 // This can be object type, skip until we find the matching open brace token
127839 // Skip until the matching open brace token
127840 token = findPrecedingMatchingToken(token, 18 /* SyntaxKind.OpenBraceToken */, sourceFile);
127841 if (!token)
127842 return undefined;
127843 break;
127844 case 21 /* SyntaxKind.CloseParenToken */:
127845 // This can be object type, skip until we find the matching open brace token
127846 // Skip until the matching open brace token
127847 token = findPrecedingMatchingToken(token, 20 /* SyntaxKind.OpenParenToken */, sourceFile);
127848 if (!token)
127849 return undefined;
127850 break;
127851 case 23 /* SyntaxKind.CloseBracketToken */:
127852 // This can be object type, skip until we find the matching open brace token
127853 // Skip until the matching open brace token
127854 token = findPrecedingMatchingToken(token, 22 /* SyntaxKind.OpenBracketToken */, sourceFile);
127855 if (!token)
127856 return undefined;

Callers 1

Calls 2

findPrecedingTokenFunction · 0.85

Tested by

no test coverage detected