tree-sitter / tree-sitter-javascript

Javascript grammar for tree-sitter
MIT License
318 stars 107 forks source link

Static class initialization block #222

Closed madmoizo closed 1 year ago

madmoizo commented 2 years ago

The following piece of code is valid but it is parsed incorrectly:

The random parsing seems to be a combination of export, static class initialization block and comments.

export class Incorrect {
  static {
    this.foo = true
    this.bar = false
    this.hello = 1
    this.init()
  }
}
export class Incorrect {
  static {
    this.foo= true
    this.bar = false
    this.init()
    this.hello = 1
  }
}
export class Correct {
  static {
    this.foo= true
    this.bar = false
    this.init()
    this.hello = 1
  }
}
export class Incorrect {
  static {
    // This comment affects parsing
    this.foo= true
    this.bar = false
    this.init()
    this.hello = 1
  }
}
// This comment affects parsing
export class Incorrect {
  static {
    this.foo= true
    this.bar = false
    this.init()
    this.hello = 1
  }
}

Functions call only

export class Incorrect {
  static {
    this.init()
    this.init()
    this.init()
  }
}
export class Incorrect {
  static {
    this.init()
    this.init()
    this.init()
  }
}
export class Incorrect {
  static {
    // This comment affects parsing
    this.init()
    this.init()
    this.init()
  }
}
// This comment does not affects parsing (which is already incorrect)
export class Incorrect {
  static {
    this.init()
    this.init()
    this.init()
  }
}

Functions call only no export

class Incorrect {
  static {
    this.init()
    this.init()
    this.init()
  }
}
class Correct {
  static {
    this.init()
    this.init()
    this.init()
  }
}
class Incorrect {
  static {
    // This comment does not affects parsing (which is already incorrect)
    this.init()
    this.init()
    this.init()
  }
}
// This comment does not affects parsing (which is already incorrect)
class Incorrect {
  static {
    this.init()
    this.init()
    this.init()
  }
}
maxbrunsfeld commented 2 years ago

Can you drop a link to where this language feature is described in the spec, or somewhere official?

madmoizo commented 2 years ago

https://tc39.es/ecma262/multipage/ecmascript-language-functions-and-classes.html#prod-ClassStaticBlock

madmoizo commented 1 year ago

You closed the issue, I assumed it was solved but may you explain why the parsing is still incorrect on my initial post?