Skip to content

Commit

Permalink
Only forbid await inside class field init values
Browse files Browse the repository at this point in the history
So that it can be used in computed properties in classes.

Makes the test262 suite run again.

Issue #1048
  • Loading branch information
marijnh committed Jun 23, 2021
1 parent 41068c9 commit 46d2f69
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
3 changes: 1 addition & 2 deletions acorn/src/scopeflags.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export const
SCOPE_ARROW = 16,
SCOPE_SIMPLE_CATCH = 32,
SCOPE_SUPER = 64,
SCOPE_DIRECT_SUPER = 128,
SCOPE_CLASS = 256
SCOPE_DIRECT_SUPER = 128

export function functionFlags(async, generator) {
return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
Expand Down
11 changes: 4 additions & 7 deletions acorn/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import {types as tt} from "./tokentype.js"
import {lineBreak} from "./whitespace.js"
import {getOptions} from "./options.js"
import {wordsRegexp} from "./util.js"
import {
SCOPE_TOP, SCOPE_FUNCTION, SCOPE_ASYNC, SCOPE_CLASS, SCOPE_GENERATOR,
SCOPE_SUPER, SCOPE_DIRECT_SUPER
} from "./scopeflags.js"
import {SCOPE_TOP, SCOPE_FUNCTION, SCOPE_ASYNC, SCOPE_GENERATOR, SCOPE_SUPER, SCOPE_DIRECT_SUPER} from "./scopeflags.js"

export class Parser {
constructor(options, input, startPos) {
Expand Down Expand Up @@ -105,9 +102,9 @@ export class Parser {
get inAsync() { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 && !this.currentVarScope().inClassFieldInit }
get canAwait() {
for (let i = this.scopeStack.length - 1; i >= 0; i--) {
let {flags} = this.scopeStack[i]
if (flags & SCOPE_FUNCTION) return (flags & SCOPE_ASYNC) > 0
if (flags & SCOPE_CLASS) return false
let scope = this.scopeStack[i]
if (scope.inClassFieldInit) return false
if (scope.flags & SCOPE_FUNCTION) return (scope.flags & SCOPE_ASYNC) > 0
}
return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction
}
Expand Down
7 changes: 1 addition & 6 deletions acorn/src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import {lineBreak, skipWhiteSpace} from "./whitespace.js"
import {isIdentifierStart, isIdentifierChar, keywordRelationalOperator} from "./identifier.js"
import {has} from "./util.js"
import {DestructuringErrors} from "./parseutil.js"
import {
functionFlags, SCOPE_SIMPLE_CATCH, SCOPE_CLASS, BIND_SIMPLE_CATCH,
BIND_LEXICAL, BIND_VAR, BIND_FUNCTION
} from "./scopeflags.js"
import {functionFlags, SCOPE_SIMPLE_CATCH, BIND_SIMPLE_CATCH, BIND_LEXICAL, BIND_VAR, BIND_FUNCTION} from "./scopeflags.js"

const pp = Parser.prototype

Expand Down Expand Up @@ -584,7 +581,6 @@ pp.parseClass = function(node, isStatement) {
let hadConstructor = false
classBody.body = []
this.expect(tt.braceL)
this.enterScope(SCOPE_CLASS)
while (this.type !== tt.braceR) {
const element = this.parseClassElement(node.superClass !== null)
if (element) {
Expand All @@ -601,7 +597,6 @@ pp.parseClass = function(node, isStatement) {
this.next()
node.body = this.finishNode(classBody, "ClassBody")
this.exitClassBody()
this.exitScope()
return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
}

Expand Down

0 comments on commit 46d2f69

Please sign in to comment.