fix(minifier): keep classes with static properties + side effect initializer#12848
Merged
graphite-app[bot] merged 1 commit intomainfrom Aug 6, 2025
Conversation
Member
Author
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #12848 will not alter performanceComparing Summary
|
116d581 to
e3022ab
Compare
Contributor
Merge activity
|
…ializer (#12848) For the record, here's the whole process: [TypeScript ES2022 + useDefineForClassFields = false](https://www.typescriptlang.org/play/?useDefineForClassFields=true&noUnusedLocals=true&noUnusedParameters=true&experimentalDecorators=true&emitDecoratorMetadata=true&target=9&jsx=0&module=0&stripInternal=false&isolatedModules=false&verbatimModuleSyntax=false&allowSyntheticDefaultImports=true&isolatedDeclarations=false&noCheck=false&lib=true&ts=5.9.2&filetype=ts#code/MYGwhgzhAEDC0G8BQ1oQC5nQS2NAZtALyIC+A3EqUA) transforms (Note Oxc has the exact same transform) ```js class C { static f = side_effect(); } ``` into ```js class C { static { this.f = side_effect(); } } ``` then babel [@babel/plugin-transform-class-static-block](https://babel.dev/repl#?corejs=3.21&spec=true&code_lz=MYGwhgzhAEDC0G8BQ1XQgFzBglsR0GAFjhAHQBm0AvIgL4Dc0dSdQA&forceAllTransforms=true&modules=commonjs&timeTravel=true&sourceType=module&lineWrap=true&presets=react%2Ctypescript&version=7.26.1&externalPlugins=%40babel%2Fplugin-transform-class-static-block%407.27.1) transforms to (Note Oxc has the exact same transform) ```js class C { static #_ = this.f = side_effect(); } ``` and the minifier remove unused code trims it down to ```js this.f = side_effect(); ``` --- To eliminate this bug, we will temporary keep all classes that have static properties + side effect initializer. i.e. ```js class C { static #_ = this.f = side_effect(); } ``` does not get trimmed down to `this.f = side_effect()`. --- Also note, this came from a project with a tsconfig ```js "useDefineForClassFields": false ``` + browserslist target `ios 16` where ES2022 `@babel/plugin-transform-class-properties` is off and ES2022 `@babel/plugin-transform-class-static-block` on.
e3022ab to
44b37f7
Compare
Boshen
added a commit
to rolldown/rolldown
that referenced
this pull request
Aug 6, 2025
changes: * oxc-project/oxc#12848 * oxc-project/oxc#12829 closes #5591
Boshen
added a commit
to rolldown/rolldown
that referenced
this pull request
Aug 7, 2025
changes: * oxc-project/oxc#12848 * oxc-project/oxc#12829 closes #5591
github-merge-queue bot
pushed a commit
to rolldown/rolldown
that referenced
this pull request
Aug 7, 2025
changes: * oxc-project/oxc#12848 * oxc-project/oxc#12829 closes #5591
github-merge-queue bot
pushed a commit
to rolldown/rolldown
that referenced
this pull request
Aug 7, 2025
changes: * oxc-project/oxc#12848 * oxc-project/oxc#12829 closes #5591
github-merge-queue bot
pushed a commit
to rolldown/rolldown
that referenced
this pull request
Aug 7, 2025
changes: * oxc-project/oxc#12848 * oxc-project/oxc#12829 closes #5591
taearls
pushed a commit
to taearls/oxc
that referenced
this pull request
Aug 12, 2025
…ializer (oxc-project#12848) For the record, here's the whole process: [TypeScript ES2022 + useDefineForClassFields = false](https://www.typescriptlang.org/play/?useDefineForClassFields=true&noUnusedLocals=true&noUnusedParameters=true&experimentalDecorators=true&emitDecoratorMetadata=true&target=9&jsx=0&module=0&stripInternal=false&isolatedModules=false&verbatimModuleSyntax=false&allowSyntheticDefaultImports=true&isolatedDeclarations=false&noCheck=false&lib=true&ts=5.9.2&filetype=ts#code/MYGwhgzhAEDC0G8BQ1oQC5nQS2NAZtALyIC+A3EqUA) transforms (Note Oxc has the exact same transform) ```js class C { static f = side_effect(); } ``` into ```js class C { static { this.f = side_effect(); } } ``` then babel [@babel/plugin-transform-class-static-block](https://babel.dev/repl#?corejs=3.21&spec=true&code_lz=MYGwhgzhAEDC0G8BQ1XQgFzBglsR0GAFjhAHQBm0AvIgL4Dc0dSdQA&forceAllTransforms=true&modules=commonjs&timeTravel=true&sourceType=module&lineWrap=true&presets=react%2Ctypescript&version=7.26.1&externalPlugins=%40babel%2Fplugin-transform-class-static-block%407.27.1) transforms to (Note Oxc has the exact same transform) ```js class C { static #_ = this.f = side_effect(); } ``` and the minifier remove unused code trims it down to ```js this.f = side_effect(); ``` --- To eliminate this bug, we will temporary keep all classes that have static properties + side effect initializer. i.e. ```js class C { static #_ = this.f = side_effect(); } ``` does not get trimmed down to `this.f = side_effect()`. --- Also note, this came from a project with a tsconfig ```js "useDefineForClassFields": false ``` + browserslist target `ios 16` where ES2022 `@babel/plugin-transform-class-properties` is off and ES2022 `@babel/plugin-transform-class-static-block` on.
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.

For the record, here's the whole process:
TypeScript ES2022 + useDefineForClassFields = false transforms
(Note Oxc has the exact same transform)
into
then babel @babel/plugin-transform-class-static-block transforms to
(Note Oxc has the exact same transform)
and the minifier remove unused code trims it down to
To eliminate this bug, we will temporary keep all classes that have static properties + side effect initializer.
i.e.
does not get trimmed down to
this.f = side_effect().Also note, this came from a project with a tsconfig
ios 16where ES2022@babel/plugin-transform-class-propertiesis off and ES2022@babel/plugin-transform-class-static-blockon.