@mui/codemod 6.4.4 → 6.4.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 +85 -10
- package/node/deprecations/all/deprecations-all.js +14 -0
- package/node/deprecations/all/postcss.config.js +4 -1
- package/node/deprecations/drawer-props/drawer-props.js +67 -0
- package/node/deprecations/drawer-props/index.js +13 -0
- package/node/deprecations/drawer-props/test-cases/actual.js +73 -0
- package/node/deprecations/drawer-props/test-cases/expected.js +97 -0
- package/node/deprecations/drawer-props/test-cases/theme.actual.js +58 -0
- package/node/deprecations/drawer-props/test-cases/theme.expected.js +74 -0
- package/node/deprecations/input-base-classes/index.js +13 -0
- package/node/deprecations/input-base-classes/input-base-classes.js +69 -0
- package/node/deprecations/input-base-classes/postcss-plugin.js +42 -0
- package/node/deprecations/input-base-classes/postcss.config.js +8 -0
- package/node/deprecations/input-base-classes/test-cases/actual.js +13 -0
- package/node/deprecations/input-base-classes/test-cases/expected.js +13 -0
- package/node/deprecations/menu-props/index.js +13 -0
- package/node/deprecations/menu-props/menu-props.js +37 -0
- package/node/deprecations/menu-props/test-cases/actual.js +67 -0
- package/node/deprecations/menu-props/test-cases/expected.js +83 -0
- package/node/deprecations/menu-props/test-cases/theme.actual.js +33 -0
- package/node/deprecations/menu-props/test-cases/theme.expected.js +39 -0
- package/node/deprecations/popover-props/index.js +13 -0
- package/node/deprecations/popover-props/popover-props.js +49 -0
- package/node/deprecations/popover-props/test-cases/actual.js +73 -0
- package/node/deprecations/popover-props/test-cases/expected.js +89 -0
- package/node/deprecations/popover-props/test-cases/theme.actual.js +19 -0
- package/node/deprecations/popover-props/test-cases/theme.expected.js +23 -0
- package/node/deprecations/snackbar-props/index.js +13 -0
- package/node/deprecations/snackbar-props/snackbar-props.js +43 -0
- package/node/deprecations/snackbar-props/test-cases/actual.js +54 -0
- package/node/deprecations/snackbar-props/test-cases/expected.js +67 -0
- package/node/deprecations/snackbar-props/test-cases/theme.actual.js +39 -0
- package/node/deprecations/snackbar-props/test-cases/theme.expected.js +46 -0
- package/node/deprecations/speed-dial-action-props/index.js +13 -0
- package/node/deprecations/speed-dial-action-props/speed-dial-action-props.js +52 -0
- package/node/deprecations/speed-dial-action-props/test-cases/actual.js +56 -0
- package/node/deprecations/speed-dial-action-props/test-cases/expected.js +104 -0
- package/node/deprecations/speed-dial-action-props/test-cases/theme.actual.js +62 -0
- package/node/deprecations/speed-dial-action-props/test-cases/theme.expected.js +88 -0
- package/node/deprecations/tabs-classes/index.js +13 -0
- package/node/deprecations/tabs-classes/postcss-plugin.js +33 -0
- package/node/deprecations/tabs-classes/postcss.config.js +8 -0
- package/node/deprecations/tabs-classes/tabs-classes.js +77 -0
- package/node/deprecations/tabs-classes/test-cases/actual.js +7 -0
- package/node/deprecations/tabs-classes/test-cases/expected.js +7 -0
- package/node/deprecations/tabs-props/index.js +13 -0
- package/node/deprecations/tabs-props/tabs-props.js +37 -0
- package/node/deprecations/tabs-props/test-cases/actual.js +33 -0
- package/node/deprecations/tabs-props/test-cases/expected.js +41 -0
- package/node/deprecations/tabs-props/test-cases/theme.actual.js +15 -0
- package/node/deprecations/tabs-props/test-cases/theme.expected.js +19 -0
- package/node/deprecations/utils/movePropIntoSlotProps.js +44 -19
- package/package.json +1 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
var _postcssPlugin = require("./postcss-plugin");
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
10
|
+
* @param {import('jscodeshift').API} api
|
|
11
|
+
*/
|
|
12
|
+
function transformer(file, api, options) {
|
|
13
|
+
const j = api.jscodeshift;
|
|
14
|
+
const root = j(file.source);
|
|
15
|
+
const printOptions = options.printOptions;
|
|
16
|
+
_postcssPlugin.classes.forEach(({
|
|
17
|
+
deprecatedClass,
|
|
18
|
+
replacementSelector
|
|
19
|
+
}) => {
|
|
20
|
+
const replacementSelectorPrefix = '&';
|
|
21
|
+
root.find(j.ImportDeclaration).filter(path => path.node.source.value.match(/^@mui\/material\/Tabs$/)).forEach(path => {
|
|
22
|
+
path.node.specifiers.forEach(specifier => {
|
|
23
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'tabsClasses') {
|
|
24
|
+
const deprecatedAtomicClass = deprecatedClass.replace(`${deprecatedClass.split('-')[0]}-`, '');
|
|
25
|
+
root.find(j.MemberExpression, {
|
|
26
|
+
object: {
|
|
27
|
+
name: specifier.local.name
|
|
28
|
+
},
|
|
29
|
+
property: {
|
|
30
|
+
name: deprecatedAtomicClass
|
|
31
|
+
}
|
|
32
|
+
}).forEach(memberExpression => {
|
|
33
|
+
const parent = memberExpression.parentPath.parentPath.value;
|
|
34
|
+
if (parent.type === j.TemplateLiteral.name) {
|
|
35
|
+
const memberExpressionIndex = parent.expressions.findIndex(expression => expression === memberExpression.value);
|
|
36
|
+
const precedingTemplateElement = parent.quasis[memberExpressionIndex];
|
|
37
|
+
const atomicClasses = replacementSelector.replaceAll('MuiTabs-', '').replaceAll(replacementSelectorPrefix, '').replaceAll(' > ', '').split('.').filter(Boolean);
|
|
38
|
+
if (precedingTemplateElement.value.raw.endsWith(deprecatedClass.startsWith(' ') ? `${replacementSelectorPrefix} .` : `${replacementSelectorPrefix}.`)) {
|
|
39
|
+
const atomicClassesArgs = [memberExpressionIndex, 1, ...atomicClasses.map(atomicClass => j.memberExpression(memberExpression.value.object, j.identifier(atomicClass)))];
|
|
40
|
+
parent.expressions.splice(...atomicClassesArgs);
|
|
41
|
+
if (replacementSelector.includes(' > ')) {
|
|
42
|
+
const quasisArgs = [memberExpressionIndex, 1, j.templateElement({
|
|
43
|
+
raw: precedingTemplateElement.value.raw.replace(' ', ''),
|
|
44
|
+
cooked: precedingTemplateElement.value.cooked.replace(' ', '')
|
|
45
|
+
}, false), j.templateElement({
|
|
46
|
+
raw: ' > .',
|
|
47
|
+
cooked: ' > .'
|
|
48
|
+
}, false)];
|
|
49
|
+
if (atomicClasses.length === 3) {
|
|
50
|
+
quasisArgs.splice(3, 0, j.templateElement({
|
|
51
|
+
raw: '.',
|
|
52
|
+
cooked: '.'
|
|
53
|
+
}, false));
|
|
54
|
+
}
|
|
55
|
+
parent.quasis.splice(...quasisArgs);
|
|
56
|
+
} else {
|
|
57
|
+
parent.quasis.splice(memberExpressionIndex, 1, j.templateElement({
|
|
58
|
+
raw: precedingTemplateElement.value.raw,
|
|
59
|
+
cooked: precedingTemplateElement.value.cooked
|
|
60
|
+
}, false), ...(atomicClasses.length > 1 ? [j.templateElement({
|
|
61
|
+
raw: '.',
|
|
62
|
+
cooked: '.'
|
|
63
|
+
}, false)] : []));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
const selectorRegex = new RegExp(`${replacementSelectorPrefix}${deprecatedClass}$`);
|
|
72
|
+
root.find(j.Literal, literal => typeof literal.value === 'string' && literal.value.match(selectorRegex)).forEach(path => {
|
|
73
|
+
path.replace(j.literal(path.value.value.replace(selectorRegex, `${replacementSelectorPrefix}${replacementSelector}`)));
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return root.toSource(printOptions);
|
|
77
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "default", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _tabsProps.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _tabsProps = _interopRequireDefault(require("./tabs-props"));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
var _movePropIntoSlots = _interopRequireDefault(require("../utils/movePropIntoSlots"));
|
|
9
|
+
var _movePropIntoSlotProps = _interopRequireDefault(require("../utils/movePropIntoSlotProps"));
|
|
10
|
+
/**
|
|
11
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
12
|
+
* @param {import('jscodeshift').API} api
|
|
13
|
+
*/
|
|
14
|
+
function transformer(file, api, options) {
|
|
15
|
+
const j = api.jscodeshift;
|
|
16
|
+
const root = j(file.source);
|
|
17
|
+
const printOptions = options.printOptions;
|
|
18
|
+
(0, _movePropIntoSlots.default)(j, {
|
|
19
|
+
root,
|
|
20
|
+
componentName: 'Tabs',
|
|
21
|
+
propName: 'ScrollButtonComponent',
|
|
22
|
+
slotName: 'scrollButton'
|
|
23
|
+
});
|
|
24
|
+
(0, _movePropIntoSlotProps.default)(j, {
|
|
25
|
+
root,
|
|
26
|
+
componentName: 'Tabs',
|
|
27
|
+
propName: 'TabScrollButtonProps',
|
|
28
|
+
slotName: 'scrollButton'
|
|
29
|
+
});
|
|
30
|
+
(0, _movePropIntoSlotProps.default)(j, {
|
|
31
|
+
root,
|
|
32
|
+
componentName: 'Tabs',
|
|
33
|
+
propName: 'TabIndicatorProps',
|
|
34
|
+
slotName: 'indicator'
|
|
35
|
+
});
|
|
36
|
+
return root.toSource(printOptions);
|
|
37
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _Tabs = _interopRequireDefault(require("@mui/material/Tabs"));
|
|
5
|
+
var _material = require("@mui/material");
|
|
6
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tabs.default, {
|
|
8
|
+
ScrollButtonComponent: CustomScrollButton,
|
|
9
|
+
TabScrollButtonProps: {
|
|
10
|
+
disableRipple: true
|
|
11
|
+
},
|
|
12
|
+
TabIndicatorProps: {
|
|
13
|
+
className: 'indicator'
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Tabs, {
|
|
17
|
+
ScrollButtonComponent: CustomScrollButton,
|
|
18
|
+
TabScrollButtonProps: {
|
|
19
|
+
disableRipple: true
|
|
20
|
+
},
|
|
21
|
+
TabIndicatorProps: {
|
|
22
|
+
className: 'indicator'
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(CustomTabs, {
|
|
26
|
+
ScrollButtonComponent: CustomScrollButton,
|
|
27
|
+
TabScrollButtonProps: {
|
|
28
|
+
disableRipple: true
|
|
29
|
+
},
|
|
30
|
+
TabIndicatorProps: {
|
|
31
|
+
className: 'indicator'
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _Tabs = _interopRequireDefault(require("@mui/material/Tabs"));
|
|
5
|
+
var _material = require("@mui/material");
|
|
6
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tabs.default, {
|
|
8
|
+
slots: {
|
|
9
|
+
scrollButton: CustomScrollButton
|
|
10
|
+
},
|
|
11
|
+
slotProps: {
|
|
12
|
+
scrollButton: {
|
|
13
|
+
disableRipple: true
|
|
14
|
+
},
|
|
15
|
+
indicator: {
|
|
16
|
+
className: 'indicator'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Tabs, {
|
|
21
|
+
slots: {
|
|
22
|
+
scrollButton: CustomScrollButton
|
|
23
|
+
},
|
|
24
|
+
slotProps: {
|
|
25
|
+
scrollButton: {
|
|
26
|
+
disableRipple: true
|
|
27
|
+
},
|
|
28
|
+
indicator: {
|
|
29
|
+
className: 'indicator'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(CustomTabs, {
|
|
34
|
+
ScrollButtonComponent: CustomScrollButton,
|
|
35
|
+
TabScrollButtonProps: {
|
|
36
|
+
disableRipple: true
|
|
37
|
+
},
|
|
38
|
+
TabIndicatorProps: {
|
|
39
|
+
className: 'indicator'
|
|
40
|
+
}
|
|
41
|
+
});
|
|
@@ -9,10 +9,11 @@ var _findComponentJSX = _interopRequireDefault(require("../../util/findComponent
|
|
|
9
9
|
var _findComponentDefaultProps = _interopRequireDefault(require("../../util/findComponentDefaultProps"));
|
|
10
10
|
var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
|
|
11
11
|
var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
|
|
12
|
-
function moveJsxPropIntoSlotProps(j, element, propName, slotName) {
|
|
12
|
+
function moveJsxPropIntoSlotProps(j, element, propName, slotName, slotPropName) {
|
|
13
13
|
const propIndex = element.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === propName);
|
|
14
14
|
if (propIndex !== -1) {
|
|
15
|
-
const
|
|
15
|
+
const removedAttr = element.openingElement.attributes.splice(propIndex, 1)[0];
|
|
16
|
+
const removedValue = removedAttr.value.type === 'StringLiteral' ? j.literal(removedAttr.value.value) : removedAttr.value.expression;
|
|
16
17
|
let hasSlotProps = false;
|
|
17
18
|
element.openingElement.attributes.forEach(attr => {
|
|
18
19
|
if (attr.name?.name === 'slotProps') {
|
|
@@ -20,31 +21,40 @@ function moveJsxPropIntoSlotProps(j, element, propName, slotName) {
|
|
|
20
21
|
const slots = attr.value.expression;
|
|
21
22
|
const slotIndex = slots.properties.findIndex(prop => prop?.key?.name === slotName);
|
|
22
23
|
if (slotIndex === -1) {
|
|
24
|
+
// Create new slot
|
|
25
|
+
const slotValue = slotPropName ? j.objectExpression([j.objectProperty(j.identifier(slotPropName), removedValue)]) : removedValue;
|
|
23
26
|
(0, _assignObject.default)(j, {
|
|
24
27
|
target: attr,
|
|
25
28
|
key: slotName,
|
|
26
|
-
expression:
|
|
29
|
+
expression: slotValue
|
|
27
30
|
});
|
|
28
31
|
} else {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
// Add property to existing slot
|
|
33
|
+
const existingSlot = slots.properties[slotIndex].value;
|
|
34
|
+
if (slotPropName) {
|
|
35
|
+
if (existingSlot.type === 'ObjectExpression') {
|
|
36
|
+
existingSlot.properties.push(j.objectProperty(j.identifier(slotPropName), removedValue));
|
|
37
|
+
} else {
|
|
38
|
+
slots.properties[slotIndex].value = j.objectExpression([j.objectProperty(j.identifier(slotPropName), removedValue)]);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
slots.properties[slotIndex].value = j.objectExpression([j.spreadElement(removedValue), j.spreadElement(existingSlot)]);
|
|
42
|
+
}
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
45
|
});
|
|
38
46
|
if (!hasSlotProps) {
|
|
47
|
+
// Create new slotProps
|
|
48
|
+
const slotValue = slotPropName ? j.objectExpression([j.objectProperty(j.identifier(slotPropName), removedValue)]) : removedValue;
|
|
39
49
|
(0, _appendAttribute.default)(j, {
|
|
40
50
|
target: element,
|
|
41
51
|
attributeName: 'slotProps',
|
|
42
|
-
expression: j.objectExpression([j.objectProperty(j.identifier(slotName),
|
|
52
|
+
expression: j.objectExpression([j.objectProperty(j.identifier(slotName), slotValue)])
|
|
43
53
|
});
|
|
44
54
|
}
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
|
-
function moveDefaultPropsPropIntoslotProps(j, defaultPropsPathCollection, propName, slotName) {
|
|
57
|
+
function moveDefaultPropsPropIntoslotProps(j, defaultPropsPathCollection, propName, slotName, slotPropName) {
|
|
48
58
|
defaultPropsPathCollection.find(j.ObjectProperty, {
|
|
49
59
|
key: {
|
|
50
60
|
name: propName
|
|
@@ -58,15 +68,28 @@ function moveDefaultPropsPropIntoslotProps(j, defaultPropsPathCollection, propNa
|
|
|
58
68
|
hasSlotProps = true;
|
|
59
69
|
const slotIndex = property.value.properties.findIndex(prop => prop?.key?.name === slotName);
|
|
60
70
|
if (slotIndex === -1) {
|
|
61
|
-
|
|
71
|
+
// Create new slot
|
|
72
|
+
const slotValue = slotPropName ? j.objectExpression([j.objectProperty(j.identifier(slotPropName), removedValue)]) : removedValue;
|
|
73
|
+
property.value.properties.push(j.objectProperty(j.identifier(slotName), slotValue));
|
|
62
74
|
} else {
|
|
63
|
-
|
|
64
|
-
property.value.properties
|
|
75
|
+
// Add property to existing slot
|
|
76
|
+
const existingSlot = property.value.properties[slotIndex].value;
|
|
77
|
+
if (slotPropName) {
|
|
78
|
+
if (existingSlot.type === 'ObjectExpression') {
|
|
79
|
+
existingSlot.properties.push(j.objectProperty(j.identifier(slotPropName), removedValue));
|
|
80
|
+
} else {
|
|
81
|
+
property.value.properties[slotIndex].value = j.objectExpression([j.objectProperty(j.identifier(slotPropName), removedValue)]);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
property.value.properties[slotIndex].value = j.objectExpression([j.spreadElement(removedValue), j.spreadElement(existingSlot)]);
|
|
85
|
+
}
|
|
65
86
|
}
|
|
66
87
|
}
|
|
67
88
|
});
|
|
68
89
|
if (!hasSlotProps) {
|
|
69
|
-
|
|
90
|
+
// Create new slotProps
|
|
91
|
+
const slotValue = slotPropName ? j.objectExpression([j.objectProperty(j.identifier(slotPropName), removedValue)]) : removedValue;
|
|
92
|
+
defaultProps.properties.push(j.objectProperty(j.identifier('slotProps'), j.objectExpression([j.objectProperty(j.identifier(slotName), slotValue)])));
|
|
70
93
|
}
|
|
71
94
|
path.prune();
|
|
72
95
|
});
|
|
@@ -78,26 +101,28 @@ function moveDefaultPropsPropIntoslotProps(j, defaultPropsPathCollection, propNa
|
|
|
78
101
|
* If there are duplicated values, the values will be spread.
|
|
79
102
|
*
|
|
80
103
|
* @param {import('jscodeshift')} j
|
|
81
|
-
* @param {{ root: import('jscodeshift').Collection; componentName: string, propName: string, slotName: string }} options
|
|
104
|
+
* @param {{ root: import('jscodeshift').Collection; componentName: string, propName: string, slotName: string, slotPropName?: string }} options
|
|
82
105
|
*
|
|
83
106
|
* @example <Component TransitionProps={value} /> => <Component slotProps={{ transition: value }} />
|
|
107
|
+
* @example <Component tooltipClasses={classes} /> => <Component slotProps={{ tooltip: { classes: classes } }} />
|
|
84
108
|
*/
|
|
85
109
|
function movePropIntoSlotProps(j, options) {
|
|
86
110
|
const {
|
|
87
111
|
root,
|
|
88
112
|
componentName,
|
|
89
113
|
propName,
|
|
90
|
-
slotName
|
|
114
|
+
slotName,
|
|
115
|
+
slotPropName
|
|
91
116
|
} = options;
|
|
92
117
|
(0, _findComponentJSX.default)(j, {
|
|
93
118
|
root,
|
|
94
119
|
componentName
|
|
95
120
|
}, elementPath => {
|
|
96
|
-
moveJsxPropIntoSlotProps(j, elementPath.node, propName, slotName);
|
|
121
|
+
moveJsxPropIntoSlotProps(j, elementPath.node, propName, slotName, slotPropName);
|
|
97
122
|
});
|
|
98
123
|
const defaultPropsPathCollection = (0, _findComponentDefaultProps.default)(j, {
|
|
99
124
|
root,
|
|
100
125
|
componentName
|
|
101
126
|
});
|
|
102
|
-
moveDefaultPropsPropIntoslotProps(j, defaultPropsPathCollection, propName, slotName);
|
|
127
|
+
moveDefaultPropsPropIntoslotProps(j, defaultPropsPathCollection, propName, slotName, slotPropName);
|
|
103
128
|
}
|