-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Rework treeshaking algorithm #1582
Rework treeshaking algorithm #1582
Conversation
Changes without whitespace adjustments: |
@lukastaegert Nice work! This PR fixes at least a couple of open issue (above). |
@Rich-Harris Thanks for the kind words 😃. So I hope you merge that one soon so I no longer have to bear the shame of having broken Rollup 😧 |
we've all been there 😉 thanks for the speedy fixes — no harm, no foul |
This is a huge refactoring of several core aspects of rollups tree-shaking algorithm. Before going into implementation details, I will present you some things this pull request fixes or improves by showing you the output of the new/modified tests against the previous implementation (for the actual tests, please look at the code).
New test results
effect-in-for-loop
output with old implementation
output with new implementation
As you can see, this code was completely ignored by the old implementation because the declaration of e was searched for in the scope before it had been added to the scope. This is now handled properly.
nested-tree-shaking
output with old implementation
output with new implementation
side-effects-call-arguments
output with old implementation
output with new implementation
side-effects-delete
output with old implementation
output with new implementation
side-effects-pattern-assignment
output with old implementation
output with new implementation
side-effects-pattern-defaults
output with old implementation
output with new implementation
This is fixed now.
side-effects-reassignment
output with old implementation
output with new implementation
Algorithmic/architecture changes
The main goal was to get rid of custom logic such as isUsedByBundle or assignToForLoopLeft that is hard to maintain and move logic to the individual nodes.
.included
Bundle
Module
Module.includeInBundle() includes each node that .shouldBeIncluded(), see below
Node
By default, Node inclusion works like this:
There are other new methods:
Assignments and Mutations
And more that I can no longer remember :)
I hope you like it, feedback always welcome.