Skip to content

Commit

Permalink
fix dialog codemod close function (#7233)
Browse files Browse the repository at this point in the history
  • Loading branch information
reidbarber authored Oct 23, 2024
1 parent cbac9c0 commit 68e3057
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ exports[`Moves close function from DialogTrigger to Dialog 1`] = `
<DialogTrigger>
<Button>Test</Button>
<Dialog>{close => <>
<Dialog>{(
{
close
}
) => <>
<Heading>Test</Heading>
<Content>Content</Content>
Expand All @@ -74,7 +78,11 @@ exports[`Removes onDismiss and leaves a comment 1`] = `
<DialogTrigger>
<Button>Test</Button>
// onDismiss was removed from Dialog. Use onOpenChange on the DialogTrigger, or onDismiss on the DialogContainer instead
<Dialog>{close => <>
<Dialog>{(
{
close
}
) => <>
<Heading>Test</Heading>
<Content>Content</Content>
Expand Down
16 changes: 15 additions & 1 deletion packages/dev/codemods/src/s1-to-s2/src/codemods/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,23 @@ function moveRenderPropsToChild(
) {
const dialogElement = renderFunction.expression.body;

const originalParam = renderFunction.expression.params[0];
if (!t.isIdentifier(originalParam)) {
addComment(path.node.children[renderFunctionIndex], ' TODO(S2-upgrade): Could not automatically move the render props. You\'ll need to update this manually.');
return;
}
const paramName = originalParam.name;
const objectPattern = t.objectPattern([
t.objectProperty(t.identifier(paramName),
t.identifier(paramName),
false,
true
)
]);

const newRenderFunction = t.jsxExpressionContainer(
t.arrowFunctionExpression(
renderFunction.expression.params,
[objectPattern],
t.jsxFragment(
t.jsxOpeningFragment(),
t.jsxClosingFragment(),
Expand Down

1 comment on commit 68e3057

@rspbot
Copy link

@rspbot rspbot commented on 68e3057 Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.