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 declare" class field definition fails to parse #270

Closed
helixbass opened this issue Dec 21, 2023 · 0 comments · Fixed by #273
Closed

"public declare" class field definition fails to parse #270

helixbass opened this issue Dec 21, 2023 · 0 comments · Fixed by #273
Labels

Comments

@helixbass
Copy link

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

class A {
  public declare readonly foo = 1;
}

Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript:

https://www.typescriptlang.org/play?#code/MYGwhgzhAECC0G8BQ1oAcCuAjEBLY0AJgKahgBOx0lYhA9gHYgCe0AZnXdALzQCMAbiQBfJEA

The output of tree-sitter parse is the following:

(program [0, 0] - [3, 0]
  (class_declaration [0, 0] - [2, 1]
    name: (type_identifier [0, 6] - [0, 7])
    body: (class_body [0, 8] - [2, 1]
      (public_field_definition [1, 2] - [1, 33]
        (accessibility_modifier [1, 2] - [1, 8])
        (ERROR [1, 9] - [1, 16]
          (property_identifier [1, 9] - [1, 16]))
        name: (property_identifier [1, 26] - [1, 29])
        value: (number [1, 32] - [1, 33])))))
tmp.ts  0 ms    (ERROR [1, 9] - [1, 16])

It looks like the grammar for public_field_definition expects declare to come before any accessibility modifier (eg public) but apparently either order is valid

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

Successfully merging a pull request may close this issue.

1 participant