Skip to content

Commit dc440aa

Browse files
authored
Merge pull request github#11255 from asgerf/js/dynamic-import-type-expr
JS: Handle DynamicImport in the context of a type
2 parents 4b9b35d + 2bcf9b8 commit dc440aa

File tree

5 files changed

+159
-3
lines changed

5 files changed

+159
-3
lines changed

javascript/extractor/src/com/semmle/js/extractor/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class Main {
4141
* A version identifier that should be updated every time the extractor changes in such a way that
4242
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
4343
*/
44-
public static final String EXTRACTOR_VERSION = "2022-11-08";
44+
public static final String EXTRACTOR_VERSION = "2022-11-14";
4545

4646
public static final Pattern NEWLINE = Pattern.compile("\n");
4747

javascript/extractor/src/com/semmle/js/extractor/TypeExprKinds.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.semmle.js.extractor.ASTExtractor.IdContext;
1111
import com.semmle.ts.ast.ArrayTypeExpr;
1212
import com.semmle.ts.ast.ConditionalTypeExpr;
13+
import com.semmle.js.ast.DynamicImport;
1314
import com.semmle.ts.ast.FunctionTypeExpr;
1415
import com.semmle.ts.ast.GenericTypeExpr;
1516
import com.semmle.ts.ast.ImportTypeExpr;
@@ -221,8 +222,7 @@ public Integer visit(InferTypeExpr nd, Void c) {
221222
return inferTypeExpr;
222223
}
223224

224-
@Override
225-
public Integer visit(ImportTypeExpr nd, Void c) {
225+
private Integer handleInlineImport() {
226226
switch (idcontext) {
227227
case NAMESPACE_BIND:
228228
return importNamespaceAccess;
@@ -235,6 +235,17 @@ public Integer visit(ImportTypeExpr nd, Void c) {
235235
}
236236
}
237237

238+
@Override
239+
public Integer visit(ImportTypeExpr nd, Void c) {
240+
return handleInlineImport();
241+
}
242+
243+
@Override
244+
public Integer visit(DynamicImport nd, Void c) {
245+
// These may appear in interface 'extend' clauses
246+
return handleInlineImport();
247+
}
248+
238249
@Override
239250
public Integer visit(OptionalTypeExpr nd, Void c) {
240251
return optionalTypeExpr;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
interface Foo extends import("foo").Bar {}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#10000=@"/dynamic-type.ts;sourcefile"
2+
files(#10000,"/dynamic-type.ts")
3+
#10001=@"/;folder"
4+
folders(#10001,"/")
5+
containerparent(#10001,#10000)
6+
#10002=@"loc,{#10000},0,0,0,0"
7+
locations_default(#10002,#10000,0,0,0,0)
8+
hasLocation(#10000,#10002)
9+
#20000=@"global_scope"
10+
scopes(#20000,0)
11+
#20001=@"script;{#10000},1,1"
12+
#20002=*
13+
lines(#20002,#20001,"interface Foo extends import(""foo"").Bar {}","
14+
")
15+
#20003=@"loc,{#10000},1,1,1,42"
16+
locations_default(#20003,#10000,1,1,1,42)
17+
hasLocation(#20002,#20003)
18+
numlines(#20001,1,1,0)
19+
#20004=*
20+
tokeninfo(#20004,7,#20001,0,"interface")
21+
#20005=@"loc,{#10000},1,1,1,9"
22+
locations_default(#20005,#10000,1,1,1,9)
23+
hasLocation(#20004,#20005)
24+
#20006=*
25+
tokeninfo(#20006,6,#20001,1,"Foo")
26+
#20007=@"loc,{#10000},1,11,1,13"
27+
locations_default(#20007,#10000,1,11,1,13)
28+
hasLocation(#20006,#20007)
29+
#20008=*
30+
tokeninfo(#20008,7,#20001,2,"extends")
31+
#20009=@"loc,{#10000},1,15,1,21"
32+
locations_default(#20009,#10000,1,15,1,21)
33+
hasLocation(#20008,#20009)
34+
#20010=*
35+
tokeninfo(#20010,7,#20001,3,"import")
36+
#20011=@"loc,{#10000},1,23,1,28"
37+
locations_default(#20011,#10000,1,23,1,28)
38+
hasLocation(#20010,#20011)
39+
#20012=*
40+
tokeninfo(#20012,8,#20001,4,"(")
41+
#20013=@"loc,{#10000},1,29,1,29"
42+
locations_default(#20013,#10000,1,29,1,29)
43+
hasLocation(#20012,#20013)
44+
#20014=*
45+
tokeninfo(#20014,4,#20001,5,"""foo""")
46+
#20015=@"loc,{#10000},1,30,1,34"
47+
locations_default(#20015,#10000,1,30,1,34)
48+
hasLocation(#20014,#20015)
49+
#20016=*
50+
tokeninfo(#20016,8,#20001,6,")")
51+
#20017=@"loc,{#10000},1,35,1,35"
52+
locations_default(#20017,#10000,1,35,1,35)
53+
hasLocation(#20016,#20017)
54+
#20018=*
55+
tokeninfo(#20018,8,#20001,7,".")
56+
#20019=@"loc,{#10000},1,36,1,36"
57+
locations_default(#20019,#10000,1,36,1,36)
58+
hasLocation(#20018,#20019)
59+
#20020=*
60+
tokeninfo(#20020,6,#20001,8,"Bar")
61+
#20021=@"loc,{#10000},1,37,1,39"
62+
locations_default(#20021,#10000,1,37,1,39)
63+
hasLocation(#20020,#20021)
64+
#20022=*
65+
tokeninfo(#20022,8,#20001,9,"{")
66+
#20023=@"loc,{#10000},1,41,1,41"
67+
locations_default(#20023,#10000,1,41,1,41)
68+
hasLocation(#20022,#20023)
69+
#20024=*
70+
tokeninfo(#20024,8,#20001,10,"}")
71+
#20025=@"loc,{#10000},1,42,1,42"
72+
locations_default(#20025,#10000,1,42,1,42)
73+
hasLocation(#20024,#20025)
74+
#20026=*
75+
tokeninfo(#20026,0,#20001,11,"")
76+
#20027=@"loc,{#10000},2,1,2,0"
77+
locations_default(#20027,#10000,2,1,2,0)
78+
hasLocation(#20026,#20027)
79+
toplevels(#20001,0)
80+
#20028=@"loc,{#10000},1,1,2,0"
81+
locations_default(#20028,#10000,1,1,2,0)
82+
hasLocation(#20001,#20028)
83+
#20029=@"local_type_name;{Foo};{#20000}"
84+
local_type_names(#20029,"Foo",#20000)
85+
#20030=*
86+
stmts(#20030,34,#20001,0,"interfa ... .Bar {}")
87+
hasLocation(#20030,#20003)
88+
stmt_containers(#20030,#20001)
89+
#20031=*
90+
typeexprs(#20031,13,#20030,-1,"import(""foo"").Bar")
91+
#20032=@"loc,{#10000},1,23,1,39"
92+
locations_default(#20032,#10000,1,23,1,39)
93+
hasLocation(#20031,#20032)
94+
enclosing_stmt(#20031,#20030)
95+
expr_containers(#20031,#20001)
96+
#20033=*
97+
typeexprs(#20033,31,#20031,0,"import(""foo"")")
98+
#20034=@"loc,{#10000},1,23,1,35"
99+
locations_default(#20034,#10000,1,23,1,35)
100+
hasLocation(#20033,#20034)
101+
enclosing_stmt(#20033,#20030)
102+
expr_containers(#20033,#20001)
103+
#20035=*
104+
exprs(#20035,4,#20033,0,"""foo""")
105+
hasLocation(#20035,#20015)
106+
enclosing_stmt(#20035,#20030)
107+
expr_containers(#20035,#20001)
108+
literals("foo","""foo""",#20035)
109+
#20036=*
110+
regexpterm(#20036,14,#20035,0,"foo")
111+
#20037=@"loc,{#10000},1,31,1,33"
112+
locations_default(#20037,#10000,1,31,1,33)
113+
hasLocation(#20036,#20037)
114+
regexp_const_value(#20036,"foo")
115+
#20038=*
116+
typeexprs(#20038,15,#20031,1,"Bar")
117+
hasLocation(#20038,#20021)
118+
enclosing_stmt(#20038,#20030)
119+
expr_containers(#20038,#20001)
120+
literals("Bar","Bar",#20038)
121+
#20039=*
122+
typeexprs(#20039,1,#20030,0,"Foo")
123+
hasLocation(#20039,#20007)
124+
enclosing_stmt(#20039,#20030)
125+
expr_containers(#20039,#20001)
126+
literals("Foo","Foo",#20039)
127+
typedecl(#20039,#20029)
128+
#20040=*
129+
entry_cfg_node(#20040,#20001)
130+
#20041=@"loc,{#10000},1,1,1,0"
131+
locations_default(#20041,#10000,1,1,1,0)
132+
hasLocation(#20040,#20041)
133+
#20042=*
134+
exit_cfg_node(#20042,#20001)
135+
hasLocation(#20042,#20027)
136+
successor(#20030,#20042)
137+
successor(#20040,#20030)
138+
numlines(#10000,1,1,0)
139+
filetype(#10000,"typescript")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: fix
3+
---
4+
* Fixed a bug that would cause the extractor to crash when an `import` type is used in
5+
the `extends` clause of an `interface`.

0 commit comments

Comments
 (0)