-
Notifications
You must be signed in to change notification settings - Fork 48.8k
Allow jsx to write tags with bracket, instead of dot, notation. #1240
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
Conversation
This will allow for hyphenated tags in the future as something like `React.DOM["font-face"](content, mountNode)` instead of the invalid `React.DOM.font-face.(content, mountNode)` Many SVG tags have hyphenated tags so this would be a good thing to have.
Would be nice to share logic with quoteAttrName in xjs.js. |
); | ||
var tagOpening; | ||
if (isFallbackTag) { | ||
tagOpening = jsxObjIdent + '["' + (nameObject.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 believe this will break closure compiler minification. I think this would be a good idea if we could detect if it is not a valid JS identifier (ie. contains -
) and use this only for invalid identifiers
Also centralize validity logic in xjs.js.
@spicyj How does this look? |
if (isValidIdentifier(nameObject.name)) { | ||
tagOpening = jsxObjIdent + '.' + (nameObject.name); | ||
} else { | ||
tagOpening = jsxObjIdent + '["' + (nameObject.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.
Maybe '[' + JSON.stringify(nameObject.name) + ']'
here?
Looks pretty reasonable. I'll let @jeffmo review and merge. |
Going by how everything HTML-related is camelCased in JavaScript rather than hyphenated, doesn't it simply make more sense to call it |
@nschaubeck Right, but lowercase+hyphens is the HTML/markup naming convention, the general naming convention for HTML-related stuff in JavaScript is camelCased like all the official HTML APIs are. |
@syranide So are you saying that JSX shouldn't support hyphenated tags? Or are you saying that it should supper camelCased version of hyphenated tags? Do those have to be mutually exclusive? JSX isn't a standard JS HTML API, it's an intermediary markup of sorts, so it makes sense to have this support to me. |
@nschaubeck My point of view (I'm not an official dev) would be that it might make sense for Personally I see two big issues:
Is it weird to separate from the standard? Kind of, but we already have and JSX is not HTML, it's JavaScript and it's just sugar. So in many ways it makes sense (to me) for the notation to be JS-style ( Side-note, the |
Closing in favor of #1539 which does the same thing and is a little cleaner -- thanks for sending this in though! |
This will allow for hyphenated tags in the future as something like
React.DOM["font-face"](content, mountNode)
instead of the invalid
React.DOM.font-face.(content, mountNode)
Many SVG tags have hyphenated tags so this would be a good thing to have.