diff --git a/src/acorn/parser/class-fields.js b/src/acorn/parser/class-fields.js index f1aade4e3..65fb1c231 100644 --- a/src/acorn/parser/class-fields.js +++ b/src/acorn/parser/class-fields.js @@ -59,6 +59,21 @@ function init() { } if (this.isContextual("static")) { + if (nextType === tt.star) { + return Reflect.apply(func, this, args) + } + + const nextNextType = lookahead(next).type + + if (nextNextType !== tt.braceR && + nextNextType !== tt.eq && + nextNextType !== tt.semi && + (next.isContextual("async") || + next.isContextual("get") || + next.isContextual("set"))) { + return Reflect.apply(func, this, args) + } + next.parsePropertyName(this.startNode()) if (next.type === tt.parenL) { diff --git a/test/compiler-tests.mjs b/test/compiler-tests.mjs index 09b2284d5..7d77b1c35 100644 --- a/test/compiler-tests.mjs +++ b/test/compiler-tests.mjs @@ -393,27 +393,27 @@ describe("compiler tests", () => { it("should parse class fields syntax", () => { const code = [ "export class A { a }", - "export class B { b = 1 }", - "export class C { [c] }", - "export class D { [d] = 1 }", - "export class E { static e }", - "export class F { static f = 1 }", - "export class G { static [g] }", - "export class H { static [h] = 1 }", - "export class I { #i }", - "export class J { static #j }", - "export class K { static #k = 1 }", - "export class L { async }", - "export class M { get }", - "export class N { set }", - "export class O { static }", - "export class P {", - ' #p = "p"', - " p() {", - " return this.#p", - " }", - "}", - "export class Q {", + "export class B { [b] }", + "export class C { static c }", + "export class D { static [d] }", + "export class E { #e }", + "export class F { static #f }", + "export class G { async }", + "export class H { get }", + "export class I { set }", + "export class J { static }", + "export class K {", + " a = 1", + " [b] = 1", + " static c = 1", + " static [d] = 1", + " static #e = 1", + " e() { this.#e }", + " static get f() {}", + " static set f(v) {}", + " static async g() {}", + " static *h() {}", + " static async *i() {}", " async = 1;", " get = 1", " set = 1",