Skip to content
This repository was archived by the owner on Jun 24, 2023. It is now read-only.

[WIP] stop adding _source prop if element is react fragment #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/vite/src/babel/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ export const reactThreeEditorBabel = (api: ConfigAPI): PluginObj => {
if (
// the element was generated and doesn't have location information
!node.loc ||
// Already has __source
path.node.attributes.some(isSourceAttr)
// Already has __source or is fragment
path.node.attributes.some(isSourceAttr) ||
isReactFragment(node)
) {
return
}
Expand Down Expand Up @@ -236,7 +237,6 @@ export const reactThreeEditorBabel = (api: ConfigAPI): PluginObj => {
init: t.stringLiteral(state.filename || "")
})
}

node.attributes.push(
t.jsxAttribute(
t.jsxIdentifier(TRACE_ID),
Expand Down Expand Up @@ -300,3 +300,16 @@ export const reactThreeEditorBabel = (api: ConfigAPI): PluginObj => {
}
}
}

function isReactFragment(node: t.JSXOpeningElement) {
if (t.isJSXMemberExpression(node.name)) {
if (t.isJSXIdentifier(node.name.object)) {
return (
node.name.object.name === "React" &&
node.name.property.name === "Fragment"
)
}
} else if (t.isJSXIdentifier(node.name)) {
return node.name.name === "Fragment"
}
}