@mui/codemod 5.11.5 → 5.11.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/codemod.js +0 -0
- package/node/v5.0.0/joy-avatar-remove-imgProps.js +68 -0
- package/node/v5.0.0/joy-avatar-remove-imgProps.test/actual.js +32 -0
- package/node/v5.0.0/joy-avatar-remove-imgProps.test/expected.js +32 -0
- package/node/v5.0.0/joy-text-field-to-input.js +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,24 @@ npx @mui/codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":\"
|
|
|
62
62
|
|
|
63
63
|
### v5.0.0
|
|
64
64
|
|
|
65
|
+
#### `joy-avatar-remove-imgProps`
|
|
66
|
+
|
|
67
|
+
Remove `imgProps` prop by transferring its value into `slotProps.img`
|
|
68
|
+
|
|
69
|
+
This change only affects Joy UI Avatar component.
|
|
70
|
+
|
|
71
|
+
```diff
|
|
72
|
+
<Avatar
|
|
73
|
+
- imgProps={{ ['data-id']: 'imageId' }}
|
|
74
|
+
- slotProps={{ root: { ['data-id']: 'rootId' }}}
|
|
75
|
+
+ slotProps={{ root: { ['data-id']: 'rootId' }, img: { ['data-id']: 'imageId' } }}
|
|
76
|
+
/>;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
npx @mui/codemod v5.0.0/joy-avatar-remove-imgProps <path>
|
|
81
|
+
```
|
|
82
|
+
|
|
65
83
|
#### `joy-text-field-to-input`
|
|
66
84
|
|
|
67
85
|
Replace `<TextField>` with composition of `Input`
|
package/codemod.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
9
|
+
* @param {import('jscodeshift').API} api
|
|
10
|
+
*/
|
|
11
|
+
function transformer(file, api, options) {
|
|
12
|
+
const j = api.jscodeshift;
|
|
13
|
+
const root = j(file.source);
|
|
14
|
+
const printOptions = options.printOptions;
|
|
15
|
+
root.find(j.ImportDeclaration).filter(({
|
|
16
|
+
node
|
|
17
|
+
}) => {
|
|
18
|
+
const sourceVal = node.source.value;
|
|
19
|
+
return ['@mui/joy',
|
|
20
|
+
// Process only Joy UI components
|
|
21
|
+
'@mui/joy/Avatar' // Filter default imports of components other than `Avatar`
|
|
22
|
+
].includes(sourceVal);
|
|
23
|
+
}).forEach(path => {
|
|
24
|
+
path.node.specifiers.forEach(elementNode => {
|
|
25
|
+
var _elementNode$imported;
|
|
26
|
+
if (elementNode.type === 'ImportSpecifier' && ((_elementNode$imported = elementNode.imported) == null ? void 0 : _elementNode$imported.name) === 'Avatar' || elementNode.type === 'ImportDefaultSpecifier') {
|
|
27
|
+
// Process only Joy `Avatar` component
|
|
28
|
+
root.findJSXElements(elementNode.local.name).forEach(elementPath => {
|
|
29
|
+
if (elementPath.node.type !== 'JSXElement') {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const slotPropsAttributeNode = elementPath.node.openingElement.attributes.find(attributeNode => {
|
|
33
|
+
var _attributeNode$value$;
|
|
34
|
+
return attributeNode.type === 'JSXAttribute' && attributeNode.name.name === 'slotProps' && ((_attributeNode$value$ = attributeNode.value.expression) == null ? void 0 : _attributeNode$value$.type) === 'ObjectExpression';
|
|
35
|
+
});
|
|
36
|
+
const newAttributeNodes = [];
|
|
37
|
+
elementPath.node.openingElement.attributes.forEach(attributeNode => {
|
|
38
|
+
if (attributeNode.type !== 'JSXAttribute') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (attributeNode.name.name !== 'imgProps') {
|
|
42
|
+
newAttributeNodes.push(attributeNode);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const val = attributeNode.value;
|
|
46
|
+
if (!(val != null && val.expression)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (slotPropsAttributeNode) {
|
|
50
|
+
const imgObjInSlotProps = slotPropsAttributeNode.value.expression.properties.find(propNode => propNode.key.name === 'img' && propNode.value.type === 'ObjectExpression');
|
|
51
|
+
if (imgObjInSlotProps) {
|
|
52
|
+
const newProperties = [...imgObjInSlotProps.value.properties, ...attributeNode.value.expression.properties];
|
|
53
|
+
imgObjInSlotProps.value.properties = newProperties;
|
|
54
|
+
} else {
|
|
55
|
+
slotPropsAttributeNode.value.expression.properties.push(j.objectProperty(j.identifier('img'), attributeNode.value));
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
newAttributeNodes.push(j.jsxAttribute(j.jsxIdentifier('slotProps'), j.jsxExpressionContainer(j.objectExpression([j.objectProperty(j.identifier('img'), attributeNode.value.expression)]))));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
elementPath.node.openingElement.attributes = newAttributeNodes;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
const transformed = root.findJSXElements();
|
|
67
|
+
return transformed.toSource(printOptions);
|
|
68
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _joy = require("@mui/joy");
|
|
5
|
+
var _Avatar = _interopRequireDefault(require("@mui/joy/Avatar"));
|
|
6
|
+
var _Avatar2 = _interopRequireDefault(require("@mui/material/Avatar"));
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
// the codemod should transform only Joy UI `Avatar`;
|
|
9
|
+
|
|
10
|
+
/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
11
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_joy.Avatar, {
|
|
12
|
+
imgProps: {
|
|
13
|
+
['aria-hidden']: true
|
|
14
|
+
}
|
|
15
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
|
|
16
|
+
slotProps: {
|
|
17
|
+
root: {
|
|
18
|
+
['aria-hidden']: false
|
|
19
|
+
},
|
|
20
|
+
img: {
|
|
21
|
+
['aria-label']: 'imgSlot'
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
imgProps: {
|
|
25
|
+
['aria-hidden']: true
|
|
26
|
+
}
|
|
27
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar2.default, {
|
|
28
|
+
imgProps: {
|
|
29
|
+
['aria-hidden']: true
|
|
30
|
+
}
|
|
31
|
+
})]
|
|
32
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _joy = require("@mui/joy");
|
|
5
|
+
var _Avatar = _interopRequireDefault(require("@mui/joy/Avatar"));
|
|
6
|
+
var _Avatar2 = _interopRequireDefault(require("@mui/material/Avatar"));
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
// the codemod should transform only Joy UI `Avatar`;
|
|
9
|
+
|
|
10
|
+
/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
11
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_joy.Avatar, {
|
|
12
|
+
slotProps: {
|
|
13
|
+
img: {
|
|
14
|
+
['aria-hidden']: true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
|
|
18
|
+
slotProps: {
|
|
19
|
+
root: {
|
|
20
|
+
['aria-hidden']: false
|
|
21
|
+
},
|
|
22
|
+
img: {
|
|
23
|
+
['aria-label']: 'imgSlot',
|
|
24
|
+
['aria-hidden']: true
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar2.default, {
|
|
28
|
+
imgProps: {
|
|
29
|
+
['aria-hidden']: true
|
|
30
|
+
}
|
|
31
|
+
})]
|
|
32
|
+
});
|
|
@@ -64,7 +64,6 @@ function transformer(file, api, options) {
|
|
|
64
64
|
}
|
|
65
65
|
propNode.value.properties.forEach(prop => {
|
|
66
66
|
const key = prop.key.value;
|
|
67
|
-
// const value = prop.value.value;
|
|
68
67
|
const newAttributeNode = j.jsxAttribute(j.jsxIdentifier(key), j.jsxExpressionContainer(prop.value));
|
|
69
68
|
switch (propNode.key.name) {
|
|
70
69
|
case 'root':
|