Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public class fields without a default value break the parser #20

Closed
djfpaagman opened this issue Nov 16, 2023 · 1 comment
Closed

Public class fields without a default value break the parser #20

djfpaagman opened this issue Nov 16, 2023 · 1 comment

Comments

@djfpaagman
Copy link
Contributor

djfpaagman commented Nov 16, 2023

I was playing around with the LSP and noticed errors for some of my Stimulus controllers.

Debugging a bit I noticed that the parser fails on them, because we use some empty public class fields like so:

import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
  someField;

  // this is just an example how we use them later, not related to the bug
  doSomething() {
    this.someField = "some value";
  }
}
  • It does work if you set it with a value, like someField = "initial value".
  • Having static in front of it also breaks

It fails on this line:

if (node.value.type === "ArrowFunctionExpression") {
with TypeError: Cannot read properties of null (reading 'type')

I guess those nodes don't have a type, so some other parsing exception should be added.

Happy to help, but I don't have a good idea in what direction to go.

edit later that day: I made a PR that implements a possible fix in #21!

@marcoroth
Copy link
Owner

Resolved via #21, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants