Skip to content

Commit 186ab4c

Browse files
committed
fix: oxc esbuild jsx option compat
1 parent b120a59 commit 186ab4c

File tree

1 file changed

+17
-13
lines changed
  • packages/vite/src/node/plugins

1 file changed

+17
-13
lines changed

packages/vite/src/node/plugins/oxc.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,19 @@ export async function transformWithOxc(
107107
}
108108

109109
switch (loadedCompilerOptions.jsx) {
110-
case 'react-jsxdev':
111-
jsxOptions.runtime = 'automatic'
112-
jsxOptions.development = true
113-
break
114110
case 'react':
115111
jsxOptions.runtime = 'classic'
112+
// this option should not be set when using classic runtime
113+
jsxOptions.importSource = undefined
116114
break
115+
case 'react-jsxdev':
116+
jsxOptions.development = true
117+
// eslint-disable-next-line no-fallthrough
117118
case 'react-jsx':
118119
jsxOptions.runtime = 'automatic'
120+
// these options should not be set when using automatic runtime
121+
jsxOptions.pragma = undefined
122+
jsxOptions.pragmaFrag = undefined
119123
break
120124
default:
121125
break
@@ -563,9 +567,18 @@ export function convertEsbuildConfigToOxcConfig(
563567
switch (esbuildTransformOptions.jsx) {
564568
case 'automatic':
565569
jsxOptions.runtime = 'automatic'
570+
if (esbuildTransformOptions.jsxImportSource) {
571+
jsxOptions.importSource = esbuildTransformOptions.jsxImportSource
572+
}
566573
break
567574
case 'transform':
568575
jsxOptions.runtime = 'classic'
576+
if (esbuildTransformOptions.jsxFactory) {
577+
jsxOptions.pragma = esbuildTransformOptions.jsxFactory
578+
}
579+
if (esbuildTransformOptions.jsxFragment) {
580+
jsxOptions.pragmaFrag = esbuildTransformOptions.jsxFragment
581+
}
569582
break
570583
default:
571584
break
@@ -574,15 +587,6 @@ export function convertEsbuildConfigToOxcConfig(
574587
if (esbuildTransformOptions.jsxDev) {
575588
jsxOptions.development = true
576589
}
577-
if (esbuildTransformOptions.jsxFactory) {
578-
jsxOptions.pragma = esbuildTransformOptions.jsxFactory
579-
}
580-
if (esbuildTransformOptions.jsxFragment) {
581-
jsxOptions.pragmaFrag = esbuildTransformOptions.jsxFragment
582-
}
583-
if (esbuildTransformOptions.jsxImportSource) {
584-
jsxOptions.importSource = esbuildTransformOptions.jsxImportSource
585-
}
586590

587591
oxcOptions.jsx = jsxOptions
588592
}

0 commit comments

Comments
 (0)