@@ -132,27 +132,32 @@ module.exports = {
132132 // Check if this is an aliased component from styled-react
133133 const originalComponentName = aliasMapping . get ( componentName ) || componentName
134134
135+ // For compound components like "ActionList.Item", we need to check the parent component
136+ const parentComponentName = originalComponentName . includes ( '.' )
137+ ? originalComponentName . split ( '.' ) [ 0 ]
138+ : originalComponentName
139+
135140 // Track all used components that are in our styled components list
136- if ( styledComponents . has ( originalComponentName ) ) {
137- allUsedComponents . add ( originalComponentName )
141+ if ( styledComponents . has ( parentComponentName ) ) {
142+ allUsedComponents . add ( parentComponentName )
138143
139144 // Check if this component has an sx prop
140145 const hasSxProp = openingElement . attributes . some (
141146 attr => attr . type === 'JSXAttribute' && attr . name && attr . name . name === 'sx' ,
142147 )
143148
144149 if ( hasSxProp ) {
145- componentsWithSx . add ( originalComponentName )
150+ componentsWithSx . add ( parentComponentName )
146151 jsxElementsWithSx . push ( { node, componentName : originalComponentName , openingElement} )
147152 } else {
148- componentsWithoutSx . add ( originalComponentName )
153+ componentsWithoutSx . add ( parentComponentName )
149154
150155 // If this is an aliased component without sx, we need to track it for renaming
151156 if ( aliasMapping . has ( componentName ) ) {
152157 jsxElementsWithoutSx . push ( {
153158 node,
154159 localName : componentName ,
155- originalName : originalComponentName ,
160+ originalName : parentComponentName ,
156161 openingElement,
157162 } )
158163 }
@@ -293,17 +298,14 @@ module.exports = {
293298 messageId : 'useAliasedComponent' ,
294299 data : { componentName, aliasName} ,
295300 fix ( fixer ) {
296- const fixes = [ ]
297-
298- // Replace the component name in the JSX opening tag
299- fixes . push ( fixer . replaceText ( openingElement . name , aliasName ) )
301+ const sourceCode = context . getSourceCode ( )
302+ const jsxText = sourceCode . getText ( jsxNode )
300303
301- // Replace the component name in the JSX closing tag if it exists
302- if ( jsxNode . closingElement ) {
303- fixes . push ( fixer . replaceText ( jsxNode . closingElement . name , aliasName ) )
304- }
304+ // Replace all instances of the component name (both main component and compound components)
305+ const componentPattern = new RegExp ( `\\b${ componentName } (?=\\.|\\s|>)` , 'g' )
306+ const aliasedText = jsxText . replace ( componentPattern , aliasName )
305307
306- return fixes
308+ return fixer . replaceText ( jsxNode , aliasedText )
307309 } ,
308310 } )
309311 }
0 commit comments