Implement plugin-transform-react-pure-annotations and add to preset-react#11428
Merged
nicolo-ribaudo merged 2 commits intobabel:masterfrom May 24, 2020
Merged
Implement plugin-transform-react-pure-annotations and add to preset-react#11428nicolo-ribaudo merged 2 commits intobabel:masterfrom
plugin-transform-react-pure-annotations and add to preset-react#11428nicolo-ribaudo merged 2 commits intobabel:masterfrom
Conversation
Member
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
Awesome!
I would like the plugin to be named @babel/plugin-transform-react-pure-annotations, since I find it more descriptive of what it does.
Apart from that, the code looks good 👍
Member
|
The CI failure doesn't seem related to this PR, but it doesn't fail on master and it fails on every node version 🤔 |
Member
|
Ok, I restarted travis on master and it failed. |
Contributor
Author
|
Updated the plugin name. I'm not sure what's up with the tests. They do pass locally... |
6a17bde to
6d80d8d
Compare
plugin-transform-react-pure-annotations and add to preset-react
2 tasks
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This implements
@babel/plugin-transform-react-pureas described in #11399, and adds it by default to@babel/preset-react. This plugin adds/*#__PURE__*/annotations before many top-level React function calls, which allows them to be tree shaken/dead code eliminated by terser and other minifiers.For example, libraries making use of
React.forwardReforReact.memocould be tree shaken if unused. For apps using large libraries of components that use these APIs, this could make a big difference to overall bundle size.This is built into
@babel/preset-reactby default for maximum impact across the ecosystem. However, it can be disabled by setting the{"pure": false}option to the preset, which also already disables pure annotations on compiled JSX.