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`] = `
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 >
Original file line number Diff line number Diff 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 ( ) ,
You can’t perform that action at this time.
0 commit comments