"public declare" class field definition fails to parse
helixbass opened this issue · comments
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:
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