Skip to content

Commit

Permalink
fix(plugin-react): restore-jsx bug when component name is lowercase (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cyco130 authored Dec 16, 2021
1 parent 5f39c28 commit ce65c56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ describe('babel-restore-jsx', () => {
)
).toMatchInlineSnapshot(`"<h1>{foo ? <p /> : null}</h1>;"`)
})

it('should handle lowercase component names', () => {
expect(jsx('React.createElement(aaa)')).toMatchInlineSnapshot(
`"React.createElement(aaa);"`
)
})
})
6 changes: 3 additions & 3 deletions packages/plugin-react/src/jsx-runtime/babel-restore-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function ({ types: t }: typeof babel): babel.PluginObj {
return null
}

const name = getJSXIdentifier(node)
const name = getJSXIdentifier(node, true)
if (name != null) {
return name
}
Expand Down Expand Up @@ -152,9 +152,9 @@ export default function ({ types: t }: typeof babel): babel.PluginObj {
return children
}

function getJSXIdentifier(node: any) {
function getJSXIdentifier(node: any, tag = false) {
//TODO: JSXNamespacedName
if (t.isIdentifier(node)) {
if (t.isIdentifier(node) && (!tag || node.name.match(/^[A-Z]/))) {
return t.jsxIdentifier(node.name)
}
if (t.isStringLiteral(node)) {
Expand Down

0 comments on commit ce65c56

Please sign in to comment.