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.
#11042
Comments
Hey @bradzacher! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
Seems like a nice thing to add to Espree/Acorn (https://github.com/acornjs/acorn-jsx), as well! |
This is a breaking change, so getting it in with Babel 8 would be good. |
Is there a timeline for the babel 8 release? |
We're just a few weeks away: #10746 This is actually a super easy fix, so it's a Good First Issue. Do you want to do it? The only changes necessary are in babel/packages/babel-parser/src/plugins/jsx/index.js Lines 411 to 447 in 1815c34
|
Sure thing, I'll take a look at it in the next few days. |
Closed by #11046 |
Feature Request
Is your feature request related to a problem? Please describe.
The JSX spec [1][2] lists
}
and>
as invalid JSX text characters.However, babel does not throw a syntax error when it encounters a naked
}
or>
in a JSXText string.According to the spec, the only way you should be able to include either of these characters (similarly for
{
and<
), is via a string expression:{'>'}
.Describe the solution you'd like
I propose that babel should follow the JSX spec, and throw a syntax error if it encounters a "naked"
}
or>
within jsx text.From my experience, it's uncommon that these characters are intentionally put in JSX text, and are instead the result of typos (i.e. typing
{}
, but having an editor auto-complete an extra}
=>{}}
), or copy pasting errors.Flow has already updated their parser to flag this as an error [3][4]. TypeScript is happy to make this change as well [5] (if Babel makes the change, as babel is generally considered the "reference implementation" for JSX).
I have also raised an issue in acorn for the same functionality [6].
Describe alternatives you've considered
}
to{'}'}
.Teachability, Documentation, Adoption, Migration Strategy
If you can, explain how users will be able to use this and possibly write out a version the docs.
Maybe a screenshot or design?
I think the best way to document this would be via clear and explicit error messaging.
For example, the following code:
produces the following flow errors:
flow.org repl
Related:
[1] https://facebook.github.io/jsx/
[2] facebook/jsx#18
[3] https://github.com/facebook/flow/blob/master/Changelog.md#01160
[4] facebook/flow@e1d0038
[5] microsoft/TypeScript#36341
[6] acornjs/acorn-jsx#106
The text was updated successfully, but these errors were encountered: