Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions acorn/src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ pp.isUsingKeyword = function(isAwaitUsing, isFor) {
if (lineBreak.test(this.input.slice(this.pos, next))) return false

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

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

let ch = this.fullCharCodeAt(next)
Expand Down
3 changes: 3 additions & 0 deletions test/tests-using.js
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,9 @@ testFail("for (await using a of x) {}", "Await using cannot appear outside of as
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"});
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"});

// await using double lookahead should detect using keyword correctly
testFail("async () => { await using\\u0061 b = c }", "Unexpected token (1:32)", {ecmaVersion: 17, sourceType: "module"});

// =============================================================================
// EDGE CASES - Unusual but valid scenarios and boundary conditions
// =============================================================================
Expand Down