Skip to content

Commit 41c82c5

Browse files
committed
Fix scope-related regressions and await vs. class property initializers issue
1 parent 6642f12 commit 41c82c5

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

acorn/src/state.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ export class Parser {
104104
get inAsync() { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 && !this.currentVarScope().inClassFieldInit }
105105

106106
get canAwait() {
107-
if (this.currentThisScope().inClassFieldInit) return false
108-
for (let i = this.scopeStack.length - 1; i >= 0; i--) {
109-
let scope = this.scopeStack[i]
110-
if (scope.flags & SCOPE_CLASS_STATIC_BLOCK) return false
111-
if (scope.flags & SCOPE_FUNCTION) return (scope.flags & SCOPE_ASYNC) > 0
107+
const scope = this.currentVarScope()
108+
if (scope.flags & SCOPE_FUNCTION) {
109+
return (scope.flags & SCOPE_ASYNC) && !scope.inClassFieldInit
112110
}
113-
return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction
111+
if (scope.flags & SCOPE_TOP) {
112+
return ((this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction) && !scope.inClassFieldInit
113+
}
114+
return false
114115
}
115116

116117
get allowSuper() {

acorn/src/statement.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,13 @@ pp.parseClassField = function(field) {
742742

743743
if (this.eat(tt.eq)) {
744744
// To raise SyntaxError if 'arguments' exists in the initializer.
745-
const scope = this.currentThisScope()
746-
const inClassFieldInit = scope.inClassFieldInit
747-
scope.inClassFieldInit = true
745+
const thisScope = this.currentThisScope(), varScope = this.currentVarScope()
746+
const thisScopeInClassFieldInit = thisScope.inClassFieldInit
747+
const varScopeInClassFieldInit = varScope.inClassFieldInit
748+
thisScope.inClassFieldInit = varScope.inClassFieldInit = true
748749
field.value = this.parseMaybeAssign()
749-
scope.inClassFieldInit = inClassFieldInit
750+
thisScope.inClassFieldInit = thisScopeInClassFieldInit
751+
varScope.inClassFieldInit = varScopeInClassFieldInit
750752
} else {
751753
field.value = null
752754
}

0 commit comments

Comments
 (0)