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
Better try statement tree shaking #3166
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3166 +/- ##
==========================================
+ Coverage 90.12% 90.17% +0.05%
==========================================
Files 165 165
Lines 5873 5896 +23
Branches 1789 1794 +5
==========================================
+ Hits 5293 5317 +24
Misses 350 350
+ Partials 230 229 -1
Continue to review full report at Codecov.
|
actually has and add instructions to commit it.
416ce23
to
88d871f
Compare
src/ast/ExecutionContext.ts
Outdated
@@ -3,6 +3,7 @@ import { PathTracker } from './utils/PathTracker'; | |||
import ThisVariable from './variables/ThisVariable'; | |||
|
|||
interface ExecutionContextIgnore { | |||
breakAndContinue: boolean; | |||
breakStatements: boolean; |
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.
Assuming this isn't a public interface, rather than having the overlap of concerns between breakAndContinue
and breakStatements
, I'd suggest to simplify this and have distinct breakStatements
and continueStatements
. Yes, the meaning of the terms would change and would require some more refactoring, but there'd be less cognitive overload.
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.
I was considering this and expect this version to be slightly more performant than the alternative in real world scenarios (loops without breaks are more common than loops with breaks and that way, you only need to check both flags for break statements while otherwise, you need to set and reset both flags for each kind of loop, which also results in more code) but I guess you are right that the advantage is negligible.
e8e7fa1
to
36bc84f
Compare
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Resolves #3161
Resolves #3162
Resolves #3163
Resolves #3164
Description
This will no longer include a try-statement if the only side-effect can be found in the catch block. Also it will properly consider
treeshake.tryCatchDeoptimization
when checking for side-effects in the try block: If the optimization is off, the block is checked for side-effects, otherwise we check if it is non-empty.Furthermore, this improves the switch statement rendering logic to prevent trailing empty lines. Also, trailing side-effect-free switch cases will be tree-shaken UNLESS there is a default case that is not the last case. I.e.
Lastly,
continue
statements are now properly differentiated frombreak
statements inside switch statements to fix the issue mentioned here: #3164 (comment)