@@ -85,36 +85,39 @@ export async function transformWithOxc(
85
85
const loadedCompilerOptions = loadedTsconfig . compilerOptions ?? { }
86
86
// tsc compiler experimentalDecorators/target/useDefineForClassFields
87
87
88
- resolvedOptions . jsx ??= { }
89
- if ( loadedCompilerOptions . jsxFactory ) {
90
- resolvedOptions . jsx . pragma = loadedCompilerOptions . jsxFactory
91
- }
92
- if ( loadedCompilerOptions . jsxFragmentFactory ) {
93
- resolvedOptions . jsx . pragmaFrag =
94
- loadedCompilerOptions . jsxFragmentFactory
95
- }
96
- if ( loadedCompilerOptions . jsxImportSource ) {
97
- resolvedOptions . jsx . importSource = loadedCompilerOptions . jsxImportSource
98
- }
88
+ if ( loadedCompilerOptions . jsx === 'preserve' ) {
89
+ resolvedOptions . jsx = 'preserve'
90
+ } else {
91
+ const jsxOptions = {
92
+ ...( resolvedOptions . jsx === 'preserve' ? { } : resolvedOptions . jsx ) ,
93
+ }
99
94
100
- switch ( loadedCompilerOptions . jsx ) {
101
- case 'react-jsxdev' :
102
- resolvedOptions . jsx . runtime = 'automatic'
103
- resolvedOptions . jsx . development = true
104
- break
105
- case 'react' :
106
- resolvedOptions . jsx . runtime = 'classic'
107
- break
108
- case 'react-jsx' :
109
- resolvedOptions . jsx . runtime = 'automatic'
110
- break
111
- case 'preserve' :
112
- if ( lang === 'tsx' ) {
113
- ctx ?. warn ( 'The tsconfig jsx preserve is not supported by oxc' )
114
- }
115
- break
116
- default :
117
- break
95
+ if ( loadedCompilerOptions . jsxFactory ) {
96
+ jsxOptions . pragma = loadedCompilerOptions . jsxFactory
97
+ }
98
+ if ( loadedCompilerOptions . jsxFragmentFactory ) {
99
+ jsxOptions . pragmaFrag = loadedCompilerOptions . jsxFragmentFactory
100
+ }
101
+ if ( loadedCompilerOptions . jsxImportSource ) {
102
+ jsxOptions . importSource = loadedCompilerOptions . jsxImportSource
103
+ }
104
+
105
+ switch ( loadedCompilerOptions . jsx ) {
106
+ case 'react-jsxdev' :
107
+ jsxOptions . runtime = 'automatic'
108
+ jsxOptions . development = true
109
+ break
110
+ case 'react' :
111
+ jsxOptions . runtime = 'classic'
112
+ break
113
+ case 'react-jsx' :
114
+ jsxOptions . runtime = 'automatic'
115
+ break
116
+ default :
117
+ break
118
+ }
119
+
120
+ resolvedOptions . jsx = jsxOptions
118
121
}
119
122
120
123
/**
@@ -239,12 +242,14 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
239
242
} ,
240
243
async transform ( code , id ) {
241
244
if ( filter ( id ) || filter ( cleanUrl ( id ) ) ) {
245
+ const oxcTransformJsxOptions = oxcTransformOptions . jsx
242
246
// disable refresh at ssr
243
247
if (
244
248
this . environment . config . consumer === 'server' &&
245
- oxcTransformOptions . jsx ?. refresh
249
+ typeof oxcTransformJsxOptions === 'object' &&
250
+ oxcTransformJsxOptions . refresh
246
251
) {
247
- oxcTransformOptions . jsx . refresh = false
252
+ oxcTransformJsxOptions . refresh = false
248
253
}
249
254
if (
250
255
( jsxFilter ( id ) || jsxFilter ( cleanUrl ( id ) ) ) &&
@@ -445,6 +450,8 @@ async function generateRuntimeHelpers(
445
450
return output . output [ 0 ] . code
446
451
}
447
452
453
+ type OxcJsxOptions = Exclude < OxcOptions [ 'jsx' ] , string | undefined >
454
+
448
455
export function convertEsbuildConfigToOxcConfig (
449
456
esbuildConfig : ESBuildOptions ,
450
457
logger : Logger ,
@@ -456,38 +463,40 @@ export function convertEsbuildConfigToOxcConfig(
456
463
jsxInject,
457
464
include,
458
465
exclude,
459
- jsx : { } ,
460
466
}
461
467
462
- switch ( esbuildTransformOptions . jsx ) {
463
- case 'automatic' :
464
- oxcOptions . jsx ! . runtime = 'automatic'
465
- break
466
-
467
- case 'transform' :
468
- oxcOptions . jsx ! . runtime = 'classic'
469
- break
468
+ if ( esbuildTransformOptions . jsx === 'preserve' ) {
469
+ oxcOptions . jsx = 'preserve'
470
+ } else {
471
+ const jsxOptions : OxcJsxOptions = { }
472
+
473
+ switch ( esbuildTransformOptions . jsx ) {
474
+ case 'automatic' :
475
+ jsxOptions . runtime = 'automatic'
476
+ break
477
+ case 'transform' :
478
+ jsxOptions . runtime = 'classic'
479
+ break
480
+ default :
481
+ break
482
+ }
470
483
471
- case 'preserve' :
472
- logger . warn ( 'The esbuild jsx preserve is not supported by oxc' )
473
- break
484
+ if ( esbuildTransformOptions . jsxDev ) {
485
+ jsxOptions . development = true
486
+ }
487
+ if ( esbuildTransformOptions . jsxFactory ) {
488
+ jsxOptions . pragma = esbuildTransformOptions . jsxFactory
489
+ }
490
+ if ( esbuildTransformOptions . jsxFragment ) {
491
+ jsxOptions . pragmaFrag = esbuildTransformOptions . jsxFragment
492
+ }
493
+ if ( esbuildTransformOptions . jsxImportSource ) {
494
+ jsxOptions . importSource = esbuildTransformOptions . jsxImportSource
495
+ }
474
496
475
- default :
476
- break
497
+ oxcOptions . jsx = jsxOptions
477
498
}
478
499
479
- if ( esbuildTransformOptions . jsxDev ) {
480
- oxcOptions . jsx ! . development = true
481
- }
482
- if ( esbuildTransformOptions . jsxFactory ) {
483
- oxcOptions . jsx ! . pragma = esbuildTransformOptions . jsxFactory
484
- }
485
- if ( esbuildTransformOptions . jsxFragment ) {
486
- oxcOptions . jsx ! . pragmaFrag = esbuildTransformOptions . jsxFragment
487
- }
488
- if ( esbuildTransformOptions . jsxImportSource ) {
489
- oxcOptions . jsx ! . importSource = esbuildTransformOptions . jsxImportSource
490
- }
491
500
if ( esbuildTransformOptions . loader ) {
492
501
if ( [ 'js' , 'jsx' , 'ts' , 'tsx' ] . includes ( esbuildTransformOptions . loader ) ) {
493
502
oxcOptions . lang = esbuildTransformOptions . loader as
0 commit comments