Skip to content

Commit 25e2e76

Browse files
committed
Fix codemod
1 parent 60ea322 commit 25e2e76

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

packages/mui-codemod/src/v5.0.0/joy-rename-components-to-slots.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,41 @@ export default function transformer(file, api, options) {
2828
const root = j(file.source);
2929
const printOptions = options.printOptions;
3030

31-
const transformed = root.findJSXElements().forEach((path) => {
32-
if (path.node.type !== 'JSXElement') {
33-
return;
34-
}
31+
root
32+
.find(j.ImportDeclaration)
33+
.filter(({ node }) => {
34+
return node.source.value.startsWith('@mui/joy');
35+
})
36+
.forEach((path) => {
37+
path.node.specifiers.forEach((node) => {
38+
// Process only Joy UI components
39+
root.findJSXElements(node.local.name).forEach((elementPath) => {
40+
if (elementPath.node.type !== 'JSXElement') {
41+
return;
42+
}
3543

36-
path.node.openingElement.attributes.forEach((node) => {
37-
if (node.type !== 'JSXAttribute') {
38-
return;
39-
}
44+
elementPath.node.openingElement.attributes.forEach((elementNode) => {
45+
if (elementNode.type !== 'JSXAttribute') {
46+
return;
47+
}
4048

41-
switch (node.name.name) {
42-
case 'components':
43-
transformComponentsProp(node);
44-
break;
49+
switch (elementNode.name.name) {
50+
case 'components':
51+
transformComponentsProp(elementNode);
52+
break;
4553

46-
case 'componentsProps':
47-
transformComponentsPropsProp(node);
48-
break;
54+
case 'componentsProps':
55+
transformComponentsPropsProp(elementNode);
56+
break;
4957

50-
default:
51-
}
58+
default:
59+
}
60+
});
61+
});
62+
});
5263
});
53-
});
64+
65+
const transformed = root.findJSXElements();
5466

5567
return transformed.toSource(printOptions);
5668
}

0 commit comments

Comments
 (0)