Closed NotWearingPants closed 2 years ago
I think it's sometimes hard to enforce with the grammar certain restrictions. Doing so can complicate a lot the grammar. Usually people do some of those checks after parsing.
Yeah, catching all possible errors is explicitly not a goal of the project. We're fine with allowing some invalid code if it makes the grammar simpler or the parse table smaller.
Looking at the link that you posted, you can actually see that the TypeScript compiler parses this successfully too. That's how it's able to report a semantic error message:
The left-hand side of a 'for .. in' statement must be of type
string
orany
The following piece of code is invalid but it is parsed correctly:
Here's a link to the TypeScript Playground showing that the snippet above is invalid JavaScript or TypeScript
The output of
tree-sitter
playground is the following:This should be an error, the LHS of a for-in loop can't be an expression, only identifier/member_expression/destructuring.