@@ -132,27 +132,32 @@ module.exports = {
132
132
// Check if this is an aliased component from styled-react
133
133
const originalComponentName = aliasMapping . get ( componentName ) || componentName
134
134
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
+
135
140
// 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 )
138
143
139
144
// Check if this component has an sx prop
140
145
const hasSxProp = openingElement . attributes . some (
141
146
attr => attr . type === 'JSXAttribute' && attr . name && attr . name . name === 'sx' ,
142
147
)
143
148
144
149
if ( hasSxProp ) {
145
- componentsWithSx . add ( originalComponentName )
150
+ componentsWithSx . add ( parentComponentName )
146
151
jsxElementsWithSx . push ( { node, componentName : originalComponentName , openingElement} )
147
152
} else {
148
- componentsWithoutSx . add ( originalComponentName )
153
+ componentsWithoutSx . add ( parentComponentName )
149
154
150
155
// If this is an aliased component without sx, we need to track it for renaming
151
156
if ( aliasMapping . has ( componentName ) ) {
152
157
jsxElementsWithoutSx . push ( {
153
158
node,
154
159
localName : componentName ,
155
- originalName : originalComponentName ,
160
+ originalName : parentComponentName ,
156
161
openingElement,
157
162
} )
158
163
}
@@ -293,17 +298,14 @@ module.exports = {
293
298
messageId : 'useAliasedComponent' ,
294
299
data : { componentName, aliasName} ,
295
300
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 )
300
303
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 )
305
307
306
- return fixes
308
+ return fixer . replaceText ( jsxNode , aliasedText )
307
309
} ,
308
310
} )
309
311
}
0 commit comments