diff --git a/acorn/src/state.js b/acorn/src/state.js index c2e41115..946bf2d8 100644 --- a/acorn/src/state.js +++ b/acorn/src/state.js @@ -104,9 +104,10 @@ export class Parser { get inAsync() { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 && !this.currentVarScope().inClassFieldInit } get canAwait() { + if (this.currentThisScope().inClassFieldInit) return false for (let i = this.scopeStack.length - 1; i >= 0; i--) { let scope = this.scopeStack[i] - if (scope.inClassFieldInit || scope.flags & SCOPE_CLASS_STATIC_BLOCK) return false + if (scope.flags & SCOPE_CLASS_STATIC_BLOCK) return false if (scope.flags & SCOPE_FUNCTION) return (scope.flags & SCOPE_ASYNC) > 0 } return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction diff --git a/test/tests-asyncawait.js b/test/tests-asyncawait.js index ed492e97..28a212e4 100644 --- a/test/tests-asyncawait.js +++ b/test/tests-asyncawait.js @@ -3540,3 +3540,5 @@ testFail("async() => await (5) ** 6", "Unexpected token (1:21)", {ecmaVersion: 8 testFail("4 + async() => 2", "Unexpected token (1:12)", {ecmaVersion: 8, loose: false}) testFail("async function𝐬 f() {}", "Unexpected token (1:17)", {ecmaVersion: 8}) + +testFail("async () => class { x = await 1 }", "Cannot use 'await' as identifier inside an async function (1:24)", {ecmaVersion: 2024})