Uh oh!
There was an error while loading. Please reload this page.
Support xml namespace prefix for JSX elements and attributes - #37421
Conversation
4r7d3c0
commented
Mar 17, 2020
hey man GJ do you know if it'll fix this |
Thomas Williamson (tomjw64)
commented
Mar 17, 2020
4r7d3c0 It will not. Sorry! |
Jack Works (Jack-Works)
commented
Mar 18, 2020
Just for curious, what will the type check semantics for JSX namespace? Does it checked as a whole identifier like |
Thomas Williamson (tomjw64)
commented
Mar 18, 2020
Jack Works (@Jack-Works) Good thoughts. My guess would be that it checks the whole identifier, but I didn't include any tests for that. I'll look into the details of this when I have some time. |
Jack Works (Jack-Works)
commented
Mar 24, 2020
Hi! My PR #37455 has been merged and it changed the identifier scanner to add JSX hyphen and JSX namespace support. (By a second parameter |
Jack Works (Jack-Works)
commented
Mar 25, 2020
Why close it? 🤔 |
Thomas Williamson (tomjw64)
commented
Mar 26, 2020
Oh, I thought you meant your PR had fixed the same issue. I'll reopen it, then. |
Nathan Shively-Sanders (sandersn)
commented
Apr 1, 2020
The reviewers list isn't working, but Wesley Wigham (@weswigham) and Daniel Rosenwasser (@DanielRosenwasser) , you might want to look at this too. |
As it stands this PR needs
I think Ryan Cavanaugh (@RyanCavanaugh) is a better person to speak to the expectations of this PR, and I would hold off on further work until there's further clarity. |
Wesley Wigham (weswigham)
commented
Apr 2, 2020
Unless I'm mistaken, it should get compiled to something like based on how we parse it? Which seems.... ok. Even if there's no spec stating as such, I'm not sure what else would be reasonable. |
Jack Works (Jack-Works)
commented
Apr 2, 2020
Does react ok with this emit behavior? For example have a try to use it to render svg with svg ns |
Andrew Branch (andrewbranch)
commented
Apr 2, 2020
The Babel React transform issues the message:
|
Jack Works (Jack-Works)
commented
Apr 2, 2020
Andrew Branch (@andrewbranch) How do you think the type of |
Andrew Branch (andrewbranch)
commented
Apr 2, 2020
I really doubt that it makes sense to use a nested property. I assume the property name on the element’s props type would just be |
Jack Works (Jack-Works)
commented
Apr 2, 2020
By making it nested, it is possible to reuse attributes. for example: interfaceIntrinsicElements{element: {namespace1: attributes// type referencenamespace2: attributes// type reference}}Without this, I have to write |
Victor Andrée (victorandree)
commented
Apr 3, 2020
Jack Works (@Jack-Works) What would you propose namespaced tags should emit or typecheck against? IMHO, understanding that I'm not sure what can be emitted (or typechecked against) except plain identifiers. Wouldn't nested types require nested props ( I'll note that namespaced JSX is useful to generate XML from JSX, using a package like jsx-xml. I would like this to work: import{JSXXML}from'jsx-xml';constxml=<ns:tagns:attr="foobar">foobaz</ns:tag>;With import{JSXXML}from'jsx-xml';constxml=JSXXML("ns:tag",{"ns:attr": "foobar"},"foobaz"); |
Jack Works (Jack-Works)
commented
Apr 4, 2020
Maybe we should leave the type check behavior until the real world usage |
Thomas Williamson (tomjw64)
commented
Apr 9, 2020
Is there any work I can do on this PR regarding the discussions above? It is difficult for me to discern a consenus about what is needed. |
Thomas Williamson (tomjw64)
commented
Aug 26, 2020
I have removed the check that the code is up to date with master since it has been long enough there are conflicts now. I still would be willing to move forward on this PR in my free time if there is a clear path. |
Andrew Branch (andrewbranch)
commented
Aug 26, 2020
I’d like to hear some more detailed use cases for namespaced attributes so we can make sure we’re not boxing ourselves into a type checking behavior we’ll be unhappy with. We can’t just ignore the type checking behavior for now, because if I understand correctly, merging this as-is would allow libraries to augment |
Jack Works (Jack-Works)
commented
Aug 27, 2020
We can ship the syntax first, not allowing it when |
I've been using JSX in Solid Framework, and I was hoping to use it not only for SVG namespaces, but for custom binding syntax like you find in Vue or Svelte. For example: https://vuejs.org/v2/guide/syntax.html#Arguments To be fair this is custom JSX compilation so just unbreaking this for Vue actually supports JSX but can't use its normal syntax with it I wonder if Evan You (@yyx990803) and co would be interested in this feature so that they can use their directives in JSX. EDIT: I guess it has never been mentioned before in this thread but looking at the linked issues this use case has been brought up several times(Vue, Adobe, and Solid related). From reading the threads I'd think this is a primary use case. I think SVG namespace support to mirror how normal markup work is important even if libraries like React came up with special JSX attributes as a workaround. So there are definitely real-world use cases. |
Andrew Branch (@andrewbranch) great to hear. I'll do what I can to add those tests, and reach out if I hit a snag. |
Just as with the `-` character, `:` is now also treated specially in JSX element and attribute names, but is only allowed a single time, and not at the beginning or end of the name, as is specified in the JSX spec. All tests in jsxInvalidEsprimaTestSuite still fail, but for slightly different reasons now. Two lines in jsxEsprimaFbTestSuite were uncommented as they included elements with namespaces, and they now pass without error.
3f809c8 to
c3d75d1Comparec3d75d1 to
6292eaaCompareThomas Williamson (tomjw64)
commented
Sep 19, 2020
Andrew Branch (@andrewbranch) Added all the aforementioned tests, and it looks pretty decent to my eyes. |
Andrew Branch (andrewbranch)
commented
Sep 21, 2020
This looks great! The only questions I’d like to get feedback on from the team are:
|
Great thoughts. This work parallels the work to allow the which special-cases jsx names with the |
While looking around, I also found this in I may have to look into how this might affect things if this no longer holds, although I'm not really sure what a "known property" is. |
Andrew Branch (andrewbranch)
commented
Sep 22, 2020
Great find on
|
9a7d384 to
079e82fCompareThomas Williamson (tomjw64)
commented
Sep 22, 2020
I made the adjustment on isIntrinsicJsxName. Now we get parseable JS in the React test case even when using an capitalized identifier that includes a colon. |
Andrew Branch (andrewbranch)
left a comment
There was a problem hiding this comment.
👍 and now we wait until the release-4.1 branch is cut from master and hope there aren’t too many merge conflicts in the meantime
| * Returns true if the hyphen character is not in the JSX element name. The hyphen character, if present, | ||
| * would prevent it from being a valid JS identifier, ignoring restrictions about keywords not being identifiers | ||
| */ | ||
| function isUnhyphenatedJsxName(name: string | __String) { | ||
| // - is the only character supported in JSX attribute names that isn't valid in JavaScript identifiers | ||
| // - is one of only two characters supported in JSX attribute names that isn't valid in JavaScript identifiers, : being the other |
There was a problem hiding this comment.
From my quick glance at this function’s usage, it seemed to me like the note about identifier validity isn’t actually relevant. On second thought, I would probably just remove these comments since they’re subtly misleading about the purpose of the function. The name and one-line implementation of the function are sufficiently self-explanatory.
Andrew Branch (andrewbranch)
commented
Nov 23, 2020
狒狒神 (@SoloJiang) it is / will be in 4.2. |

I got tired of the VSCode TypeScript checker complaining about JSX that React, Babel, and the JSX spec consider perfectly fine, so I thought I'd check to see this feature has been requested in the past and make a PR if so. Looked to be two issues requesting the support. I haven't contributed to TypeScript before, so I've probably done this all wrong, but I'm willing to put some more of my personal time into this to get it right. Thanks for your time.
Checks
Backlogmilestone (required)No, but here's a quote saying there's a chance that a PR could be taken (Ryan Cavanaugh (@RyanCavanaugh) on March 7, 2016):
masterbranchgulp runtestslocallyFixes#11833, #7411
Commit message: