Skip to content

Commit ce65c56

Browse files
authored
fix(plugin-react): restore-jsx bug when component name is lowercase (#6110)
1 parent 5f39c28 commit ce65c56

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,10 @@ describe('babel-restore-jsx', () => {
108108
)
109109
).toMatchInlineSnapshot(`"<h1>{foo ? <p /> : null}</h1>;"`)
110110
})
111+
112+
it('should handle lowercase component names', () => {
113+
expect(jsx('React.createElement(aaa)')).toMatchInlineSnapshot(
114+
`"React.createElement(aaa);"`
115+
)
116+
})
111117
})

packages/plugin-react/src/jsx-runtime/babel-restore-jsx.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default function ({ types: t }: typeof babel): babel.PluginObj {
7676
return null
7777
}
7878

79-
const name = getJSXIdentifier(node)
79+
const name = getJSXIdentifier(node, true)
8080
if (name != null) {
8181
return name
8282
}
@@ -152,9 +152,9 @@ export default function ({ types: t }: typeof babel): babel.PluginObj {
152152
return children
153153
}
154154

155-
function getJSXIdentifier(node: any) {
155+
function getJSXIdentifier(node: any, tag = false) {
156156
//TODO: JSXNamespacedName
157-
if (t.isIdentifier(node)) {
157+
if (t.isIdentifier(node) && (!tag || node.name.match(/^[A-Z]/))) {
158158
return t.jsxIdentifier(node.name)
159159
}
160160
if (t.isStringLiteral(node)) {

0 commit comments

Comments
 (0)