-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add a 'throwIfNamespace' option for JSX transform #6563
Conversation
* If there is flag "throwIfNamespace" | ||
* print XMLNamespace like string literal | ||
*/ | ||
return t.stringLiteral(node.namespace.name + ":" + node.name.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure about this, should I make some helper for it? (I've discovered that there is getQualifiedJSXName
, so maybe something in this way.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can a namespace be nested? I don't think a helper is necessary, and you can use a template literal here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok looks like they can't be nested (parse error)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that namespace could be nested. Ok, I will go for template literal, I've wanted to stay in style with getQualifiedJSXName
implementation. 😆
It passes in travis so it's fine, looks like a cache issue or you aren't rebased |
@hzoo You are right. I've rebased it. 👍 |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/5508/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR 👍.
We're missing documentation about the new option.
); | ||
if (opts.throwIfNamespace) { | ||
throw path.buildCodeFrameError( | ||
"Namespace tags are not supported. ReactJSX is not XML.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, the error message sounds a bit strange to me. What does ReactJSX is not XML
mean? What do you think if we drop this part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something the react team would of said? They are just saying the React's version of JSX looks like XML (which supports namespace tags) but it's not
We can reword it if you think that makes sense. "React's JSX doesn't support namespace tags (although it looks similar to XML which does)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I would prefer something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried something like this, feel free to reword this. 👍
@xtuc Sorry! I've added documentation in the last commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small doc nit
|
||
`boolean`, defaults to `true`. | ||
|
||
This option controls how to handle XML Namespaces. React's don't support it thus default behavior is to throw an error when XML namespace occurs, this behavior could be suppressed by setting it to false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight grammar nit:
React's don't
-> React's JSX doesn't
Or maybe even:
Toggles whether or not to throw an error if a XML namespaced tag name is used. For example:
<f:image />Though the JSX spec allows this, it is disabled by default since React's JSX does not currently have support for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@existentialism Thanks for the grammar 😥 . At the end, I've used your version. Providing an example is a good idea.
if (opts.throwIfNamespace) { | ||
throw path.buildCodeFrameError( | ||
"Namespace tags are not supported by default. React's JSX doesn't support namespace tags." + | ||
"You can turn on the 'throwIfNamespace' flag to bypass this warning.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the template literal not work here? looks like this is all one line, and you need a space tags.You
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hzoo You are right. I'm missing a space, good catch. I've used template literals, but then I run into "line is too long' warning. But now I discovered that there is line continuation (\)
so I'm going to rewrite this.
@@ -78,7 +78,8 @@ With options: | |||
{ | |||
"plugins": [ | |||
["@babel/transform-react-jsx", { | |||
"pragma": "dom" // default pragma is React.createElement | |||
"pragma": "dom", // default pragma is React.createElement | |||
"throwIfNamespace": false // default throwIfNamespace is true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just say defaults to true
Awesome, nice work @jukben! 👌 |
Definitely, and very fast and great quality =) |
Hi guys 👋 , this is my first attempt to contribute, feel free to correct me, I've tried my best. 💪
I'm not sure about this part, to be honest: https://github.com/babel/babel/pull/6563/files#r147231979
P.S: It seems to that tests on master falling. 😔