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
Add simple way to manually declare pure functions #4718
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#manual-pure-functions or load it into the REPL: |
Codecov Report
@@ Coverage Diff @@
## master #4718 +/- ##
=======================================
Coverage 99.03% 99.03%
=======================================
Files 216 217 +1
Lines 7664 7690 +26
Branches 2116 2126 +10
=======================================
+ Hits 7590 7616 +26
Misses 24 24
Partials 50 50
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
This PR has been released as part of rollup@3.4.0-0. Note that this is a pre-release, so to test it, you need to install Rollup via |
cbe714a
to
0048150
Compare
This PR has been released as part of rollup@3.4.0-1. Note that this is a pre-release, so to test it, you need to install Rollup via |
28eb501
to
cc53d89
Compare
This PR has been released as part of rollup@3.5.0. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
supports #4327
Description
For features like chunk merging by minimal chunk size, it is very important to properly detect side effect free code as otherwise, chunks will not be merged that could otherwise be merged.
Sometimes, however, there are limits to what Rollup can detect, and by default, Rollup is always conservative about its assumptions. As a quick fix, this feature allows to mark function calls as pure solely by name matching:
treeshake.manualPureFunctions
Type:
string[]
CLI:
--treeshake.manualPureFunctions <names>
Allows to manually define a list of function names that should always be considered "pure", i.e. they have no side effects like changing global state etc. when called. The check is performed solely by name.
This can not only help with dead code removal, but can also improve JavaScript chunk generation especially when using
experimentalMinChunkSize
.Besides any functions matching that name, any properties on a pure function and any functions returned from a pure functions will also be considered pure.