transform-react-jsx with `runtime: automatic` should always using `jsx-runtime`
See original GitHub issueBug Report
“@babel/plugin-transform-react-jsx” ^7.10.4
[ "@babel/plugin-transform-react-jsx", { "runtime": "automatic" }]
Current behavior fallbacked classic runtime when jsx use spread with key exists
_createElement("span", {...obj, key: "key"})
Input Code
<span {...obj} key={"key"} />
Expected behavior
_jsx("span", obj, "key")
Environment
- Babel version(s): 7.12.0
- Node/npm version: 14.12.0
- OS: [e.g. OSX 10.13.4, Windows 10]
- Monorepo: yes
- How you are using Babel:
cli
,register
,loader
Possible Solution
may transform codes like
<span key={key} {...obj} />
=> jsx("span", obj, key)
<span {...obj} key={key} />
=> jsx("span", {...obj, key}, key)
it will be friendly for custom jsx-runtime
and some react-like lib
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Introducing the New JSX Transform – React Blog
With the new transform, you can use JSX without importing React. ... JSX transform will automatically import the necessary react/jsx-runtime ...
Read more >babel/preset-react
Decides which runtime to use. automatic auto imports the functions that JSX transpiles to. classic does not automatic import anything. development.
Read more >New jsx compiler? - help - Meteor forums
Does anyone know how to use the new JSX compiler in Meteor? I actually don't know where the transform is specified in my...
Read more >a-jsx-runtime - npm Package Health Analysis - Snyk
[ "@babel/plugin-transform-react-jsx", { "runtime": "automatic", // add the `import` etc automatically. "importSource": "a-jsx-runtime", // use ...
Read more >You don't need React to use JSX. In this ... - Arnaud Dostes
import {jsx as _jsx} from 'react/jsx-runtime'; ... From the blog post, we know we need to do two things: use the new automatic...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I got it by the comments.
https://github.com/babel/babel/blob/master/packages/babel-helper-builder-react-jsx-experimental/src/index.js#L270
But it will be confused for adding custom
jsx-runtime
like https://github.com/emotion-js/emotion/pull/1970have to expose as
clear enough https://github.com/facebook/react/issues/20031#issuecomment-710346866