File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
packages/dev/codemods/src/s1-to-s2 Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,11 @@ exports[`Moves close function from DialogTrigger to Dialog 1`] = `
50
50
51
51
<DialogTrigger >
52
52
<Button >Test</Button >
53
- <Dialog >{ close => <>
53
+ <Dialog >{ (
54
+ {
55
+ close
56
+ }
57
+ ) => <>
54
58
<Heading >Test</Heading >
55
59
56
60
<Content >Content</Content >
@@ -74,7 +78,11 @@ exports[`Removes onDismiss and leaves a comment 1`] = `
74
78
<DialogTrigger >
75
79
<Button >Test</Button >
76
80
// 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
+ ) => <>
78
86
<Heading >Test</Heading >
79
87
80
88
<Content >Content</Content >
Original file line number Diff line number Diff line change @@ -386,9 +386,23 @@ function moveRenderPropsToChild(
386
386
) {
387
387
const dialogElement = renderFunction . expression . body ;
388
388
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
+
389
403
const newRenderFunction = t . jsxExpressionContainer (
390
404
t . arrowFunctionExpression (
391
- renderFunction . expression . params ,
405
+ [ objectPattern ] ,
392
406
t . jsxFragment (
393
407
t . jsxOpeningFragment ( ) ,
394
408
t . jsxClosingFragment ( ) ,
You can’t perform that action at this time.
0 commit comments