mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
TS: Tolerate syntax errors in class declaration
This commit is contained in:
@@ -942,9 +942,7 @@ public class TypeScriptASTConverter {
|
||||
SourceLocation bodyLoc = new SourceLocation(loc.getSource(), loc.getStart(), loc.getEnd());
|
||||
advance(bodyLoc, skip);
|
||||
ClassBody body = new ClassBody(bodyLoc, convertChildren(node, "members"));
|
||||
if ("ClassExpression".equals(kind) || id == null) {
|
||||
// Note that `export default class {}` is represented as a ClassDeclaration
|
||||
// in TypeScript but we treat this as a ClassExpression.
|
||||
if ("ClassExpression".equals(kind)) {
|
||||
ClassExpression classExpr =
|
||||
new ClassExpression(loc, id, typeParameters, superClass, superInterfaces, body);
|
||||
attachSymbolInformation(classExpr.getClassDef(), node);
|
||||
@@ -967,7 +965,13 @@ public class TypeScriptASTConverter {
|
||||
classDecl.addDecorators(convertChildren(node, "decorators"));
|
||||
advanceUntilAfter(loc, classDecl.getDecorators());
|
||||
}
|
||||
return fixExports(loc, classDecl);
|
||||
Node exportedDecl = fixExports(loc, classDecl);
|
||||
// Convert default-exported anonymous class declarations to class expressions.
|
||||
if (exportedDecl instanceof ExportDefaultDeclaration && !classDecl.getClassDef().hasId()) {
|
||||
return new ExportDefaultDeclaration(
|
||||
exportedDecl.getLoc(), new ClassExpression(classDecl.getLoc(), classDecl.getClassDef()));
|
||||
}
|
||||
return exportedDecl;
|
||||
}
|
||||
|
||||
private Node convertCommaListExpression(JsonObject node, SourceLocation loc) throws ParseError {
|
||||
|
||||
1
javascript/extractor/tests/ts/input/exportclass.ts
Normal file
1
javascript/extractor/tests/ts/input/exportclass.ts
Normal file
@@ -0,0 +1 @@
|
||||
export class {}
|
||||
114
javascript/extractor/tests/ts/output/trap/exportclass.ts.trap
Normal file
114
javascript/extractor/tests/ts/output/trap/exportclass.ts.trap
Normal file
@@ -0,0 +1,114 @@
|
||||
#10000=@"/exportclass.ts;sourcefile"
|
||||
files(#10000,"/exportclass.ts","exportclass","ts",0)
|
||||
#10001=@"/;folder"
|
||||
folders(#10001,"/","")
|
||||
containerparent(#10001,#10000)
|
||||
#10002=@"loc,{#10000},0,0,0,0"
|
||||
locations_default(#10002,#10000,0,0,0,0)
|
||||
hasLocation(#10000,#10002)
|
||||
#20000=@"global_scope"
|
||||
scopes(#20000,0)
|
||||
#20001=@"script;{#10000},1,1"
|
||||
#20002=*
|
||||
lines(#20002,#20001,"export class {}","
|
||||
")
|
||||
#20003=@"loc,{#10000},1,1,1,15"
|
||||
locations_default(#20003,#10000,1,1,1,15)
|
||||
hasLocation(#20002,#20003)
|
||||
numlines(#20001,1,1,0)
|
||||
#20004=*
|
||||
tokeninfo(#20004,7,#20001,0,"export")
|
||||
#20005=@"loc,{#10000},1,1,1,6"
|
||||
locations_default(#20005,#10000,1,1,1,6)
|
||||
hasLocation(#20004,#20005)
|
||||
#20006=*
|
||||
tokeninfo(#20006,7,#20001,1,"class")
|
||||
#20007=@"loc,{#10000},1,8,1,12"
|
||||
locations_default(#20007,#10000,1,8,1,12)
|
||||
hasLocation(#20006,#20007)
|
||||
#20008=*
|
||||
tokeninfo(#20008,8,#20001,2,"{")
|
||||
#20009=@"loc,{#10000},1,14,1,14"
|
||||
locations_default(#20009,#10000,1,14,1,14)
|
||||
hasLocation(#20008,#20009)
|
||||
#20010=*
|
||||
tokeninfo(#20010,8,#20001,3,"}")
|
||||
#20011=@"loc,{#10000},1,15,1,15"
|
||||
locations_default(#20011,#10000,1,15,1,15)
|
||||
hasLocation(#20010,#20011)
|
||||
#20012=*
|
||||
tokeninfo(#20012,0,#20001,4,"")
|
||||
#20013=@"loc,{#10000},2,1,2,0"
|
||||
locations_default(#20013,#10000,2,1,2,0)
|
||||
hasLocation(#20012,#20013)
|
||||
toplevels(#20001,0)
|
||||
#20014=@"loc,{#10000},1,1,2,0"
|
||||
locations_default(#20014,#10000,1,1,2,0)
|
||||
hasLocation(#20001,#20014)
|
||||
#20015=@"module;{#10000},1,1"
|
||||
scopes(#20015,3)
|
||||
scopenodes(#20001,#20015)
|
||||
scopenesting(#20015,#20000)
|
||||
isModule(#20001)
|
||||
isES2015Module(#20001)
|
||||
#20016=*
|
||||
stmts(#20016,30,#20001,0,"export class {}")
|
||||
hasLocation(#20016,#20003)
|
||||
stmtContainers(#20016,#20001)
|
||||
#20017=*
|
||||
stmts(#20017,26,#20016,-1,"class {}")
|
||||
#20018=@"loc,{#10000},1,8,1,15"
|
||||
locations_default(#20018,#10000,1,8,1,15)
|
||||
hasLocation(#20017,#20018)
|
||||
stmtContainers(#20017,#20001)
|
||||
#20019=*
|
||||
properties(#20019,#20017,2,0,"constructor() {}")
|
||||
#20020=@"loc,{#10000},1,6,1,5"
|
||||
locations_default(#20020,#10000,1,6,1,5)
|
||||
hasLocation(#20019,#20020)
|
||||
#20021=*
|
||||
exprs(#20021,0,#20019,0,"constructor")
|
||||
hasLocation(#20021,#20020)
|
||||
enclosingStmt(#20021,#20017)
|
||||
exprContainers(#20021,#20001)
|
||||
literals("constructor","constructor",#20021)
|
||||
#20022=*
|
||||
exprs(#20022,9,#20019,1,"() {}")
|
||||
hasLocation(#20022,#20020)
|
||||
enclosingStmt(#20022,#20017)
|
||||
exprContainers(#20022,#20001)
|
||||
#20023=*
|
||||
scopes(#20023,1)
|
||||
scopenodes(#20022,#20023)
|
||||
scopenesting(#20023,#20015)
|
||||
#20024=@"var;{arguments};{#20023}"
|
||||
variables(#20024,"arguments",#20023)
|
||||
isArgumentsObject(#20024)
|
||||
#20025=*
|
||||
stmts(#20025,1,#20022,-2,"{}")
|
||||
hasLocation(#20025,#20020)
|
||||
stmtContainers(#20025,#20022)
|
||||
isMethod(#20019)
|
||||
#20026=*
|
||||
entry_cfg_node(#20026,#20001)
|
||||
#20027=@"loc,{#10000},1,1,1,0"
|
||||
locations_default(#20027,#10000,1,1,1,0)
|
||||
hasLocation(#20026,#20027)
|
||||
#20028=*
|
||||
exit_cfg_node(#20028,#20001)
|
||||
hasLocation(#20028,#20013)
|
||||
successor(#20022,#20019)
|
||||
#20029=*
|
||||
entry_cfg_node(#20029,#20022)
|
||||
hasLocation(#20029,#20020)
|
||||
#20030=*
|
||||
exit_cfg_node(#20030,#20022)
|
||||
hasLocation(#20030,#20020)
|
||||
successor(#20025,#20030)
|
||||
successor(#20029,#20025)
|
||||
successor(#20021,#20022)
|
||||
successor(#20019,#20017)
|
||||
successor(#20017,#20028)
|
||||
successor(#20026,#20016)
|
||||
numlines(#10000,1,1,0)
|
||||
filetype(#10000,"typescript")
|
||||
Reference in New Issue
Block a user