diff --git a/acorn/src/state.js b/acorn/src/state.js index 946bf2d8..51f28595 100644 --- a/acorn/src/state.js +++ b/acorn/src/state.js @@ -104,13 +104,14 @@ 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.flags & SCOPE_CLASS_STATIC_BLOCK) return false - if (scope.flags & SCOPE_FUNCTION) return (scope.flags & SCOPE_ASYNC) > 0 + const scope = this.currentVarScope() + if (scope.flags & SCOPE_FUNCTION) { + return (scope.flags & SCOPE_ASYNC) && !scope.inClassFieldInit } - return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction + if (scope.flags & SCOPE_TOP) { + return ((this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction) && !scope.inClassFieldInit + } + return false } get allowSuper() { diff --git a/acorn/src/statement.js b/acorn/src/statement.js index 0dcfd04f..9997b926 100644 --- a/acorn/src/statement.js +++ b/acorn/src/statement.js @@ -742,11 +742,13 @@ pp.parseClassField = function(field) { if (this.eat(tt.eq)) { // To raise SyntaxError if 'arguments' exists in the initializer. - const scope = this.currentThisScope() - const inClassFieldInit = scope.inClassFieldInit - scope.inClassFieldInit = true + const thisScope = this.currentThisScope(), varScope = this.currentVarScope() + const thisScopeInClassFieldInit = thisScope.inClassFieldInit + const varScopeInClassFieldInit = varScope.inClassFieldInit + thisScope.inClassFieldInit = varScope.inClassFieldInit = true field.value = this.parseMaybeAssign() - scope.inClassFieldInit = inClassFieldInit + thisScope.inClassFieldInit = thisScopeInClassFieldInit + varScope.inClassFieldInit = varScopeInClassFieldInit } else { field.value = null }