Skip to content

Commit

Permalink
fix(plugin-react): duplicate __self prop and __source prop (#9387)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Aug 29, 2022
1 parent af599ce commit c89de3a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
14 changes: 14 additions & 0 deletions packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts
Expand Up @@ -115,4 +115,18 @@ describe('babel-restore-jsx', () => {
`"React.createElement(aaa);"`
)
})

it('should not handle contains __self prop', () => {
expect(
jsx('React.createElement(Provider, { __self: this })')
).toMatchInlineSnapshot('"<Provider />;"')
})

it('should not handle contains __source prop', () => {
expect(
jsx(
'React.createElement(Provider, { __source: { fileName: _jsxFileName, lineNumber: 133 }})'
)
).toMatchInlineSnapshot('"<Provider />;"')
})
})
22 changes: 14 additions & 8 deletions packages/plugin-react/src/jsx-runtime/babel-restore-jsx.ts
Expand Up @@ -126,14 +126,20 @@ export default function (
if (!isPlainObjectExpression(node)) {
return null
}
return node.properties.map((prop: any) =>
t.isObjectProperty(prop)
? t.jsxAttribute(
getJSXIdentifier(prop.key)!,
getJSXAttributeValue(prop.value)
)
: t.jsxSpreadAttribute(prop.argument)
)
return node.properties
.map((prop: any) =>
t.isObjectProperty(prop)
? t.jsxAttribute(
getJSXIdentifier(prop.key)!,
getJSXAttributeValue(prop.value)
)
: t.jsxSpreadAttribute(prop.argument)
)
.filter((prop: any) =>
t.isJSXIdentifier(prop.name)
? prop.name.name !== '__self' && prop.name.name !== '__source'
: true
)
}

function getJSXChild(node: any) {
Expand Down

0 comments on commit c89de3a

Please sign in to comment.