From b3f2d2439e4df124b70149205cbb37af07db0220 Mon Sep 17 00:00:00 2001 From: peetck Date: Thu, 10 Oct 2024 10:41:11 +0700 Subject: [PATCH] fix: improve isReactNode (also check _Fragment) --- src/pluginConstants.ts | 4 ++++ src/utils/magicString/react/isReactNode/index.ts | 10 ++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pluginConstants.ts b/src/pluginConstants.ts index c9b2a21..14c9088 100644 --- a/src/pluginConstants.ts +++ b/src/pluginConstants.ts @@ -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'] diff --git a/src/utils/magicString/react/isReactNode/index.ts b/src/utils/magicString/react/isReactNode/index.ts index 115fdec..ff940fc 100644 --- a/src/utils/magicString/react/isReactNode/index.ts +++ b/src/utils/magicString/react/isReactNode/index.ts @@ -1,14 +1,12 @@ +import { FRAGMENT_NAMES, JSX_CALLEE_NAMES } from 'pluginConstants' + export default function isReactNode(node: Record) { 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 }