Skip to content
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

Merged
merged 8 commits into from
Oct 29, 2017
Merged

Conversation

jukben
Copy link
Contributor

@jukben jukben commented Oct 26, 2017

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes, close #6535
Tests Added + Pass? Yes
Documentation PR Added
Any Dependency Changes?

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. 😔

* If there is flag "throwIfNamespace"
* print XMLNamespace like string literal
*/
return t.stringLiteral(node.namespace.name + ":" + node.name.name);
Copy link
Contributor Author

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.)

Copy link
Member

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

Copy link
Member

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)

Copy link
Contributor Author

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. 😆

@hzoo
Copy link
Member

hzoo commented Oct 26, 2017

It passes in travis so it's fine, looks like a cache issue or you aren't rebased

@jukben
Copy link
Contributor Author

jukben commented Oct 26, 2017

@hzoo You are right. I've rebased it. 👍

@xtuc xtuc added the PR: New Feature 🚀 A type of pull request used for our changelog categories label Oct 26, 2017
@babel-bot
Copy link
Collaborator

babel-bot commented Oct 26, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/5508/

Copy link
Member

@xtuc xtuc left a 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.",
Copy link
Member

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?

Copy link
Member

@hzoo hzoo Oct 26, 2017

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)"

Copy link
Member

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.

Copy link
Contributor Author

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. 👍

@babel babel deleted a comment from babel-bot Oct 26, 2017
@jukben
Copy link
Contributor Author

jukben commented Oct 27, 2017

@xtuc Sorry! I've added documentation in the last commit.

Copy link
Member

@existentialism existentialism left a 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.
Copy link
Member

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.

Copy link
Contributor Author

@jukben jukben Oct 27, 2017

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.",
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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

@hzoo hzoo merged commit 04d2c03 into babel:master Oct 29, 2017
@hzoo
Copy link
Member

hzoo commented Oct 29, 2017

Awesome, nice work @jukben! 👌

@DanielRuf
Copy link

Awesome, nice work @jukben! 👌

Definitely, and very fast and great quality =)

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 1, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a 'throwIfNamespace' option for JSX transform that defaults to 'true'
7 participants