Commits
Click on a commit to change the comparison rangefix(minifier): keep classes with static properties + side effect initializer (#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.