Repository navigation
fix(es/minifier): Keep function and class declarations whose self-reference is dropped - #12401
Merged
Donny/강동윤 (kdy1) merged 1 commit intoSep 23, 2026
Conversation
Baltasar Blanco (baltasarblanco)
requested review from
a team
as code owners
September 22, 2026 15:24
🦋 Changeset detectedLatest commit: 3644472 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 |
…erence is dropped
Baltasar Blanco (baltasarblanco)
force-pushed
the
fix/12400-dce-self-ref-usage
branch
from
September 23, 2026 02:02
190ff47 to
3644472
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
The tree shaker's
Analyzerdeliberately does not count a function's or class's references to itself (VarInfodocs: "This does not include self-references in a function"). TheDropper, which subtracts usages when a node is removed, had no such exclusion. So when an unused local initialized with the enclosing function's name was dropped, the function lost a usage it never gained, hit zero, and was dropped on the next pass while still referenced from outside:This makes the
Droppertrack the innermost enclosing named function/class the same way theAnalyzerdoes, and skip self-references when subtracting. The same mechanism applied to class declarations, so both are covered.Tests:
Two exec tests in
tests/exec.rs(function declaration and class declaration variants). Both fail onmainwithReferenceErrorand pass with this change../scripts/exec.shand the fullswc_ecma_transforms_optimizationandswc_ecma_minifiersuites pass with no fixture output changes.Related issue (if exists):
Closes #12400