Skip to content

Commit

Permalink
Merge pull request #8 from peetck/main
Browse files Browse the repository at this point in the history
fix: improve isReactNode (also check _Fragment)
  • Loading branch information
peetck authored Oct 11, 2024
2 parents 236ca91 + b3f2d24 commit 91b5f94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/pluginConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ export const IS_E2E_ENABLED = "process.env.E2E_ENABLED === 'true'"
export const UNCHANGED = null

export const DATA_QA = 'data-qa'

export const JSX_CALLEE_NAMES = ['jsxDEV', 'jsx', '_jsx', 'jsxs', '_jsxs']

export const FRAGMENT_NAMES = ['Fragment', '_Fragment']
10 changes: 4 additions & 6 deletions src/utils/magicString/react/isReactNode/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { FRAGMENT_NAMES, JSX_CALLEE_NAMES } from 'pluginConstants'

export default function isReactNode(node: Record<string, any>) {
const isReactCreateElement =
node?.callee?.object?.name === 'React' && node?.callee?.property?.name === 'createElement'

const isJsxAndNotFragment =
(node?.callee?.name === 'jsxDEV' ||
node?.callee?.name === 'jsx' ||
node?.callee?.name === '_jsx' ||
node?.callee?.name === 'jsxs' ||
node?.callee?.name === '_jsxs') &&
node?.arguments?.[0]?.name !== 'Fragment'
JSX_CALLEE_NAMES.includes(node?.callee?.name) &&
!FRAGMENT_NAMES.includes(node?.arguments?.[0]?.name)

return isReactCreateElement || isJsxAndNotFragment
}

0 comments on commit 91b5f94

Please sign in to comment.