11package com .semmle .js .extractor ;
22
3+ import com .semmle .jcorn .TokenType ;
34import com .semmle .js .ast .DefaultVisitor ;
45import com .semmle .js .ast .INode ;
56import com .semmle .js .ast .Identifier ;
@@ -64,6 +65,7 @@ public class TypeExprKinds {
6465 private static final int importVarTypeAccess = 32 ;
6566 private static final int optionalTypeExpr = 33 ;
6667 private static final int restTypeExpr = 34 ;
68+ private static final int bigintLiteralTypeExpr = 35 ;
6769
6870 public static int getTypeExprKind (final INode type , final IdContext idcontext ) {
6971 Integer kind = type .accept (new DefaultVisitor <Void , Integer >() {
@@ -159,6 +161,7 @@ public Integer visit(InterfaceTypeExpr nd, Void c) {
159161
160162 @ Override
161163 public Integer visit (Literal nd , Void c ) {
164+ TokenType type = nd .getTokenType ();
162165 if (nd .getValue () == null ) {
163166 // We represent the null type as a keyword type in QL, but in the extractor AST
164167 // it is a Literal because the TypeScript AST does not distinguish those.
@@ -167,12 +170,14 @@ public Integer visit(Literal nd, Void c) {
167170 // - TypeScript documentation does not treat the null type as a literal type.
168171 // - There is an "undefined" type, but there is no "undefined" literal.
169172 return keywordTypeExpr ;
170- } else if (nd . getValue () instanceof String ) {
173+ } else if (type == TokenType . string ) {
171174 return stringLiteralTypeExpr ;
172- } else if (nd . getValue () instanceof Number ) {
175+ } else if (type == TokenType . num ) {
173176 return numberLiteralTypeExpr ;
174- } else if (nd . getValue () instanceof Boolean ) {
177+ } else if (type == TokenType . _true || type == TokenType . _false ) {
175178 return booeleanLiteralTypeExpr ;
179+ } else if (type == TokenType .bigint ) {
180+ return bigintLiteralTypeExpr ;
176181 } else {
177182 throw new CatastrophicError ("Unsupported literal type expression kind: " + nd .getValue ().getClass ());
178183 }
0 commit comments