You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Passing the pure option to @babel/plugin-transform-react-jsx in order to force pure annotation for custom JSX factory (like @emotion/react).
By default, Babel disable pure annotations if the jsx importSource is not react but we have the opportunity to force pure annotations by adding the pure option to the babel plugin like explained here: babel/babel#11126 (comment)
This is useful in library mode and it improve treeshaking.
If anything, we could resolve the jsxImportSource, find its package.json, and look for sideEffects field to see if the module has side effects. Not a perfect heuristic, but probably good enough. (eg: @emotion/react has sideEffects: false in its package.json)
Though I think I'm leaning toward jsxPure: true default, since JSX calls are supposed to be pure anyway
Thanks for your review! I added a commit for making jsxPure true by default.
About looking for the sideEffects field in package.json, I think it's not a good way to determine if a custom runtime is side effect free. For example, preact/jsx-runtime didn't have this field in the package.json file. https://github.com/preactjs/preact/blob/master/jsx-runtime/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p2-nice-to-haveNot breaking anything but nice to have (priority)
4 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Passing the
pureoption to@babel/plugin-transform-react-jsxin order to force pure annotation for custom JSX factory (like@emotion/react).By default, Babel disable pure annotations if the jsx
importSourceis notreactbut we have the opportunity to force pure annotations by adding thepureoption to the babel plugin like explained here:babel/babel#11126 (comment)
This is useful in library mode and it improve treeshaking.
For example:
produce the following output:
But with:
it produce the following output:
Additional context
Pure annotation explanation
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).