-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Cannot parse <T>(t: T) => T
under JSX mode (problems with expression prefix)
#165
Comments
Curious how esbuild parses it, since they obv support distinguishing between TSX types and elements declarations: https://github.com/evanw/esbuild/blob/fc37c2fa9de2ad77476a6d4a8f1516196b90187e/internal/js_parser/ts_parser_test.go#L556 Would be sweet to replicate these tests if possible too. Replicating the tests here is probably fine since it's MIT? https://github.com/evanw/esbuild/blob/main/LICENSE.md |
Hmm, may be a design problem. See the last two sentences.
I could change it so that lexing "pauses" on RegExp and JSX. Then a channel from the parser could communicate where it is? Don't like the idea of that big of change considering it is only for an edge case. That TS parser tests look good. Shouldn't be too hard to grep out and make some tests for under |
<T>(t: T) => T
under JSX mode<T>(t: T) => T
under JSX mode (problems with expression prefix)
A few more problems with the current "expression prefix" token thing for changing the lexing mode:
I think more 'state' in the lexer could solve this. There is current low level state, but a higher level state that captures the state here
Might attempt in #173, might not? 🤷 |
The JSX lexing kicks in after the previous token is considered a expression prefix (this works for JSX lexing). So for the colon
:
, JSX lexing mode kicks inThis means that the following doesn't work:
This also doesn't parse correctly
Not sure how to tackle this. The lexing is designed to be context-free. Communicating with the parser would require architectural changes. Maybe the lexer could hold a state so that it knows it is in some mode? Maybe could lookahead in the lexer and check that the next == '('?
It is a shame because the expression prefix mode works really well ATM and covers regular expression stuff.
I think this works on non JSX parsing mode?
Alternatively this works ATM
This is not to do with generic arrow function syntax (don't do this)
or the casting syntax (never do this)
The text was updated successfully, but these errors were encountered: