diff --git a/packages/plugin-react/src/jsx-runtime/restore-jsx.ts b/packages/plugin-react/src/jsx-runtime/restore-jsx.ts index 268153f4ba5d45..f728ef32e7e4e7 100644 --- a/packages/plugin-react/src/jsx-runtime/restore-jsx.ts +++ b/packages/plugin-react/src/jsx-runtime/restore-jsx.ts @@ -24,17 +24,25 @@ export async function restoreJSX( return jsxNotFound } - const reactJsxRE = new RegExp( - '\\b' + reactAlias + '\\.(createElement|Fragment)\\b', + const reactJsxFragmentRE = new RegExp( + '\\b' + reactAlias + '\\.(Fragment)\\b', + 'g' + ) + const reactJsxCreatElementRE = new RegExp( + '\\b' + reactAlias + '\\.(createElement)\\b(\\([A-Z]\\w)', 'g' ) let hasCompiledJsx = false - code = code.replace(reactJsxRE, (_, prop) => { + code = code.replace(reactJsxFragmentRE, (_, prop) => { hasCompiledJsx = true // Replace with "React" so JSX can be reverse compiled. return 'React.' + prop }) + code = code.replace(reactJsxCreatElementRE, (_, prop, prop2) => { + hasCompiledJsx = true + return 'React.' + prop + prop2 + }) if (!hasCompiledJsx) { return jsxNotFound