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
Lazily inject imports to the JSX runtime #12493
Lazily inject imports to the JSX runtime #12493
Conversation
const foo = /*#__PURE__*/undefined.jsx("p", {}); | ||
var _reactJsxRuntime = require("react/jsx-runtime"); | ||
|
||
const foo = /*#__PURE__*/_reactJsxRuntime.jsx("p", {}); |
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.
This fixture shows that it's fixed.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/35275/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit e9daba1:
|
let reference = pass.get( | ||
`@babel/plugin-react-jsx/imports/${importName}`, | ||
); |
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'm just wondering - does keeping this in a state has any benefit here? i mean - wouldn't a closure state do the trick just fine? I don't expect any change here - just wondering if there is something I'm not thinking about
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.
The plugin might be cached, so multiple runs of the plugin over the same file could have the same closure. Thus, we would still need to have a programNode -> imports
WeakMap
to avoid using imports attatched in a separate Babel run.
9ad420a
to
e9daba1
Compare
@nicolo-ribaudo Did this PR also fix #12468 (comment) ? |
I don't think, there isn't a call to |
Injecting automatic imports to react on
Program:enter
has a problem: if a plugin later injects some JSX, the automatic imports logic cannot inject the necessary import.This PR changes the injection to happen when transforming the JSX element, so that it works with injected JSX.