Skip to content

Commit

Permalink
Fix scope-related regressions and await vs. class property initialize…
Browse files Browse the repository at this point in the history
…rs issue
  • Loading branch information
adams85 committed Dec 29, 2024
1 parent 6642f12 commit 41c82c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 7 additions & 6 deletions acorn/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 6 additions & 4 deletions acorn/src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 41c82c5

Please sign in to comment.