mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Merge pull request #11255 from asgerf/js/dynamic-import-type-expr
JS: Handle DynamicImport in the context of a type
This commit is contained in:
@@ -41,7 +41,7 @@ public class Main {
|
||||
* A version identifier that should be updated every time the extractor changes in such a way that
|
||||
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
|
||||
*/
|
||||
public static final String EXTRACTOR_VERSION = "2022-11-08";
|
||||
public static final String EXTRACTOR_VERSION = "2022-11-14";
|
||||
|
||||
public static final Pattern NEWLINE = Pattern.compile("\n");
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.semmle.js.ast.TemplateElement;
|
||||
import com.semmle.js.extractor.ASTExtractor.IdContext;
|
||||
import com.semmle.ts.ast.ArrayTypeExpr;
|
||||
import com.semmle.ts.ast.ConditionalTypeExpr;
|
||||
import com.semmle.js.ast.DynamicImport;
|
||||
import com.semmle.ts.ast.FunctionTypeExpr;
|
||||
import com.semmle.ts.ast.GenericTypeExpr;
|
||||
import com.semmle.ts.ast.ImportTypeExpr;
|
||||
@@ -221,8 +222,7 @@ public class TypeExprKinds {
|
||||
return inferTypeExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visit(ImportTypeExpr nd, Void c) {
|
||||
private Integer handleInlineImport() {
|
||||
switch (idcontext) {
|
||||
case NAMESPACE_BIND:
|
||||
return importNamespaceAccess;
|
||||
@@ -235,6 +235,17 @@ public class TypeExprKinds {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visit(ImportTypeExpr nd, Void c) {
|
||||
return handleInlineImport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visit(DynamicImport nd, Void c) {
|
||||
// These may appear in interface 'extend' clauses
|
||||
return handleInlineImport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer visit(OptionalTypeExpr nd, Void c) {
|
||||
return optionalTypeExpr;
|
||||
|
||||
1
javascript/extractor/tests/ts/input/dynamic-type.ts
Normal file
1
javascript/extractor/tests/ts/input/dynamic-type.ts
Normal file
@@ -0,0 +1 @@
|
||||
interface Foo extends import("foo").Bar {}
|
||||
139
javascript/extractor/tests/ts/output/trap/dynamic-type.ts.trap
Normal file
139
javascript/extractor/tests/ts/output/trap/dynamic-type.ts.trap
Normal file
@@ -0,0 +1,139 @@
|
||||
#10000=@"/dynamic-type.ts;sourcefile"
|
||||
files(#10000,"/dynamic-type.ts")
|
||||
#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,"interface Foo extends import(""foo"").Bar {}","
|
||||
")
|
||||
#20003=@"loc,{#10000},1,1,1,42"
|
||||
locations_default(#20003,#10000,1,1,1,42)
|
||||
hasLocation(#20002,#20003)
|
||||
numlines(#20001,1,1,0)
|
||||
#20004=*
|
||||
tokeninfo(#20004,7,#20001,0,"interface")
|
||||
#20005=@"loc,{#10000},1,1,1,9"
|
||||
locations_default(#20005,#10000,1,1,1,9)
|
||||
hasLocation(#20004,#20005)
|
||||
#20006=*
|
||||
tokeninfo(#20006,6,#20001,1,"Foo")
|
||||
#20007=@"loc,{#10000},1,11,1,13"
|
||||
locations_default(#20007,#10000,1,11,1,13)
|
||||
hasLocation(#20006,#20007)
|
||||
#20008=*
|
||||
tokeninfo(#20008,7,#20001,2,"extends")
|
||||
#20009=@"loc,{#10000},1,15,1,21"
|
||||
locations_default(#20009,#10000,1,15,1,21)
|
||||
hasLocation(#20008,#20009)
|
||||
#20010=*
|
||||
tokeninfo(#20010,7,#20001,3,"import")
|
||||
#20011=@"loc,{#10000},1,23,1,28"
|
||||
locations_default(#20011,#10000,1,23,1,28)
|
||||
hasLocation(#20010,#20011)
|
||||
#20012=*
|
||||
tokeninfo(#20012,8,#20001,4,"(")
|
||||
#20013=@"loc,{#10000},1,29,1,29"
|
||||
locations_default(#20013,#10000,1,29,1,29)
|
||||
hasLocation(#20012,#20013)
|
||||
#20014=*
|
||||
tokeninfo(#20014,4,#20001,5,"""foo""")
|
||||
#20015=@"loc,{#10000},1,30,1,34"
|
||||
locations_default(#20015,#10000,1,30,1,34)
|
||||
hasLocation(#20014,#20015)
|
||||
#20016=*
|
||||
tokeninfo(#20016,8,#20001,6,")")
|
||||
#20017=@"loc,{#10000},1,35,1,35"
|
||||
locations_default(#20017,#10000,1,35,1,35)
|
||||
hasLocation(#20016,#20017)
|
||||
#20018=*
|
||||
tokeninfo(#20018,8,#20001,7,".")
|
||||
#20019=@"loc,{#10000},1,36,1,36"
|
||||
locations_default(#20019,#10000,1,36,1,36)
|
||||
hasLocation(#20018,#20019)
|
||||
#20020=*
|
||||
tokeninfo(#20020,6,#20001,8,"Bar")
|
||||
#20021=@"loc,{#10000},1,37,1,39"
|
||||
locations_default(#20021,#10000,1,37,1,39)
|
||||
hasLocation(#20020,#20021)
|
||||
#20022=*
|
||||
tokeninfo(#20022,8,#20001,9,"{")
|
||||
#20023=@"loc,{#10000},1,41,1,41"
|
||||
locations_default(#20023,#10000,1,41,1,41)
|
||||
hasLocation(#20022,#20023)
|
||||
#20024=*
|
||||
tokeninfo(#20024,8,#20001,10,"}")
|
||||
#20025=@"loc,{#10000},1,42,1,42"
|
||||
locations_default(#20025,#10000,1,42,1,42)
|
||||
hasLocation(#20024,#20025)
|
||||
#20026=*
|
||||
tokeninfo(#20026,0,#20001,11,"")
|
||||
#20027=@"loc,{#10000},2,1,2,0"
|
||||
locations_default(#20027,#10000,2,1,2,0)
|
||||
hasLocation(#20026,#20027)
|
||||
toplevels(#20001,0)
|
||||
#20028=@"loc,{#10000},1,1,2,0"
|
||||
locations_default(#20028,#10000,1,1,2,0)
|
||||
hasLocation(#20001,#20028)
|
||||
#20029=@"local_type_name;{Foo};{#20000}"
|
||||
local_type_names(#20029,"Foo",#20000)
|
||||
#20030=*
|
||||
stmts(#20030,34,#20001,0,"interfa ... .Bar {}")
|
||||
hasLocation(#20030,#20003)
|
||||
stmt_containers(#20030,#20001)
|
||||
#20031=*
|
||||
typeexprs(#20031,13,#20030,-1,"import(""foo"").Bar")
|
||||
#20032=@"loc,{#10000},1,23,1,39"
|
||||
locations_default(#20032,#10000,1,23,1,39)
|
||||
hasLocation(#20031,#20032)
|
||||
enclosing_stmt(#20031,#20030)
|
||||
expr_containers(#20031,#20001)
|
||||
#20033=*
|
||||
typeexprs(#20033,31,#20031,0,"import(""foo"")")
|
||||
#20034=@"loc,{#10000},1,23,1,35"
|
||||
locations_default(#20034,#10000,1,23,1,35)
|
||||
hasLocation(#20033,#20034)
|
||||
enclosing_stmt(#20033,#20030)
|
||||
expr_containers(#20033,#20001)
|
||||
#20035=*
|
||||
exprs(#20035,4,#20033,0,"""foo""")
|
||||
hasLocation(#20035,#20015)
|
||||
enclosing_stmt(#20035,#20030)
|
||||
expr_containers(#20035,#20001)
|
||||
literals("foo","""foo""",#20035)
|
||||
#20036=*
|
||||
regexpterm(#20036,14,#20035,0,"foo")
|
||||
#20037=@"loc,{#10000},1,31,1,33"
|
||||
locations_default(#20037,#10000,1,31,1,33)
|
||||
hasLocation(#20036,#20037)
|
||||
regexp_const_value(#20036,"foo")
|
||||
#20038=*
|
||||
typeexprs(#20038,15,#20031,1,"Bar")
|
||||
hasLocation(#20038,#20021)
|
||||
enclosing_stmt(#20038,#20030)
|
||||
expr_containers(#20038,#20001)
|
||||
literals("Bar","Bar",#20038)
|
||||
#20039=*
|
||||
typeexprs(#20039,1,#20030,0,"Foo")
|
||||
hasLocation(#20039,#20007)
|
||||
enclosing_stmt(#20039,#20030)
|
||||
expr_containers(#20039,#20001)
|
||||
literals("Foo","Foo",#20039)
|
||||
typedecl(#20039,#20029)
|
||||
#20040=*
|
||||
entry_cfg_node(#20040,#20001)
|
||||
#20041=@"loc,{#10000},1,1,1,0"
|
||||
locations_default(#20041,#10000,1,1,1,0)
|
||||
hasLocation(#20040,#20041)
|
||||
#20042=*
|
||||
exit_cfg_node(#20042,#20001)
|
||||
hasLocation(#20042,#20027)
|
||||
successor(#20030,#20042)
|
||||
successor(#20040,#20030)
|
||||
numlines(#10000,1,1,0)
|
||||
filetype(#10000,"typescript")
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
category: fix
|
||||
---
|
||||
* Fixed a bug that would cause the extractor to crash when an `import` type is used in
|
||||
the `extends` clause of an `interface`.
|
||||
Reference in New Issue
Block a user