Skip to content

Commit 6642f12

Browse files
committed
Revert "Further refine handling of await in class fields" (except for new tests)
This reverts commit 9e365f7.
1 parent 9e365f7 commit 6642f12

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

acorn/src/expression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ pp.checkUnreserved = function({start, end, name}) {
10431043
this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator")
10441044
if (this.inAsync && name === "await")
10451045
this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function")
1046-
if (this.currentScope().inClassFieldInit && name === "arguments")
1046+
if (this.currentThisScope().inClassFieldInit && name === "arguments")
10471047
this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer")
10481048
if (this.inClassStaticBlock && (name === "arguments" || name === "await"))
10491049
this.raise(start, `Cannot use ${name} in class static initialization block`)

acorn/src/state.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,15 @@ export class Parser {
9999

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

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

104-
get inAsync() { return (this.currentScope().flags & SCOPE_ASYNC) > 0 && !this.currentScope().inClassFieldInit }
104+
get inAsync() { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 && !this.currentVarScope().inClassFieldInit }
105105

106106
get canAwait() {
107+
if (this.currentThisScope().inClassFieldInit) return false
107108
for (let i = this.scopeStack.length - 1; i >= 0; i--) {
108109
let scope = this.scopeStack[i]
109-
if (scope.flags & SCOPE_CLASS_STATIC_BLOCK || scope.inClassFieldInit) return false
110+
if (scope.flags & SCOPE_CLASS_STATIC_BLOCK) return false
110111
if (scope.flags & SCOPE_FUNCTION) return (scope.flags & SCOPE_ASYNC) > 0
111112
}
112113
return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction
@@ -122,8 +123,8 @@ export class Parser {
122123
get treatFunctionsAsVar() { return this.treatFunctionsAsVarInScope(this.currentScope()) }
123124

124125
get allowNewDotTarget() {
125-
const {flags} = this.currentThisScope()
126-
return (flags & (SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK)) > 0 || this.currentScope().inClassFieldInit
126+
const {flags, inClassFieldInit} = this.currentThisScope()
127+
return (flags & (SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK)) > 0 || inClassFieldInit
127128
}
128129

129130
get inClassStaticBlock() {

acorn/src/statement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ 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.currentScope()
745+
const scope = this.currentThisScope()
746746
const inClassFieldInit = scope.inClassFieldInit
747747
scope.inClassFieldInit = true
748748
field.value = this.parseMaybeAssign()

0 commit comments

Comments
 (0)