Skip to content

Commit c89de3a

Browse files
authored
fix(plugin-react): duplicate __self prop and __source prop (#9387)
1 parent af599ce commit c89de3a

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,18 @@ describe('babel-restore-jsx', () => {
115115
`"React.createElement(aaa);"`
116116
)
117117
})
118+
119+
it('should not handle contains __self prop', () => {
120+
expect(
121+
jsx('React.createElement(Provider, { __self: this })')
122+
).toMatchInlineSnapshot('"<Provider />;"')
123+
})
124+
125+
it('should not handle contains __source prop', () => {
126+
expect(
127+
jsx(
128+
'React.createElement(Provider, { __source: { fileName: _jsxFileName, lineNumber: 133 }})'
129+
)
130+
).toMatchInlineSnapshot('"<Provider />;"')
131+
})
118132
})

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,20 @@ export default function (
126126
if (!isPlainObjectExpression(node)) {
127127
return null
128128
}
129-
return node.properties.map((prop: any) =>
130-
t.isObjectProperty(prop)
131-
? t.jsxAttribute(
132-
getJSXIdentifier(prop.key)!,
133-
getJSXAttributeValue(prop.value)
134-
)
135-
: t.jsxSpreadAttribute(prop.argument)
136-
)
129+
return node.properties
130+
.map((prop: any) =>
131+
t.isObjectProperty(prop)
132+
? t.jsxAttribute(
133+
getJSXIdentifier(prop.key)!,
134+
getJSXAttributeValue(prop.value)
135+
)
136+
: t.jsxSpreadAttribute(prop.argument)
137+
)
138+
.filter((prop: any) =>
139+
t.isJSXIdentifier(prop.name)
140+
? prop.name.name !== '__self' && prop.name.name !== '__source'
141+
: true
142+
)
137143
}
138144

139145
function getJSXChild(node: any) {

0 commit comments

Comments
 (0)