Skip to content

Commit

Permalink
Revert "Further refine handling of await in class fields" (except for…
Browse files Browse the repository at this point in the history
… new tests)

This reverts commit 9e365f7.
  • Loading branch information
adams85 committed Dec 29, 2024
1 parent 9e365f7 commit 6642f12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion acorn/src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ pp.checkUnreserved = function({start, end, name}) {
this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator")
if (this.inAsync && name === "await")
this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function")
if (this.currentScope().inClassFieldInit && name === "arguments")
if (this.currentThisScope().inClassFieldInit && name === "arguments")
this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer")
if (this.inClassStaticBlock && (name === "arguments" || name === "await"))
this.raise(start, `Cannot use ${name} in class static initialization block`)
Expand Down
11 changes: 6 additions & 5 deletions acorn/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ export class Parser {

get inFunction() { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 }

get inGenerator() { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 && !this.currentScope().inClassFieldInit }
get inGenerator() { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 && !this.currentVarScope().inClassFieldInit }

get inAsync() { return (this.currentScope().flags & SCOPE_ASYNC) > 0 && !this.currentScope().inClassFieldInit }
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 || scope.inClassFieldInit) 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
Expand All @@ -122,8 +123,8 @@ export class Parser {
get treatFunctionsAsVar() { return this.treatFunctionsAsVarInScope(this.currentScope()) }

get allowNewDotTarget() {
const {flags} = this.currentThisScope()
return (flags & (SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK)) > 0 || this.currentScope().inClassFieldInit
const {flags, inClassFieldInit} = this.currentThisScope()
return (flags & (SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK)) > 0 || inClassFieldInit
}

get inClassStaticBlock() {
Expand Down
2 changes: 1 addition & 1 deletion acorn/src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ pp.parseClassField = function(field) {

if (this.eat(tt.eq)) {
// To raise SyntaxError if 'arguments' exists in the initializer.
const scope = this.currentScope()
const scope = this.currentThisScope()
const inClassFieldInit = scope.inClassFieldInit
scope.inClassFieldInit = true
field.value = this.parseMaybeAssign()
Expand Down

0 comments on commit 6642f12

Please sign in to comment.