diff --git a/src/acorn/parser/class-fields.js b/src/acorn/parser/class-fields.js index 0d1b13b7a..759cac777 100644 --- a/src/acorn/parser/class-fields.js +++ b/src/acorn/parser/class-fields.js @@ -35,17 +35,20 @@ function init() { } function parseClassElement(func, args) { - if (this.type !== tt.name) { + const { type } = this + + if (type !== tt.bracketL && + type !== tt.name) { return Reflect.apply(func, this, args) } - const { type } = lookahead(this) + const nextType = lookahead(this).type - if (type === tt.parenL || - type === tt.star || - (type !== tt.braceR && - type !== tt.eq && - type !== tt.semi && + if (nextType === tt.parenL || + nextType === tt.star || + (nextType !== tt.braceR && + nextType !== tt.eq && + nextType !== tt.semi && (this.isContextual("async") || this.isContextual("get") || this.isContextual("set") || @@ -55,8 +58,7 @@ function init() { const node = this.startNode() - node.computed = false - node.key = this.parseIdent(true) + this.parsePropertyName(node) node.value = this.eat(tt.eq) ? this.parseExpression() diff --git a/test/compiler-tests.mjs b/test/compiler-tests.mjs index b01272a77..9e85ec83f 100644 --- a/test/compiler-tests.mjs +++ b/test/compiler-tests.mjs @@ -394,18 +394,20 @@ describe("compiler tests", () => { const code = [ "export class A { a }", 'export class B { b = "b" }', - "export class C { #c }", - "export class D { async }", - "export class E { get }", - "export class F { set }", - "export class G { static }", - "export class H {", - ' #h= "h"', - " h() {", - " return this.#h", + "export class C { [c] }", + 'export class D { [d] = "d" }', + "export class E { #e }", + "export class F { async }", + "export class G { get }", + "export class H { set }", + "export class I { static }", + "export class J {", + ' #j= "j"', + " j() {", + " return this.#j", " }", "}", - "export class I {", + "export class K {", " async = 1;", " get = 1", " set = 1",