Skip to content

Commit

Permalink
fix: oxc esbuild jsx option compat
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jan 17, 2025
1 parent b120a59 commit 186ab4c
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions packages/vite/src/node/plugins/oxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,19 @@ export async function transformWithOxc(
}

switch (loadedCompilerOptions.jsx) {
case 'react-jsxdev':
jsxOptions.runtime = 'automatic'
jsxOptions.development = true
break
case 'react':
jsxOptions.runtime = 'classic'
// this option should not be set when using classic runtime
jsxOptions.importSource = undefined
break
case 'react-jsxdev':
jsxOptions.development = true
// eslint-disable-next-line no-fallthrough
case 'react-jsx':
jsxOptions.runtime = 'automatic'
// these options should not be set when using automatic runtime
jsxOptions.pragma = undefined
jsxOptions.pragmaFrag = undefined
break
default:
break
Expand Down Expand Up @@ -563,9 +567,18 @@ export function convertEsbuildConfigToOxcConfig(
switch (esbuildTransformOptions.jsx) {
case 'automatic':
jsxOptions.runtime = 'automatic'
if (esbuildTransformOptions.jsxImportSource) {
jsxOptions.importSource = esbuildTransformOptions.jsxImportSource
}
break
case 'transform':
jsxOptions.runtime = 'classic'
if (esbuildTransformOptions.jsxFactory) {
jsxOptions.pragma = esbuildTransformOptions.jsxFactory
}
if (esbuildTransformOptions.jsxFragment) {
jsxOptions.pragmaFrag = esbuildTransformOptions.jsxFragment
}
break
default:
break
Expand All @@ -574,15 +587,6 @@ export function convertEsbuildConfigToOxcConfig(
if (esbuildTransformOptions.jsxDev) {
jsxOptions.development = true
}
if (esbuildTransformOptions.jsxFactory) {
jsxOptions.pragma = esbuildTransformOptions.jsxFactory
}
if (esbuildTransformOptions.jsxFragment) {
jsxOptions.pragmaFrag = esbuildTransformOptions.jsxFragment
}
if (esbuildTransformOptions.jsxImportSource) {
jsxOptions.importSource = esbuildTransformOptions.jsxImportSource
}

oxcOptions.jsx = jsxOptions
}
Expand Down

0 comments on commit 186ab4c

Please sign in to comment.