diff --git a/acorn/src/statement.js b/acorn/src/statement.js index 42bcf7672..95978708a 100644 --- a/acorn/src/statement.js +++ b/acorn/src/statement.js @@ -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) diff --git a/test/tests-using.js b/test/tests-using.js index 5d9ec80f5..5726987bf 100644 --- a/test/tests-using.js +++ b/test/tests-using.js @@ -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 // =============================================================================