lezer-parser/javascript

Parenthesized extends expression seems to confuse the parser

Closed this issue · 3 comments

Trying to parse a class declaration like this

class A extends (class B {}) {}

seems to confuse the parser quite a bit:

image

Although from looking at the code it appears that arbitrary expressions are supported after extends.

This is parsing with {typescript:true}.

At some point, typescript only allowed types after extends, which makes sense because it needs to parse things like SomeClass<TypeParam>, which isn't an expression.

However, it seems like modern TS somehow allows both expressions and types there. From microsoft/TypeScript#3516, it seems like they just parse an expression followed by an optional type argument list. Attached patch switches the grammar to do something similar.

Thanks, this seems reasonable!