Skip to content

Commit 68e3057

Browse files
authored
fix dialog codemod close function (#7233)
1 parent cbac9c0 commit 68e3057

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

packages/dev/codemods/src/s1-to-s2/__tests__/__snapshots__/dialog.test.ts.snap

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ exports[`Moves close function from DialogTrigger to Dialog 1`] = `
5050
5151
<DialogTrigger>
5252
<Button>Test</Button>
53-
<Dialog>{close => <>
53+
<Dialog>{(
54+
{
55+
close
56+
}
57+
) => <>
5458
<Heading>Test</Heading>
5559
5660
<Content>Content</Content>
@@ -74,7 +78,11 @@ exports[`Removes onDismiss and leaves a comment 1`] = `
7478
<DialogTrigger>
7579
<Button>Test</Button>
7680
// onDismiss was removed from Dialog. Use onOpenChange on the DialogTrigger, or onDismiss on the DialogContainer instead
77-
<Dialog>{close => <>
81+
<Dialog>{(
82+
{
83+
close
84+
}
85+
) => <>
7886
<Heading>Test</Heading>
7987
8088
<Content>Content</Content>

packages/dev/codemods/src/s1-to-s2/src/codemods/transforms.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,23 @@ function moveRenderPropsToChild(
386386
) {
387387
const dialogElement = renderFunction.expression.body;
388388

389+
const originalParam = renderFunction.expression.params[0];
390+
if (!t.isIdentifier(originalParam)) {
391+
addComment(path.node.children[renderFunctionIndex], ' TODO(S2-upgrade): Could not automatically move the render props. You\'ll need to update this manually.');
392+
return;
393+
}
394+
const paramName = originalParam.name;
395+
const objectPattern = t.objectPattern([
396+
t.objectProperty(t.identifier(paramName),
397+
t.identifier(paramName),
398+
false,
399+
true
400+
)
401+
]);
402+
389403
const newRenderFunction = t.jsxExpressionContainer(
390404
t.arrowFunctionExpression(
391-
renderFunction.expression.params,
405+
[objectPattern],
392406
t.jsxFragment(
393407
t.jsxOpeningFragment(),
394408
t.jsxClosingFragment(),

0 commit comments

Comments
 (0)