Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Fix parsing of computed class fields. [closes #787]
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Apr 27, 2019
1 parent c93add3 commit 3c50b83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
20 changes: 11 additions & 9 deletions src/acorn/parser/class-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand All @@ -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()
Expand Down
22 changes: 12 additions & 10 deletions test/compiler-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 3c50b83

Please sign in to comment.