Skip to content

Commit db919e3

Browse files
orgadshannoeru
andauthored
fix: respect useDefineForClassFields=false setting (#156)
Co-authored-by: hanlee <[email protected]>
1 parent 20e6db2 commit db919e3

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ export default createUnplugin<Options | undefined, false>(
8484
jsc.target = compilerOptions.target
8585
}
8686

87+
if (compilerOptions.useDefineForClassFields != null) {
88+
jsc.transform.useDefineForClassFields = compilerOptions.useDefineForClassFields
89+
}
90+
8791
if (options.jsc) {
8892
jsc = defu<SWCOptions, SWCOptions[]>(options.jsc, jsc)
8993
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export class TestClass {
2+
inlineProperty = 'value';
3+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2020",
4+
"module": "esnext",
5+
"strict": true,
6+
"useDefineForClassFields": false
7+
}
8+
}

test/index.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,21 @@ it('minify', async () => {
9393
"
9494
`)
9595
})
96+
97+
it('useDefineForClassFields=false', async () => {
98+
const bundle = await rollup({
99+
input: fixture('class-fields/class-field.ts'),
100+
plugins: [
101+
swc.rollup(),
102+
],
103+
})
104+
105+
const { output } = await bundle.generate({
106+
format: 'esm',
107+
dir: fixture('class-fields/dist'),
108+
})
109+
110+
const code = output[0].code
111+
// Ensure inline property is moved to constructor
112+
expect(code).toContain('this.inlineProperty = \'value\'')
113+
})

0 commit comments

Comments
 (0)