Skip to content

Commit 51a7243

Browse files
authored
Merge pull request #10017 from erik-krogh/forAwait
JS: support top-level for await statements
2 parents 09d249e + a28948e commit 51a7243

File tree

5 files changed

+469
-2
lines changed

5 files changed

+469
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,11 @@ private DynamicImport parseDynamicImport(Position startLoc) {
448448
protected Statement parseForStatement(Position startLoc) {
449449
int startPos = this.start;
450450
boolean isAwait = false;
451-
if (this.inAsync && this.eatContextual("await")) isAwait = true;
451+
if (this.inAsync || (options.esnext() && !this.inFunction)) {
452+
if (this.eatContextual("await")) {
453+
isAwait = true;
454+
}
455+
}
452456
Statement forStmt = super.parseForStatement(startLoc);
453457
if (isAwait) {
454458
if (forStmt instanceof ForOfStatement) ((ForOfStatement) forStmt).setAwait(true);

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-06-27";
44+
public static final String EXTRACTOR_VERSION = "2022-07-11";
4545

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
async function foo() {
2+
for await (const call of calls) {
3+
call();
4+
}
5+
}
6+
7+
for await (const call of calls) {
8+
call();
9+
}

0 commit comments

Comments
 (0)