Skip to content

Commit 479fca9

Browse files
authored
Merge pull request github#1946 from xiemaisi/js/top-level-await
Approved by asger-semmle
2 parents b4b7314 + 9ff5c70 commit 479fca9

File tree

5 files changed

+269
-3
lines changed

5 files changed

+269
-3
lines changed

change-notes/1.23/extractor-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
## Changes to code extraction
66

77
* Asynchronous generator methods are now parsed correctly and no longer cause a spurious syntax error.
8+
* Top-level `await` is now supported.

javascript/extractor/src/com/semmle/jcorn/Parser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ protected Expression parseMaybeUnary(
14601460
int startPos = this.start;
14611461
Position startLoc = this.startLoc;
14621462
Expression expr;
1463-
if (this.inAsync && this.isContextual("await")) {
1463+
if ((this.inAsync || options.esnext() && !this.inFunction) && this.isContextual("await")) {
14641464
expr = this.parseAwait();
14651465
sawUnary = true;
14661466
} else if (this.type.isPrefix) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class Main {
3737
* A version identifier that should be updated every time the extractor changes in such a way that
3838
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
3939
*/
40-
public static final String EXTRACTOR_VERSION = "2019-09-04";
40+
public static final String EXTRACTOR_VERSION = "2019-09-13";
4141

4242
public static final Pattern NEWLINE = Pattern.compile("\n");
4343

@@ -328,7 +328,7 @@ private ArgsParser addArgs(ArgsParser argsParser) {
328328
0,
329329
"Enable experimental support for pending ECMAScript proposals "
330330
+ "(public class fields, function.sent, decorators, export extensions, function bind, "
331-
+ "parameter-less catch, dynamic import, numeric separators, bigints), "
331+
+ "parameter-less catch, dynamic import, numeric separators, bigints, top-level await), "
332332
+ "as well as other language extensions (E4X, JScript, Mozilla and v8-specific extensions) and full HTML extraction.");
333333
argsParser.addFlag(
334334
P_EXTERNS, 0, "Extract the given JavaScript files as Closure-style externs.");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { language } from 'settings';
2+
const strings = await import(`./i18n/${language}`);
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
#10000=@"/top-level-await.js;sourcefile"
2+
files(#10000,"/top-level-await.js","top-level-await","js",0)
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,"import { language } from 'settings';","
14+
")
15+
#20003=@"loc,{#10000},1,1,1,36"
16+
locations_default(#20003,#10000,1,1,1,36)
17+
hasLocation(#20002,#20003)
18+
#20004=*
19+
lines(#20004,#20001,"const strings = await import(`./i18n/${language}`);","
20+
")
21+
#20005=@"loc,{#10000},2,1,2,51"
22+
locations_default(#20005,#10000,2,1,2,51)
23+
hasLocation(#20004,#20005)
24+
numlines(#20001,2,2,0)
25+
#20006=*
26+
tokeninfo(#20006,7,#20001,0,"import")
27+
#20007=@"loc,{#10000},1,1,1,6"
28+
locations_default(#20007,#10000,1,1,1,6)
29+
hasLocation(#20006,#20007)
30+
#20008=*
31+
tokeninfo(#20008,8,#20001,1,"{")
32+
#20009=@"loc,{#10000},1,8,1,8"
33+
locations_default(#20009,#10000,1,8,1,8)
34+
hasLocation(#20008,#20009)
35+
#20010=*
36+
tokeninfo(#20010,6,#20001,2,"language")
37+
#20011=@"loc,{#10000},1,10,1,17"
38+
locations_default(#20011,#10000,1,10,1,17)
39+
hasLocation(#20010,#20011)
40+
#20012=*
41+
tokeninfo(#20012,8,#20001,3,"}")
42+
#20013=@"loc,{#10000},1,19,1,19"
43+
locations_default(#20013,#10000,1,19,1,19)
44+
hasLocation(#20012,#20013)
45+
#20014=*
46+
tokeninfo(#20014,6,#20001,4,"from")
47+
#20015=@"loc,{#10000},1,21,1,24"
48+
locations_default(#20015,#10000,1,21,1,24)
49+
hasLocation(#20014,#20015)
50+
#20016=*
51+
tokeninfo(#20016,4,#20001,5,"'settings'")
52+
#20017=@"loc,{#10000},1,26,1,35"
53+
locations_default(#20017,#10000,1,26,1,35)
54+
hasLocation(#20016,#20017)
55+
#20018=*
56+
tokeninfo(#20018,8,#20001,6,";")
57+
#20019=@"loc,{#10000},1,36,1,36"
58+
locations_default(#20019,#10000,1,36,1,36)
59+
hasLocation(#20018,#20019)
60+
#20020=*
61+
tokeninfo(#20020,7,#20001,7,"const")
62+
#20021=@"loc,{#10000},2,1,2,5"
63+
locations_default(#20021,#10000,2,1,2,5)
64+
hasLocation(#20020,#20021)
65+
#20022=*
66+
tokeninfo(#20022,6,#20001,8,"strings")
67+
#20023=@"loc,{#10000},2,7,2,13"
68+
locations_default(#20023,#10000,2,7,2,13)
69+
hasLocation(#20022,#20023)
70+
#20024=*
71+
tokeninfo(#20024,8,#20001,9,"=")
72+
#20025=@"loc,{#10000},2,15,2,15"
73+
locations_default(#20025,#10000,2,15,2,15)
74+
hasLocation(#20024,#20025)
75+
#20026=*
76+
tokeninfo(#20026,6,#20001,10,"await")
77+
#20027=@"loc,{#10000},2,17,2,21"
78+
locations_default(#20027,#10000,2,17,2,21)
79+
hasLocation(#20026,#20027)
80+
#20028=*
81+
tokeninfo(#20028,7,#20001,11,"import")
82+
#20029=@"loc,{#10000},2,23,2,28"
83+
locations_default(#20029,#10000,2,23,2,28)
84+
hasLocation(#20028,#20029)
85+
#20030=*
86+
tokeninfo(#20030,8,#20001,12,"(")
87+
#20031=@"loc,{#10000},2,29,2,29"
88+
locations_default(#20031,#10000,2,29,2,29)
89+
hasLocation(#20030,#20031)
90+
#20032=*
91+
tokeninfo(#20032,8,#20001,13,"`")
92+
#20033=@"loc,{#10000},2,30,2,30"
93+
locations_default(#20033,#10000,2,30,2,30)
94+
hasLocation(#20032,#20033)
95+
#20034=*
96+
tokeninfo(#20034,4,#20001,14,"./i18n/")
97+
#20035=@"loc,{#10000},2,31,2,37"
98+
locations_default(#20035,#10000,2,31,2,37)
99+
hasLocation(#20034,#20035)
100+
#20036=*
101+
tokeninfo(#20036,8,#20001,15,"${")
102+
#20037=@"loc,{#10000},2,38,2,39"
103+
locations_default(#20037,#10000,2,38,2,39)
104+
hasLocation(#20036,#20037)
105+
#20038=*
106+
tokeninfo(#20038,6,#20001,16,"language")
107+
#20039=@"loc,{#10000},2,40,2,47"
108+
locations_default(#20039,#10000,2,40,2,47)
109+
hasLocation(#20038,#20039)
110+
#20040=*
111+
tokeninfo(#20040,8,#20001,17,"}")
112+
#20041=@"loc,{#10000},2,48,2,48"
113+
locations_default(#20041,#10000,2,48,2,48)
114+
hasLocation(#20040,#20041)
115+
#20042=*
116+
tokeninfo(#20042,4,#20001,18,"")
117+
#20043=@"loc,{#10000},2,49,2,48"
118+
locations_default(#20043,#10000,2,49,2,48)
119+
hasLocation(#20042,#20043)
120+
#20044=*
121+
tokeninfo(#20044,8,#20001,19,"`")
122+
#20045=@"loc,{#10000},2,49,2,49"
123+
locations_default(#20045,#10000,2,49,2,49)
124+
hasLocation(#20044,#20045)
125+
#20046=*
126+
tokeninfo(#20046,8,#20001,20,")")
127+
#20047=@"loc,{#10000},2,50,2,50"
128+
locations_default(#20047,#10000,2,50,2,50)
129+
hasLocation(#20046,#20047)
130+
#20048=*
131+
tokeninfo(#20048,8,#20001,21,";")
132+
#20049=@"loc,{#10000},2,51,2,51"
133+
locations_default(#20049,#10000,2,51,2,51)
134+
hasLocation(#20048,#20049)
135+
#20050=*
136+
tokeninfo(#20050,0,#20001,22,"")
137+
#20051=@"loc,{#10000},3,1,3,0"
138+
locations_default(#20051,#10000,3,1,3,0)
139+
hasLocation(#20050,#20051)
140+
toplevels(#20001,0)
141+
#20052=@"loc,{#10000},1,1,3,0"
142+
locations_default(#20052,#10000,1,1,3,0)
143+
hasLocation(#20001,#20052)
144+
#20053=@"module;{#10000},1,1"
145+
scopes(#20053,3)
146+
scopenodes(#20001,#20053)
147+
scopenesting(#20053,#20000)
148+
isModule(#20001)
149+
isES2015Module(#20001)
150+
#20054=@"var;{language};{#20053}"
151+
variables(#20054,"language",#20053)
152+
#20055=@"local_type_name;{language};{#20053}"
153+
local_type_names(#20055,"language",#20053)
154+
#20056=@"local_namespace_name;{language};{#20053}"
155+
local_namespace_names(#20056,"language",#20053)
156+
variables(#20054,"language",#20053)
157+
#20057=@"var;{strings};{#20053}"
158+
variables(#20057,"strings",#20053)
159+
local_type_names(#20055,"language",#20053)
160+
local_namespace_names(#20056,"language",#20053)
161+
#20058=*
162+
stmts(#20058,27,#20001,0,"import ... tings';")
163+
hasLocation(#20058,#20003)
164+
stmtContainers(#20058,#20001)
165+
#20059=*
166+
exprs(#20059,4,#20058,-1,"'settings'")
167+
hasLocation(#20059,#20017)
168+
enclosingStmt(#20059,#20058)
169+
exprContainers(#20059,#20001)
170+
literals("settings","'settings'",#20059)
171+
#20060=*
172+
exprs(#20060,83,#20058,0,"language")
173+
hasLocation(#20060,#20011)
174+
enclosingStmt(#20060,#20058)
175+
exprContainers(#20060,#20001)
176+
#20061=*
177+
exprs(#20061,0,#20060,0,"language")
178+
hasLocation(#20061,#20011)
179+
enclosingStmt(#20061,#20058)
180+
exprContainers(#20061,#20001)
181+
literals("language","language",#20061)
182+
#20062=*
183+
exprs(#20062,78,#20060,1,"language")
184+
hasLocation(#20062,#20011)
185+
enclosingStmt(#20062,#20058)
186+
exprContainers(#20062,#20001)
187+
literals("language","language",#20062)
188+
decl(#20062,#20054)
189+
typedecl(#20062,#20055)
190+
namespacedecl(#20062,#20056)
191+
#20063=*
192+
stmts(#20063,22,#20001,1,"const s ... age}`);")
193+
hasLocation(#20063,#20005)
194+
stmtContainers(#20063,#20001)
195+
#20064=*
196+
exprs(#20064,64,#20063,0,"strings ... uage}`)")
197+
#20065=@"loc,{#10000},2,7,2,50"
198+
locations_default(#20065,#10000,2,7,2,50)
199+
hasLocation(#20064,#20065)
200+
enclosingStmt(#20064,#20063)
201+
exprContainers(#20064,#20001)
202+
#20066=*
203+
exprs(#20066,78,#20064,0,"strings")
204+
hasLocation(#20066,#20023)
205+
enclosingStmt(#20066,#20063)
206+
exprContainers(#20066,#20001)
207+
literals("strings","strings",#20066)
208+
decl(#20066,#20057)
209+
#20067=*
210+
exprs(#20067,92,#20064,1,"await i ... uage}`)")
211+
#20068=@"loc,{#10000},2,17,2,50"
212+
locations_default(#20068,#10000,2,17,2,50)
213+
hasLocation(#20067,#20068)
214+
enclosingStmt(#20067,#20063)
215+
exprContainers(#20067,#20001)
216+
#20069=*
217+
exprs(#20069,99,#20067,0,"import( ... uage}`)")
218+
#20070=@"loc,{#10000},2,23,2,50"
219+
locations_default(#20070,#10000,2,23,2,50)
220+
hasLocation(#20069,#20070)
221+
enclosingStmt(#20069,#20063)
222+
exprContainers(#20069,#20001)
223+
#20071=*
224+
exprs(#20071,71,#20069,0,"`./i18n/${language}`")
225+
#20072=@"loc,{#10000},2,30,2,49"
226+
locations_default(#20072,#10000,2,30,2,49)
227+
hasLocation(#20071,#20072)
228+
enclosingStmt(#20071,#20063)
229+
exprContainers(#20071,#20001)
230+
#20073=*
231+
exprs(#20073,72,#20071,0,"./i18n/")
232+
hasLocation(#20073,#20035)
233+
enclosingStmt(#20073,#20063)
234+
exprContainers(#20073,#20001)
235+
literals("./i18n/","./i18n/",#20073)
236+
#20074=*
237+
exprs(#20074,79,#20071,1,"language")
238+
hasLocation(#20074,#20039)
239+
enclosingStmt(#20074,#20063)
240+
exprContainers(#20074,#20001)
241+
literals("language","language",#20074)
242+
bind(#20074,#20054)
243+
#20075=*
244+
entry_cfg_node(#20075,#20001)
245+
#20076=@"loc,{#10000},1,1,1,0"
246+
locations_default(#20076,#10000,1,1,1,0)
247+
hasLocation(#20075,#20076)
248+
#20077=*
249+
exit_cfg_node(#20077,#20001)
250+
hasLocation(#20077,#20051)
251+
successor(#20063,#20066)
252+
successor(#20071,#20073)
253+
successor(#20074,#20069)
254+
successor(#20073,#20074)
255+
successor(#20069,#20067)
256+
successor(#20067,#20064)
257+
successor(#20066,#20071)
258+
successor(#20064,#20077)
259+
successor(#20058,#20063)
260+
successor(#20060,#20058)
261+
successor(#20075,#20060)
262+
numlines(#10000,2,2,0)
263+
filetype(#10000,"javascript")

0 commit comments

Comments
 (0)