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

Function classifyTokenType

test/fixtures/snapshot/typescript.js:130833–130927  ·  view source on GitHub ↗
(tokenKind, token)

Source from the content-addressed store, hash-verified

130831 // cases like 'disabled merge code' classification, we just get the token kind and
130832 // classify based on that instead.
130833 function classifyTokenType(tokenKind, token) {
130834 if (ts.isKeyword(tokenKind)) {
130835 return 3 /* ClassificationType.keyword */;
130836 }
130837 // Special case `<` and `>`: If they appear in a generic context they are punctuation,
130838 // not operators.
130839 if (tokenKind === 29 /* SyntaxKind.LessThanToken */ || tokenKind === 31 /* SyntaxKind.GreaterThanToken */) {
130840 // If the node owning the token has a type argument list or type parameter list, then
130841 // we can effectively assume that a '<' and '>' belong to those lists.
130842 if (token && ts.getTypeArgumentOrTypeParameterList(token.parent)) {
130843 return 10 /* ClassificationType.punctuation */;
130844 }
130845 }
130846 if (ts.isPunctuation(tokenKind)) {
130847 if (token) {
130848 var parent = token.parent;
130849 if (tokenKind === 63 /* SyntaxKind.EqualsToken */) {
130850 // the '=' in a variable declaration is special cased here.
130851 if (parent.kind === 254 /* SyntaxKind.VariableDeclaration */ ||
130852 parent.kind === 167 /* SyntaxKind.PropertyDeclaration */ ||
130853 parent.kind === 164 /* SyntaxKind.Parameter */ ||
130854 parent.kind === 285 /* SyntaxKind.JsxAttribute */) {
130855 return 5 /* ClassificationType.operator */;
130856 }
130857 }
130858 if (parent.kind === 221 /* SyntaxKind.BinaryExpression */ ||
130859 parent.kind === 219 /* SyntaxKind.PrefixUnaryExpression */ ||
130860 parent.kind === 220 /* SyntaxKind.PostfixUnaryExpression */ ||
130861 parent.kind === 222 /* SyntaxKind.ConditionalExpression */) {
130862 return 5 /* ClassificationType.operator */;
130863 }
130864 }
130865 return 10 /* ClassificationType.punctuation */;
130866 }
130867 else if (tokenKind === 8 /* SyntaxKind.NumericLiteral */) {
130868 return 4 /* ClassificationType.numericLiteral */;
130869 }
130870 else if (tokenKind === 9 /* SyntaxKind.BigIntLiteral */) {
130871 return 25 /* ClassificationType.bigintLiteral */;
130872 }
130873 else if (tokenKind === 10 /* SyntaxKind.StringLiteral */) {
130874 return token && token.parent.kind === 285 /* SyntaxKind.JsxAttribute */ ? 24 /* ClassificationType.jsxAttributeStringLiteralValue */ : 6 /* ClassificationType.stringLiteral */;
130875 }
130876 else if (tokenKind === 13 /* SyntaxKind.RegularExpressionLiteral */) {
130877 // TODO: we should get another classification type for these literals.
130878 return 6 /* ClassificationType.stringLiteral */;
130879 }
130880 else if (ts.isTemplateLiteralKind(tokenKind)) {
130881 // TODO (drosen): we should *also* get another classification type for these literals.
130882 return 6 /* ClassificationType.stringLiteral */;
130883 }
130884 else if (tokenKind === 11 /* SyntaxKind.JsxText */) {
130885 return 23 /* ClassificationType.jsxText */;
130886 }
130887 else if (tokenKind === 79 /* SyntaxKind.Identifier */) {
130888 if (token) {
130889 switch (token.parent.kind) {
130890 case 257 /* SyntaxKind.ClassDeclaration */:

Callers 2

tryClassifyNodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected