-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Proposal: throw syntax error for }
and >
in JSX text.
#36341
Comments
Catching up to facebook/jsx#18 😉 |
Well, upon further consideration, this is kind of messed up. It's not an error in Babel, despite this being in the JSX spec for quite a while. I think we'd want Babel (being the de facto "correct" JSX implementation) to issue a syntax error here first so that it doesn't look like we're just making up rules |
Seems reasonable, I'll look at raising an issue there as well, as I'd love to see this across all implementations. |
Raised as babel/babel#11042 |
FYI - I'm working on a PR to add this to babel - they would like to get the change in for release with babel 8 (which is due in a few weeks). |
The PR was just merged into the babel8 branch, so it'll be released with v8. Off the top of your head, did you have a pointer for where I would go about making this change within the typescript codebase? I'd be happy to raise a PR to make it happen! |
Honestly, I'm kind of surprised that with the fact that the implementations all work the way they currently do, that we didn't consider this a spec bug. Is there a good reason we want all these implementations to break people? (i.e. who are we helping?) Should we check with the JSX spec authors? |
I think detecting misbalanced |
Backstory for how this got implemented in flow: A dangling Fast forward another few weeks and the change was released in flow, and the flow engineer manually fixed up the remaining few hundred errors.
This is a net benefit for everyone - it's very rare that a dangling |
* Throw syntax error for `}` and `>` in JSX text Fixes #36341 * Add codefix for error
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms:
jsx children child
Code
Expected behavior:
Typescript throws a syntax error, as
}
and>
are not valid JSX text characters, as per the JSX spec:https://facebook.github.io/jsx/
Actual behavior:
No errors.
Related - typescript errors on
{
and<
, but not because they are invalid characters; it instead errors due to the ambiguity in the syntax and it treating them as an unterminated expression and an incorrect tag respectively.Playground Link: https://www.typescriptlang.org/play/?jsx=2&ssl=1&ssc=1&pln=5&pc=1#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwBQduEAdqvMnALxwA8AJsABuAPgC+PAPQCR9Jq3gAjLr2nDhk1fSA
Related Issues:
https://github.com/facebook/flow/blob/master/Changelog.md#01160
facebook/flow@e1d0038
babel/babel#11042
acornjs/acorn-jsx#106
I'm bringing this up because flow just made this change, and it seems like a logical one.
Considering it's almost always going to be a UI bug caused due to typos, it seems like a good idea to error on it. Those that want those characters can be explicit and wrap the character as an expression (
{'>'}
, which is the same thing you do if you want an end of line space).For reference, this is what now happens when you attempt to parse
}
or>
in flow:This code:
produces the following flow errors:
flow.org repl
The text was updated successfully, but these errors were encountered: