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

Support JSX xml-namespaced attributes #841

Closed
thesoftwarephilosopher opened this issue Jul 31, 2024 · 4 comments
Closed

Support JSX xml-namespaced attributes #841

thesoftwarephilosopher opened this issue Jul 31, 2024 · 4 comments

Comments

@thesoftwarephilosopher
Copy link

Specifically, allow transforming:

  <urlset
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  >...</urlset>
@thesoftwarephilosopher
Copy link
Author

thesoftwarephilosopher commented Aug 8, 2024

Looking at the generated tokens,

<span foo:hi='bar'></span>

produces

Location  Label       Raw   contextualKeyword scopeDepth isType identifierRole jsxRole shadowsGlobal isAsyncOperation contextId rhsEndIndex isExpression numNullishCoalesceStarts numNullishCoalesceEnds isOptionalChainStart isOptionalChainEnd subscriptStartIndex nullishStartIndex
1:1-1:2   jsxTagStart <     0                 0                                0                                                                         0                        0                                                                                                   
1:2-1:6   jsxName     span  0                 0                                                                                                          0                        0                                                                                                   
1:7-1:10  jsxName     foo   0                 0                                                                                                          0                        0                                                                                                   
1:10-1:11 :           :     0                 0                                                                                                          0                        0                                                                                                   
1:11-1:13 name        hi    0                 0                                                                                                          0                        0                                                                                                   
1:13-1:14 =           =     0                 0                                                                                                          0                        0                                                                                                   
1:14-1:19 string      'bar' 0                 0                                                                                                          0                        0                                                                                                   
1:19-1:20 jsxTagEnd   >     0                 0                                                                                                          0                        0                                                                                                   
1:20-1:21 jsxTagStart <     0                 0                                                                                                          0                        0                                                                                                   
1:21-1:22 /           /     0                 0                                                                                                          0                        0                                                                                                   
1:22-1:26 jsxName     span  0                 0                                                                                                          0                        0                                                                                                   
1:26-1:27 jsxTagEnd   >     0                 0                                                                                                          0                        0                                                                                                   
2:1-2:1   eof               0                 0                                                                                                          0                        0                                                                                                   

So a quick fix would just be to run through tokens, and when you find jsxName followed by : and name, combine those two into the jsxName value, and remove those two tokens.

@thesoftwarephilosopher
Copy link
Author

So far, this needs JSXTransformer.ts to have this inserted at line 420:

      } else if (this.tokens.matches4(tt.jsxName, tt.colon, tt.name, tt.eq)) {

Still not sure what to put in there though. I tried adding the two strings, and the linter said string concatenation is bad, so...

@thesoftwarephilosopher
Copy link
Author

Actually the tokenizer would probably be a better place.

@thesoftwarephilosopher
Copy link
Author

Never mind, switched to @swc/core and the issue is fixed with equivalent runtime performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant