Skip to content

Commit d3f71a6

Browse files
authored
Fix await using double lookahead edge case
FIX: Don't recognize `await using` as contextual keywords when followed directly by a backslash. Issue #1382
1 parent ad66d00 commit d3f71a6

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

acorn/src/statement.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ pp.isUsingKeyword = function(isAwaitUsing, isFor) {
8484
if (lineBreak.test(this.input.slice(this.pos, next))) return false
8585

8686
if (isAwaitUsing) {
87-
let awaitEndPos = next + 5 /* await */, after
88-
if (this.input.slice(next, awaitEndPos) !== "using" ||
89-
awaitEndPos === this.input.length ||
90-
isIdentifierChar(after = this.input.charCodeAt(awaitEndPos)) ||
91-
(after > 0xd7ff && after < 0xdc00)
87+
let usingEndPos = next + 5 /* using */, after
88+
if (this.input.slice(next, usingEndPos) !== "using" ||
89+
usingEndPos === this.input.length ||
90+
isIdentifierChar(after = this.fullCharCodeAt(usingEndPos)) ||
91+
after === 92 /* '\' */
9292
) return false
9393

94-
skipWhiteSpace.lastIndex = awaitEndPos
94+
skipWhiteSpace.lastIndex = usingEndPos
9595
let skipAfterUsing = skipWhiteSpace.exec(this.input)
96-
next = awaitEndPos + skipAfterUsing[0].length
97-
if (skipAfterUsing && lineBreak.test(this.input.slice(awaitEndPos, next))) return false
96+
next = usingEndPos + skipAfterUsing[0].length
97+
if (skipAfterUsing && lineBreak.test(this.input.slice(usingEndPos, next))) return false
9898
}
9999

100100
let ch = this.fullCharCodeAt(next)

test/tests-using.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,9 @@ testFail("for (await using a of x) {}", "Await using cannot appear outside of as
11841184
testFail("switch (x) { case 1: using y = resource; }", "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement (1:21)", {ecmaVersion: 17, sourceType: "module"});
11851185
testFail("switch (x) { case 1: break; default: using y = resource; }", "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement (1:37)", {ecmaVersion: 17, sourceType: "module"});
11861186

1187+
// await using double lookahead should detect using keyword correctly
1188+
testFail("async () => { await using\\u0061 b = c }", "Unexpected token (1:32)", {ecmaVersion: 17, sourceType: "module"});
1189+
11871190
// =============================================================================
11881191
// EDGE CASES - Unusual but valid scenarios and boundary conditions
11891192
// =============================================================================

0 commit comments

Comments
 (0)