@@ -67,6 +67,7 @@ module.exports = function transformProtectToShow({ source }, { jscodeshift: j })
6767 const root = j ( source ) ;
6868 let dirtyFlag = false ;
6969 const protectLocalNames = [ ] ;
70+ const protectPropsLocalsToRename = [ ] ;
7071
7172 const isClientComponent = hasUseClientDirective ( root , j ) ;
7273
@@ -87,29 +88,61 @@ module.exports = function transformProtectToShow({ source }, { jscodeshift: j })
8788 return undefined ;
8889 }
8990
90- // Transform imports: Protect → Show
91+ // Transform imports: Protect → Show, ProtectProps → ShowProps
9192 const allPackages = [ ...CLIENT_ONLY_PACKAGES , ...HYBRID_PACKAGES ] ;
9293 allPackages . forEach ( packageName => {
9394 root . find ( j . ImportDeclaration , { source : { value : packageName } } ) . forEach ( path => {
9495 const node = path . node ;
9596 const specifiers = node . specifiers || [ ] ;
9697
9798 specifiers . forEach ( spec => {
98- if ( j . ImportSpecifier . check ( spec ) && spec . imported . name === 'Protect' ) {
99- const effectiveLocalName = spec . local ? spec . local . name : spec . imported . name ;
100- spec . imported . name = 'Show' ;
101- if ( spec . local && spec . local . name === 'Protect' ) {
102- spec . local . name = 'Show' ;
99+ if ( j . ImportSpecifier . check ( spec ) ) {
100+ if ( spec . imported . name === 'Protect' ) {
101+ const effectiveLocalName = spec . local ? spec . local . name : spec . imported . name ;
102+ spec . imported . name = 'Show' ;
103+ if ( spec . local && spec . local . name === 'Protect' ) {
104+ spec . local . name = 'Show' ;
105+ }
106+ if ( ! protectLocalNames . includes ( effectiveLocalName ) ) {
107+ protectLocalNames . push ( effectiveLocalName ) ;
108+ }
109+ dirtyFlag = true ;
103110 }
104- if ( ! protectLocalNames . includes ( effectiveLocalName ) ) {
105- protectLocalNames . push ( effectiveLocalName ) ;
111+
112+ if ( spec . imported . name === 'ProtectProps' ) {
113+ const effectiveLocalName = spec . local ? spec . local . name : spec . imported . name ;
114+ spec . imported . name = 'ShowProps' ;
115+ if ( spec . local && spec . local . name === 'ProtectProps' ) {
116+ spec . local . name = 'ShowProps' ;
117+ }
118+ if ( effectiveLocalName === 'ProtectProps' ) {
119+ protectPropsLocalsToRename . push ( effectiveLocalName ) ;
120+ }
121+ dirtyFlag = true ;
106122 }
107- dirtyFlag = true ;
108123 }
109124 } ) ;
110125 } ) ;
111126 } ) ;
112127
128+ // Rename references to ProtectProps (only when local name was ProtectProps)
129+ if ( protectPropsLocalsToRename . length > 0 ) {
130+ root
131+ . find ( j . TSTypeReference , {
132+ typeName : {
133+ type : 'Identifier' ,
134+ name : 'ProtectProps' ,
135+ } ,
136+ } )
137+ . forEach ( path => {
138+ const typeName = path . node . typeName ;
139+ if ( j . Identifier . check ( typeName ) && typeName . name === 'ProtectProps' ) {
140+ typeName . name = 'ShowProps' ;
141+ dirtyFlag = true ;
142+ }
143+ } ) ;
144+ }
145+
113146 // Transform JSX: <Protect ...> → <Show when={...}>
114147 root . find ( j . JSXElement ) . forEach ( path => {
115148 const openingElement = path . node . openingElement ;
@@ -185,9 +218,9 @@ module.exports = function transformProtectToShow({ source }, { jscodeshift: j })
185218 // Reconstruct attributes with `when` prop
186219 const newAttributes = [ ] ;
187220
188- if ( whenValue ) {
189- newAttributes . push ( j . jsxAttribute ( j . jsxIdentifier ( 'when' ) , whenValue ) ) ;
190- }
221+ const finalWhenValue = whenValue || j . stringLiteral ( 'signedIn' ) ;
222+
223+ newAttributes . push ( j . jsxAttribute ( j . jsxIdentifier ( 'when' ) , finalWhenValue ) ) ;
191224
192225 // Add remaining attributes (fallback, etc.)
193226 otherAttributes . forEach ( attr => newAttributes . push ( attr ) ) ;
0 commit comments