@mui/codemod 6.0.0-alpha.0 → 6.0.0-alpha.3
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 +182 -2
- package/node/deprecations/accordion-props/accordion-props.js +11 -71
- package/node/deprecations/accordion-props/test-cases/actual.js +16 -0
- package/node/deprecations/accordion-props/test-cases/expected.js +14 -0
- package/node/deprecations/accordion-props/test-cases/theme.actual.js +24 -0
- package/node/deprecations/accordion-props/test-cases/theme.expected.js +24 -0
- package/node/deprecations/all/deprecations-all.js +4 -0
- package/node/deprecations/all/postcss.config.js +7 -1
- package/node/deprecations/avatar-props/avatar-props.js +5 -39
- package/node/deprecations/avatar-props/test-cases/actual.js +10 -0
- package/node/deprecations/avatar-props/test-cases/expected.js +10 -0
- package/node/deprecations/avatar-props/test-cases/theme.actual.js +14 -0
- package/node/deprecations/avatar-props/test-cases/theme.expected.js +15 -0
- package/node/deprecations/backdrop-props/backdrop-props.js +5 -61
- package/node/deprecations/backdrop-props/test-cases/actual.js +8 -7
- package/node/deprecations/backdrop-props/test-cases/expected.js +7 -7
- package/node/deprecations/backdrop-props/test-cases/theme.actual.js +11 -0
- package/node/deprecations/backdrop-props/test-cases/theme.expected.js +12 -2
- package/node/deprecations/badge-props/badge-props.js +22 -0
- package/node/deprecations/badge-props/index.js +13 -0
- package/node/deprecations/badge-props/test-cases/actual.js +59 -0
- package/node/deprecations/badge-props/test-cases/expected.js +44 -0
- package/node/deprecations/badge-props/test-cases/theme.actual.js +73 -0
- package/node/deprecations/badge-props/test-cases/theme.expected.js +58 -0
- package/node/deprecations/step-connector-classes/index.js +13 -0
- package/node/deprecations/step-connector-classes/postcss-plugin.js +33 -0
- package/node/deprecations/step-connector-classes/postcss.config.js +8 -0
- package/node/deprecations/step-connector-classes/step-connector-classes.js +77 -0
- package/node/deprecations/step-connector-classes/test-cases/actual.js +7 -0
- package/node/deprecations/step-connector-classes/test-cases/expected.js +7 -0
- package/node/deprecations/step-label-props/step-label-props.js +14 -0
- package/node/deprecations/step-label-props/test-cases/actual.js +23 -0
- package/node/deprecations/step-label-props/test-cases/expected.js +24 -0
- package/node/deprecations/step-label-props/test-cases/theme.actual.js +22 -0
- package/node/deprecations/step-label-props/test-cases/theme.expected.js +25 -0
- package/node/deprecations/toggle-button-group-classes/index.js +13 -0
- package/node/deprecations/toggle-button-group-classes/postcss-plugin.js +33 -0
- package/node/deprecations/toggle-button-group-classes/postcss.config.js +8 -0
- package/node/deprecations/toggle-button-group-classes/test-cases/actual.js +7 -0
- package/node/deprecations/toggle-button-group-classes/test-cases/expected.js +7 -0
- package/node/deprecations/toggle-button-group-classes/toggle-button-group-classes.js +77 -0
- package/node/deprecations/utils/movePropIntoSlotProps.js +111 -0
- package/node/deprecations/utils/movePropIntoSlots.js +101 -0
- package/node/v5.0.0/base-remove-unstyled-suffix.js +4 -4
- package/node/v5.0.0/styled-engine-provider.test/theme-provider.expected.js +3 -3
- package/node/v6.0.0/all/index.js +13 -0
- package/node/v6.0.0/all/postcss.config.js +9 -0
- package/node/v6.0.0/all/v6-all.js +17 -0
- package/node/v6.0.0/styled/index.js +13 -0
- package/node/v6.0.0/styled/styled-v6.js +478 -0
- package/node/v6.0.0/styled/test-cases/BasicStyled.actual.js +54 -0
- package/node/v6.0.0/styled/test-cases/BasicStyled.expected.js +104 -0
- package/node/v6.0.0/styled/test-cases/ConditionalStyled.actual.js +115 -0
- package/node/v6.0.0/styled/test-cases/ConditionalStyled.expected.js +206 -0
- package/node/v6.0.0/styled/test-cases/LogicalStyled.actual.js +28 -0
- package/node/v6.0.0/styled/test-cases/LogicalStyled.expected.js +52 -0
- package/node/v6.0.0/styled/test-cases/NestedSpread.actual.js +42 -0
- package/node/v6.0.0/styled/test-cases/NestedSpread.expected.js +85 -0
- package/node/v6.0.0/styled/test-cases/ObjectMap.actual.js +36 -0
- package/node/v6.0.0/styled/test-cases/ObjectMap.expected.js +109 -0
- package/node/v6.0.0/styled/test-cases/ThemePaletteMode.actual.js +62 -0
- package/node/v6.0.0/styled/test-cases/ThemePaletteMode.expected.js +76 -0
- package/node/v6.0.0/styled/test-cases/VariantAndModeStyled.actual.js +11 -0
- package/node/v6.0.0/styled/test-cases/VariantAndModeStyled.expected.js +19 -0
- package/package.json +8 -8
|
@@ -20,4 +20,26 @@ fn({
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
});
|
|
24
|
+
fn({
|
|
25
|
+
MuiStepLabel: {
|
|
26
|
+
defaultProps: {
|
|
27
|
+
StepIconComponent: StepIconComponent,
|
|
28
|
+
StepIconProps: StepIconProps
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
fn({
|
|
33
|
+
MuiStepLabel: {
|
|
34
|
+
defaultProps: {
|
|
35
|
+
componentsProps: {
|
|
36
|
+
label: componentsLabelProps
|
|
37
|
+
},
|
|
38
|
+
slotProps: {
|
|
39
|
+
label: slotLabelProps
|
|
40
|
+
},
|
|
41
|
+
StepIconComponent: StepIconComponent,
|
|
42
|
+
StepIconProps: StepIconProps
|
|
43
|
+
}
|
|
44
|
+
}
|
|
23
45
|
});
|
|
@@ -19,4 +19,29 @@ fn({
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
});
|
|
23
|
+
fn({
|
|
24
|
+
MuiStepLabel: {
|
|
25
|
+
defaultProps: {
|
|
26
|
+
slots: {
|
|
27
|
+
stepIcon: StepIconComponent
|
|
28
|
+
},
|
|
29
|
+
slotProps: {
|
|
30
|
+
stepIcon: StepIconProps
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
fn({
|
|
36
|
+
MuiStepLabel: {
|
|
37
|
+
defaultProps: {
|
|
38
|
+
slotProps: {
|
|
39
|
+
label: (0, _extends2.default)({}, componentsLabelProps, slotLabelProps),
|
|
40
|
+
stepIcon: StepIconProps
|
|
41
|
+
},
|
|
42
|
+
slots: {
|
|
43
|
+
stepIcon: StepIconComponent
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
22
47
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "default", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _toggleButtonGroupClasses.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _toggleButtonGroupClasses = _interopRequireDefault(require("./toggle-button-group-classes"));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const classes = [{
|
|
4
|
+
deprecatedClass: ' .MuiToggleButtonGroup-groupedHorizontal',
|
|
5
|
+
replacementSelector: '.MuiToggleButtonGroup-horizontal > .MuiToggleButtonGroup-grouped'
|
|
6
|
+
}, {
|
|
7
|
+
deprecatedClass: ' .MuiToggleButtonGroup-groupedVertical',
|
|
8
|
+
replacementSelector: '.MuiToggleButtonGroup-vertical > .MuiToggleButtonGroup-grouped'
|
|
9
|
+
}];
|
|
10
|
+
const plugin = () => {
|
|
11
|
+
return {
|
|
12
|
+
postcssPlugin: `Replace deperecated ToggleButtonGroup classes with new classes`,
|
|
13
|
+
Rule(rule) {
|
|
14
|
+
const {
|
|
15
|
+
selector
|
|
16
|
+
} = rule;
|
|
17
|
+
classes.forEach(({
|
|
18
|
+
deprecatedClass,
|
|
19
|
+
replacementSelector
|
|
20
|
+
}) => {
|
|
21
|
+
const selectorRegex = new RegExp(`${deprecatedClass}$`);
|
|
22
|
+
if (selector.match(selectorRegex)) {
|
|
23
|
+
rule.selector = selector.replace(selectorRegex, replacementSelector);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
plugin.postcss = true;
|
|
30
|
+
module.exports = {
|
|
31
|
+
plugin,
|
|
32
|
+
classes
|
|
33
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _ToggleButtonGroup = require("@mui/material/ToggleButtonGroup");
|
|
4
|
+
'& .MuiToggleButtonGroup-groupedHorizontal';
|
|
5
|
+
'& .MuiToggleButtonGroup-groupedVertical';
|
|
6
|
+
`& .${_ToggleButtonGroup.toggleButtonGroupClasses.groupedHorizontal}`;
|
|
7
|
+
`& .${_ToggleButtonGroup.toggleButtonGroupClasses.groupedVertical}`;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _ToggleButtonGroup = require("@mui/material/ToggleButtonGroup");
|
|
4
|
+
"&.MuiToggleButtonGroup-horizontal > .MuiToggleButtonGroup-grouped";
|
|
5
|
+
"&.MuiToggleButtonGroup-vertical > .MuiToggleButtonGroup-grouped";
|
|
6
|
+
`&.${_ToggleButtonGroup.toggleButtonGroupClasses.horizontal} > .${_ToggleButtonGroup.toggleButtonGroupClasses.grouped}`;
|
|
7
|
+
`&.${_ToggleButtonGroup.toggleButtonGroupClasses.vertical} > .${_ToggleButtonGroup.toggleButtonGroupClasses.grouped}`;
|
|
@@ -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\/ToggleButtonGroup$/)).forEach(path => {
|
|
22
|
+
path.node.specifiers.forEach(specifier => {
|
|
23
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'toggleButtonGroupClasses') {
|
|
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('MuiToggleButtonGroup-', '').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), 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,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = movePropIntoSlotProps;
|
|
8
|
+
var _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
|
|
9
|
+
var _findComponentDefaultProps = _interopRequireDefault(require("../../util/findComponentDefaultProps"));
|
|
10
|
+
var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
|
|
11
|
+
var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
|
|
12
|
+
function moveJsxPropIntoSlotProps(j, element, propName, slotName) {
|
|
13
|
+
const propIndex = element.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === propName);
|
|
14
|
+
if (propIndex !== -1) {
|
|
15
|
+
const removedValue = element.openingElement.attributes.splice(propIndex, 1)[0].value.expression;
|
|
16
|
+
let hasSlotProps = false;
|
|
17
|
+
element.openingElement.attributes.forEach(attr => {
|
|
18
|
+
var _attr$name;
|
|
19
|
+
if (((_attr$name = attr.name) == null ? void 0 : _attr$name.name) === 'slotProps') {
|
|
20
|
+
hasSlotProps = true;
|
|
21
|
+
const slots = attr.value.expression;
|
|
22
|
+
const slotIndex = slots.properties.findIndex(prop => {
|
|
23
|
+
var _prop$key;
|
|
24
|
+
return (prop == null || (_prop$key = prop.key) == null ? void 0 : _prop$key.name) === slotName;
|
|
25
|
+
});
|
|
26
|
+
if (slotIndex === -1) {
|
|
27
|
+
(0, _assignObject.default)(j, {
|
|
28
|
+
target: attr,
|
|
29
|
+
key: slotName,
|
|
30
|
+
expression: removedValue
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
const slotPropsSlotValue = slots.properties.splice(slotIndex, 1)[0].value;
|
|
34
|
+
(0, _assignObject.default)(j, {
|
|
35
|
+
target: attr,
|
|
36
|
+
key: slotName,
|
|
37
|
+
expression: j.objectExpression([j.spreadElement(removedValue), j.spreadElement(slotPropsSlotValue)])
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (!hasSlotProps) {
|
|
43
|
+
(0, _appendAttribute.default)(j, {
|
|
44
|
+
target: element,
|
|
45
|
+
attributeName: 'slotProps',
|
|
46
|
+
expression: j.objectExpression([j.objectProperty(j.identifier(slotName), removedValue)])
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function moveDefaultPropsPropIntoslotProps(j, defaultPropsPathCollection, propName, slotName) {
|
|
52
|
+
defaultPropsPathCollection.find(j.ObjectProperty, {
|
|
53
|
+
key: {
|
|
54
|
+
name: propName
|
|
55
|
+
}
|
|
56
|
+
}).forEach(path => {
|
|
57
|
+
const removedValue = path.value.value;
|
|
58
|
+
const defaultProps = path.parent.value;
|
|
59
|
+
let hasSlotProps = false;
|
|
60
|
+
defaultProps.properties.forEach(property => {
|
|
61
|
+
var _property$key;
|
|
62
|
+
if (((_property$key = property.key) == null ? void 0 : _property$key.name) === 'slotProps') {
|
|
63
|
+
hasSlotProps = true;
|
|
64
|
+
const slotIndex = property.value.properties.findIndex(prop => {
|
|
65
|
+
var _prop$key2;
|
|
66
|
+
return (prop == null || (_prop$key2 = prop.key) == null ? void 0 : _prop$key2.name) === slotName;
|
|
67
|
+
});
|
|
68
|
+
if (slotIndex === -1) {
|
|
69
|
+
property.value.properties.push(j.objectProperty(j.identifier(slotName), removedValue));
|
|
70
|
+
} else {
|
|
71
|
+
const slotPropsSlotValue = property.value.properties.splice(slotIndex, 1)[0].value;
|
|
72
|
+
property.value.properties.push(j.objectProperty(j.identifier(slotName), j.objectExpression([j.spreadElement(removedValue), j.spreadElement(slotPropsSlotValue)])));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (!hasSlotProps) {
|
|
77
|
+
defaultProps.properties.push(j.objectProperty(j.identifier('slotProps'), j.objectExpression([j.objectProperty(j.identifier(slotName), removedValue)])));
|
|
78
|
+
}
|
|
79
|
+
path.prune();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Moves prop into slotProps.
|
|
85
|
+
* If the slotProps prop exists, it will merge the prop into the slotProps.
|
|
86
|
+
* If there are duplicated values, the values will be spread.
|
|
87
|
+
*
|
|
88
|
+
* @param {import('jscodeshift')} j
|
|
89
|
+
* @param {{ root: import('jscodeshift').Collection; componentName: string, propName: string, slotName: string }} options
|
|
90
|
+
*
|
|
91
|
+
* @example <Component TransitionProps={value} /> => <Component slotProps={{ transition: value }} />
|
|
92
|
+
*/
|
|
93
|
+
function movePropIntoSlotProps(j, options) {
|
|
94
|
+
const {
|
|
95
|
+
root,
|
|
96
|
+
componentName,
|
|
97
|
+
propName,
|
|
98
|
+
slotName
|
|
99
|
+
} = options;
|
|
100
|
+
(0, _findComponentJSX.default)(j, {
|
|
101
|
+
root,
|
|
102
|
+
componentName
|
|
103
|
+
}, elementPath => {
|
|
104
|
+
moveJsxPropIntoSlotProps(j, elementPath.node, propName, slotName);
|
|
105
|
+
});
|
|
106
|
+
const defaultPropsPathCollection = (0, _findComponentDefaultProps.default)(j, {
|
|
107
|
+
root,
|
|
108
|
+
componentName
|
|
109
|
+
});
|
|
110
|
+
moveDefaultPropsPropIntoslotProps(j, defaultPropsPathCollection, propName, slotName);
|
|
111
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = movePropIntoSlots;
|
|
8
|
+
var _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
|
|
9
|
+
var _findComponentDefaultProps = _interopRequireDefault(require("../../util/findComponentDefaultProps"));
|
|
10
|
+
var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
|
|
11
|
+
var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
|
|
12
|
+
function moveJsxPropIntoSlots(j, element, propName, slotName) {
|
|
13
|
+
const index = element.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === propName);
|
|
14
|
+
if (index !== -1) {
|
|
15
|
+
const removedValue = element.openingElement.attributes.splice(index, 1)[0].value.expression;
|
|
16
|
+
let hasSlots = false;
|
|
17
|
+
element.openingElement.attributes.forEach(attr => {
|
|
18
|
+
var _attr$name;
|
|
19
|
+
if (((_attr$name = attr.name) == null ? void 0 : _attr$name.name) === 'slots') {
|
|
20
|
+
hasSlots = true;
|
|
21
|
+
const slotIndex = attr.value.expression.properties.findIndex(prop => {
|
|
22
|
+
var _prop$key;
|
|
23
|
+
return (prop == null || (_prop$key = prop.key) == null ? void 0 : _prop$key.name) === slotName;
|
|
24
|
+
});
|
|
25
|
+
if (slotIndex === -1) {
|
|
26
|
+
(0, _assignObject.default)(j, {
|
|
27
|
+
target: attr,
|
|
28
|
+
key: slotName,
|
|
29
|
+
expression: removedValue
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (!hasSlots) {
|
|
35
|
+
(0, _appendAttribute.default)(j, {
|
|
36
|
+
target: element,
|
|
37
|
+
attributeName: 'slots',
|
|
38
|
+
expression: j.objectExpression([j.objectProperty(j.identifier(slotName), removedValue)])
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function moveDefaultPropsPropIntoSlots(j, defaultPropsPathCollection, propName, slotName) {
|
|
44
|
+
defaultPropsPathCollection.find(j.ObjectProperty, {
|
|
45
|
+
key: {
|
|
46
|
+
name: propName
|
|
47
|
+
}
|
|
48
|
+
}).forEach(path => {
|
|
49
|
+
const removedValue = path.value.value;
|
|
50
|
+
const defaultProps = path.parent.value;
|
|
51
|
+
let hasSlots = false;
|
|
52
|
+
defaultProps.properties.forEach(property => {
|
|
53
|
+
var _property$key;
|
|
54
|
+
if (((_property$key = property.key) == null ? void 0 : _property$key.name) === 'slots') {
|
|
55
|
+
hasSlots = true;
|
|
56
|
+
const slots = property.value;
|
|
57
|
+
const slotIndex = slots.properties.findIndex(prop => {
|
|
58
|
+
var _prop$key2;
|
|
59
|
+
return (prop == null || (_prop$key2 = prop.key) == null ? void 0 : _prop$key2.name) === slotName;
|
|
60
|
+
});
|
|
61
|
+
if (slotIndex === -1) {
|
|
62
|
+
slots.properties.push(j.objectProperty(j.identifier(slotName), removedValue));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (!hasSlots) {
|
|
67
|
+
defaultProps.properties.push(j.property('init', j.identifier('slots'), j.objectExpression([j.objectProperty(j.identifier(slotName), removedValue)])));
|
|
68
|
+
}
|
|
69
|
+
path.prune();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Moves prop into slots.
|
|
75
|
+
* If the slots prop exists, it will add the prop to the slots.
|
|
76
|
+
* If there are duplicated values, the slots values will be used.
|
|
77
|
+
*
|
|
78
|
+
* @param {import('jscodeshift')} j
|
|
79
|
+
* @param {{ root: import('jscodeshift').Collection; componentName: string, propName: string, slotName: string }} options
|
|
80
|
+
*
|
|
81
|
+
* @example <Component TransitionComponent={CustomTransition} /> => <Component slots={{ transition: CustomTransition }} />
|
|
82
|
+
*/
|
|
83
|
+
function movePropIntoSlots(j, options) {
|
|
84
|
+
const {
|
|
85
|
+
root,
|
|
86
|
+
componentName,
|
|
87
|
+
propName,
|
|
88
|
+
slotName
|
|
89
|
+
} = options;
|
|
90
|
+
(0, _findComponentJSX.default)(j, {
|
|
91
|
+
root,
|
|
92
|
+
componentName
|
|
93
|
+
}, elementPath => {
|
|
94
|
+
moveJsxPropIntoSlots(j, elementPath.node, propName, slotName);
|
|
95
|
+
});
|
|
96
|
+
const defaultPropsPathCollection = (0, _findComponentDefaultProps.default)(j, {
|
|
97
|
+
root,
|
|
98
|
+
componentName
|
|
99
|
+
});
|
|
100
|
+
moveDefaultPropsPropIntoSlots(j, defaultPropsPathCollection, propName, slotName);
|
|
101
|
+
}
|
|
@@ -15,12 +15,12 @@ function transformer(file, api) {
|
|
|
15
15
|
node
|
|
16
16
|
}) => {
|
|
17
17
|
const sourceVal = node.source.value;
|
|
18
|
-
if (sourceVal.startsWith('@mui/base')) {
|
|
19
|
-
node.source.value = sourceVal.replace(/unstyled/im, '');
|
|
20
|
-
node.source.raw = sourceVal.replace(/unstyled/im, '');
|
|
21
|
-
}
|
|
22
18
|
return sourceVal.startsWith('@mui/base');
|
|
23
19
|
}).forEach(path => {
|
|
20
|
+
const sourceVal = path.node.source.value;
|
|
21
|
+
if (sourceVal.startsWith('@mui/base')) {
|
|
22
|
+
path.node.source = j.stringLiteral(sourceVal.replace(/unstyled/im, ''));
|
|
23
|
+
}
|
|
24
24
|
const specifiers = [];
|
|
25
25
|
path.node.specifiers.forEach(elementNode => {
|
|
26
26
|
var _elementNode$imported;
|
|
@@ -14,14 +14,14 @@ var _OtherProvider;
|
|
|
14
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
16
|
const App = () => {
|
|
17
|
-
return /*#__PURE__*/(0, _jsxRuntime.
|
|
17
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.StyledEngineProvider, {
|
|
18
18
|
injectFirst: true,
|
|
19
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.ThemeProvider, {
|
|
19
|
+
children: ["(", /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.ThemeProvider, {
|
|
20
20
|
theme: (0, _styles.createTheme)(),
|
|
21
21
|
children: _OtherProvider || (_OtherProvider = /*#__PURE__*/(0, _jsxRuntime.jsx)(_contexts.OtherProvider, {
|
|
22
22
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_pages.default, {})
|
|
23
23
|
}))
|
|
24
|
-
})
|
|
24
|
+
}), ")"]
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
27
|
var _default = exports.default = App;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "default", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _v6All.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _v6All = _interopRequireDefault(require("./v6-all"));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = v6All;
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
9
|
+
* @param {import('jscodeshift').API} api
|
|
10
|
+
*/
|
|
11
|
+
function v6All(file) {
|
|
12
|
+
// Currently empty, when adding the first codemod:
|
|
13
|
+
// - Read mui-codemod/CONTRIBUTING.md
|
|
14
|
+
// - Follow mui-codemod/src/deprecations/all/deprecations-all.js as a guide
|
|
15
|
+
// - Remove this comment
|
|
16
|
+
return file.source;
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "default", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _styledV.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _styledV = _interopRequireDefault(require("./styled-v6"));
|