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
[tsx] <T extends U></T>;
is not parsed correctly
#47355
Comments
In this you'd need to write |
Seems Babel handles it correctly 🤔 |
The Babel behavior is surprising to say the least This is parsed as a let f = <T extends U>(x: T) => { console.log('hi') }
f();
//</T> This is parsed as a generic arrow function: let f = <T extends U>(x: T) => { console.log('hi'); }
f();
//</T> Not sure I would call this "correctly" - it appears to be entirely heuristical |
Ah, that's interesting to know😄 |
Yeah, Babel first tries to parse it as JSX and then falls back to an arrow function. In your specific example, the semicolon make I reported this "bug" while checking what need to do to align to your parser. |
FWIW, I actually like Babel's result more. It's better to be parsed as correctly as possible before spitting an error. |
Downside of the Babel behavior is that it basically requires infinite lookahead. |
Bug Report
🔎 Search Terms
jsx extends ambiguity type parameters
🕗 Version & Regression Information
I only tested 4.5.4 and Nighty on the repl
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The second JSX expression is parsed as a malformed arrow function
🙂 Expected behavior
Both are valid JSX elements
The text was updated successfully, but these errors were encountered: