-
-
Notifications
You must be signed in to change notification settings - Fork 722
fix(minifier): keep classes with static properties + side effect initializer #12848
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(minifier): keep classes with static properties + side effect initializer #12848
Conversation
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
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
changes: * oxc-project/oxc#12848 * oxc-project/oxc#12829 closes #5591
changes: * oxc-project/oxc#12848 * oxc-project/oxc#12829 closes #5591
changes: * oxc-project/oxc#12848 * oxc-project/oxc#12829 closes #5591
changes: * oxc-project/oxc#12848 * oxc-project/oxc#12829 closes #5591
changes: * oxc-project/oxc#12848 * oxc-project/oxc#12829 closes #5591
…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.

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.