Skip to content

Conversation

@CPunisher
Copy link
Member

@CPunisher CPunisher commented Aug 13, 2025

Description:

Manual reasoning:

Um...There are some options to handle this problem:

  1. Prefer size. Check if there's any this in the statement with side effect. This could be inefficient and I'm not sure whether there's any other corner case.
  2. Prefer performance. Just like what oxc does, keep entire class declarations if some static property contains side effect initializer.

Since it's anti-pattern code, I'm not sure above options are worthy just for this case...Maybe a better one is emitting warnings for all those anti-pattern code. However, swc minifier doesn't diagnostic system for minifier, and I don't know how many code in swc minifier is used for handling such cases (so it could be redundant to introduce it now).

After some consideration I finally decide to directly add contains_this_expr check for it.

Related issue (if exists):
fixes #10981

@CPunisher CPunisher requested a review from a team as a code owner August 13, 2025 10:03
@changeset-bot
Copy link

changeset-bot bot commented Aug 13, 2025

⚠️ No Changeset found

Latest commit: 2b40f51

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 13, 2025

CodSpeed Performance Report

Merging #11003 will not alter performance

Comparing CPunisher:08-13-fix/static-prop-with-this (2b40f51) with main (cda08d1)

Summary

✅ 140 untouched benchmarks

@CPunisher CPunisher changed the title fix(es/minifier): don't elimiate class expr if some side effects contain this fix(es/minifier): don't eliminate class expr if some side effects contain this Aug 13, 2025
@kdy1 kdy1 added this to the Planned milestone Aug 13, 2025
@kdy1 kdy1 merged commit 18aeac6 into swc-project:main Aug 13, 2025
468 of 475 checks passed
@kdy1 kdy1 modified the milestones: Planned, 1.13.4 Aug 21, 2025
@swc-project swc-project locked as resolved and limited conversation to collaborators Sep 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

es/minifier: incorrect class expression + static property + side effect initializer

2 participants