-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(es/minifier): Prevent removing side effects from accessing getter #9530
Conversation
🦋 Changeset detectedLatest commit: 78cb61a The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
CodSpeed Performance ReportMerging #9530 will degrade performances by 3.52%Comparing Summary
Benchmarks breakdown
|
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.
Better to add tests at issues/9500, otherwise good.
Closes #9500
Caused by
swc/crates/swc_ecma_minifier/src/compress/pure/misc.rs
Line 1547 in c7fdd6b
self.ignore_return_value
,swc/crates/swc_ecma_minifier/src/compress/pure/misc.rs
Line 966 in c7fdd6b
converts the object to
0
because the object is side-effect-free according toswc/crates/swc_ecma_utils/src/lib.rs
Line 1496 in c7fdd6b
We should skip this process to fix the issue.
As is known only accessing getters and setters may cause side effect, we can safely do the transformation when none of them appears in the object. More precision is possible if comparing the lit prop names. I also collect computed keys of getters and setters in the object, is there any bad case?
The reason why only numeric (string) key removes the statement is that string key (
Computed
) is converted toIdent
in other phases, e.g.{}['a']
=>{}.a
, which does not matching the pattern.