Closed jackschu closed 4 weeks ago
I think the best way to fix this was just to allow an optional "automatic semicolon" after 'static', creating a conflict and letting GLR resolve it, thanks for the report
hey @amaanq it seems like #314 will cause treesitter to parse the following block without emitting an error
class Foo {
static ; {}
}
But a JS runtime would give Unexpected token '{'
is this OK?
I've vaguely heard that treesitter is allowed to parse more than what the spec allows, but I'm curious how you think about it
you're right, sorry about that! it should be just _automatic_semicolon
, should be fixed in a sec
Repro
The following piece of code is valid but it is parsed incorrectly:
Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript: https://www.typescriptlang.org/play?#code/MYGwhgzhAEBiD29oG8BQ0PQgFzNglsOpgPQkAW+qxamGAjNANTT0DcxAvqpx0A
The output of
tree-sitter parse
is the following:this is on commit
ac10a11e0c8db512f70e6b798260d2516d22454c
Analysis
I did a bunch of digging, it seems like this happens because the language believe 'static' is the start of a property name I think tree sitter here should have decided that the
class_static_block
andfield_definition
here represent a conflict and gone to GLR, but somehow the presence of$._semicolon
confuses itI tried adding to
conflicts
after removingoptional(';')
and$._semicolon
, the former is clearly redundant, but the latter is load bearing because the spec requires that semicolon or else statements like this would be considered valid