File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -383,6 +383,21 @@ describe('transformWithEsbuild', () => {
383
383
const actual = await transformClassCode ( 'es2022' , { } )
384
384
expect ( actual ) . toBe ( defineForClassFieldsFalseTransformedCode )
385
385
} )
386
+
387
+ test ( 'useDefineForClassFields: false and static property should not be transpile to static block' , async ( ) => {
388
+ const result = await transformWithEsbuild (
389
+ `
390
+ class foo {
391
+ static bar = 'bar'
392
+ }
393
+ ` ,
394
+ 'bar.ts' ,
395
+ {
396
+ target : 'esnext' ,
397
+ } ,
398
+ )
399
+ expect ( result ?. code ) . not . toContain ( 'static {' )
400
+ } )
386
401
} )
387
402
} )
388
403
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ export async function transformWithEsbuild(
96
96
}
97
97
98
98
let tsconfigRaw = options ?. tsconfigRaw
99
+ const fallbackSupported : Record < string , boolean > = { }
99
100
100
101
// if options provide tsconfigRaw in string, it takes highest precedence
101
102
if ( typeof tsconfigRaw !== 'string' ) {
@@ -150,6 +151,15 @@ export async function transformWithEsbuild(
150
151
compilerOptions . experimentalDecorators = true
151
152
}
152
153
154
+ // Compat with esbuild 0.17 where static properties are transpiled to
155
+ // static blocks when `useDefineForClassFields` is false. Its support
156
+ // is not great yet, so temporarily disable it for now.
157
+ // TODO: Remove this in Vite 5, don't pass hardcoded `esnext` target
158
+ // to `transformWithEsbuild` in the esbuild plugin.
159
+ if ( compilerOptions . useDefineForClassFields !== true ) {
160
+ fallbackSupported [ 'class-static-blocks' ] = false
161
+ }
162
+
153
163
// esbuild uses tsconfig fields when both the normal options and tsconfig was set
154
164
// but we want to prioritize the normal options
155
165
if ( options ) {
@@ -172,6 +182,10 @@ export async function transformWithEsbuild(
172
182
...options ,
173
183
loader,
174
184
tsconfigRaw,
185
+ supported : {
186
+ ...fallbackSupported ,
187
+ ...options ?. supported ,
188
+ } ,
175
189
}
176
190
177
191
// Some projects in the ecosystem are calling this function with an ESBuildOptions
You can’t perform that action at this time.
0 commit comments