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
Do not tear apart declarations in loop or if bodies #3947
Do not tear apart declarations in loop or if bodies #3947
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via
or load it into the REPL: |
Codecov Report
@@ Coverage Diff @@
## master #3947 +/- ##
==========================================
- Coverage 97.18% 97.18% -0.01%
==========================================
Files 188 188
Lines 6681 6678 -3
Branches 1946 1948 +2
==========================================
- Hits 6493 6490 -3
Misses 99 99
Partials 89 89
Continue to review full report at Codecov.
|
d447972
to
6911a37
Compare
@@ -49,11 +49,11 @@ export default class ForInStatement extends StatementBase { | |||
|
|||
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren) { | |||
this.included = true; | |||
this.left.includeAllDeclaredVariables(context, includeChildrenRecursively); | |||
this.left.include(context, includeChildrenRecursively || true); |
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.
How is it different from this.left.include(context, true);
?
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.
There is a special string value for includeChildrenRecursively
that is like true
but also includes "related" code. Something we use to deoptimize try-catch statements.
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 PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
As it turns out, partially tree-shaking a declaration while keeping side-effects, i.e.
will wreak havoc if the declaration is the body of a loop or if statement, e.g.
as it will replace the conditional side-effect with an unconditional one. Similar things apply to loops. The solution is to always include the identifier together with the initialiser in such a situation.