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

parser: JSXMemberExpression where property contains hyphens #5355

Closed
overlookmotel opened this issue Aug 30, 2024 · 5 comments · Fixed by #5440
Closed

parser: JSXMemberExpression where property contains hyphens #5355

overlookmotel opened this issue Aug 30, 2024 · 5 comments · Fixed by #5440
Assignees
Labels
A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Comments

@overlookmotel
Copy link
Contributor

overlookmotel commented Aug 30, 2024

According to JSX spec, this is legal syntax: <Foo.bar-qux> (because bar-qux is a valid JSXIdentifier).

Currently Oxc transforms this to _jsx(Foo.bar-qux, {}):

https://oxc-project.github.io/oxc/playground/?code=3YCAAICRgICAgICAgICekQl4rrIkZg9c51vDD8rqZZS485A%2Ff3EUAIA%3D

We should transform it to _jsx(Foo["bar-qux"], {}) instead.

NB: Babel just errors out on this input, and SWC gets it wrong the same way we do, so this is not a high priority. But it's probably easier to do it now while we're already making loads of changes to how we handle JSX.

@overlookmotel overlookmotel added C-bug Category - Bug A-transformer Area - Transformer / Transpiler labels Aug 30, 2024
@Boshen
Copy link
Member

Boshen commented Aug 31, 2024

TODO: React transform should throw the same babel error.

@Boshen Boshen self-assigned this Aug 31, 2024
@overlookmotel
Copy link
Contributor Author

Babel throws that error in parser. Babel REPL

I don't think Babel's behavior is correct because (as you pointed out yesterday) it's valid JSX. But it's undefined whether it's valid or not as React JSX.

So yes, we could raise an error in React transform, or we could accept it and transform it to _jsx(Foo["bar-qux"], {}).

@Boshen
Copy link
Member

Boshen commented Sep 4, 2024

As it turns out, this is an undocumented syntax error, confirmed by babel, tsc and babel.

Boshen added a commit that referenced this issue Sep 4, 2024
@Boshen Boshen changed the title Correctly transform JSXMemberExpression where property contains hyphens parser: JSXMemberExpression where property contains hyphens Sep 4, 2024
@Boshen
Copy link
Member

Boshen commented Sep 4, 2024

This is now a syntax error in oxc:

  × Unexpected token
   ╭─[misc/fail/oxc-5355.jsx:1:6]
 1 │ <Foo.bar-baz />
   ·      ───────
   ╰────

Boshen added a commit that referenced this issue Sep 4, 2024
@Boshen Boshen closed this as completed Sep 4, 2024
@overlookmotel
Copy link
Contributor Author

Brilliant! Thanks for solving it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transformer Area - Transformer / Transpiler C-bug Category - Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants