Skip to content

Commit

Permalink
Fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Mar 29, 2024
1 parent 59f9780 commit 32c1785
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion acorn/src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ pp.parseForStatement = function(node) {
let startsWithLet = this.isContextual("let"), isForOf = false
let containsEsc = this.containsEsc
let refDestructuringErrors = new DestructuringErrors
let initPos = this.start
let init = awaitAt > -1
? this.parseExprSubscripts(refDestructuringErrors, "await")
: this.parseExpression(true, refDestructuringErrors)
Expand All @@ -245,7 +246,7 @@ pp.parseForStatement = function(node) {
if (this.type === tt._in) this.unexpected(awaitAt)
node.await = true
} else if (isForOf && this.options.ecmaVersion >= 8) {
if (!containsEsc && init.type === "Identifier" && init.name === "async") this.unexpected()
if (init.start === initPos && !containsEsc && init.type === "Identifier" && init.name === "async") this.unexpected()
else if (this.options.ecmaVersion >= 9) node.await = false
}
if (startsWithLet && isForOf) this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'.")
Expand Down
1 change: 1 addition & 0 deletions test/tests-async-iteration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2000,3 +2000,4 @@ testFail("for (async of [1]) {}", "Unexpected token (1:14)", {ecmaVersion: 9})

testFail("async () => { for (async\nof []); }", "Unexpected token (2:0)", {ecmaVersion: 9})
testFail("async () => { for (async of\n[]); }", "Unexpected token (2:0)", {ecmaVersion: 9})
test("for ((async) of [7]);", {}, {ecmaVersion: 9})

0 comments on commit 32c1785

Please sign in to comment.