@mui/codemod 6.0.0-alpha.11 → 6.0.0-alpha.14
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 +285 -180
- package/node/deprecations/all/deprecations-all.js +4 -0
- package/node/deprecations/all/postcss.config.js +7 -1
- package/node/deprecations/tab-classes/index.js +13 -0
- package/node/deprecations/tab-classes/postcss-plugin.js +30 -0
- package/node/deprecations/tab-classes/postcss.config.js +8 -0
- package/node/deprecations/tab-classes/tab-classes.js +53 -0
- package/node/deprecations/tab-classes/test-cases/actual.js +5 -0
- package/node/deprecations/tab-classes/test-cases/expected.js +5 -0
- package/node/deprecations/table-sort-label-classes/index.js +13 -0
- package/node/deprecations/table-sort-label-classes/postcss-plugin.js +33 -0
- package/node/deprecations/table-sort-label-classes/postcss.config.js +8 -0
- package/node/deprecations/table-sort-label-classes/table-sort-label-classes.js +77 -0
- package/node/deprecations/table-sort-label-classes/test-cases/actual.js +7 -0
- package/node/deprecations/table-sort-label-classes/test-cases/expected.js +7 -0
- package/node/util/migrateToVariants.js +47 -36
- package/node/v5.0.0/theme-spacing.test/large-actual.js +1 -1
- package/node/v5.0.0/theme-spacing.test/large-expected.js +1 -1
- package/node/v6.0.0/grid-v2-props/grid-v2-props.js +149 -0
- package/node/v6.0.0/grid-v2-props/index.js +13 -0
- package/node/v6.0.0/grid-v2-props/test-cases/actual.js +85 -0
- package/node/v6.0.0/grid-v2-props/test-cases/custom-breakpoints.actual.js +18 -0
- package/node/v6.0.0/grid-v2-props/test-cases/custom-breakpoints.expected.js +22 -0
- package/node/v6.0.0/grid-v2-props/test-cases/expected.js +97 -0
- package/node/v6.0.0/styled/test-cases/ConditionalStyled.expected.js +9 -22
- package/node/v6.0.0/styled/test-cases/DynamicPropsStyled.actual.js +39 -0
- package/node/v6.0.0/styled/test-cases/DynamicPropsStyled.expected.js +65 -0
- package/node/v6.0.0/styled/test-cases/NestedSpread.expected.js +11 -13
- package/package.json +3 -3
|
@@ -26,9 +26,11 @@ var _modalProps = _interopRequireDefault(require("../modal-props"));
|
|
|
26
26
|
var _outlinedInputProps = _interopRequireDefault(require("../outlined-input-props"));
|
|
27
27
|
var _paginationItemClasses = _interopRequireDefault(require("../pagination-item-classes"));
|
|
28
28
|
var _speedDialProps = _interopRequireDefault(require("../speed-dial-props"));
|
|
29
|
+
var _tableSortLabelClasses = _interopRequireDefault(require("../table-sort-label-classes"));
|
|
29
30
|
var _stepConnectorClasses = _interopRequireDefault(require("../step-connector-classes"));
|
|
30
31
|
var _stepLabelProps = _interopRequireDefault(require("../step-label-props"));
|
|
31
32
|
var _textFieldProps = _interopRequireDefault(require("../text-field-props"));
|
|
33
|
+
var _tabClasses = _interopRequireDefault(require("../tab-classes"));
|
|
32
34
|
var _toggleButtonGroupClasses = _interopRequireDefault(require("../toggle-button-group-classes"));
|
|
33
35
|
/**
|
|
34
36
|
* @param {import('jscodeshift').FileInfo} file
|
|
@@ -58,7 +60,9 @@ function deprecationsAll(file, api, options) {
|
|
|
58
60
|
file.source = (0, _speedDialProps.default)(file, api, options);
|
|
59
61
|
file.source = (0, _stepConnectorClasses.default)(file, api, options);
|
|
60
62
|
file.source = (0, _stepLabelProps.default)(file, api, options);
|
|
63
|
+
file.source = (0, _tableSortLabelClasses.default)(file, api, options);
|
|
61
64
|
file.source = (0, _textFieldProps.default)(file, api, options);
|
|
65
|
+
file.source = (0, _tabClasses.default)(file, api, options);
|
|
62
66
|
file.source = (0, _toggleButtonGroupClasses.default)(file, api, options);
|
|
63
67
|
return file.source;
|
|
64
68
|
}
|
|
@@ -27,6 +27,12 @@ const {
|
|
|
27
27
|
const {
|
|
28
28
|
plugin: circularProgressClassesPlugin
|
|
29
29
|
} = require('../circular-progress-classes/postcss-plugin');
|
|
30
|
+
const {
|
|
31
|
+
plugin: tabClassesPlugin
|
|
32
|
+
} = require('../tab-classes/postcss-plugin');
|
|
33
|
+
const {
|
|
34
|
+
plugin: tableSortLabelClassesPlugin
|
|
35
|
+
} = require('../table-sort-label-classes/postcss-plugin');
|
|
30
36
|
module.exports = {
|
|
31
|
-
plugins: [accordionSummaryClassesPlugin, alertClassesPlugin, buttonClassesPlugin, buttonGroupClassesPlugin, chipClassesPlugin, circularProgressClassesPlugin, paginationItemClassesPlugin, stepConnectorClassesPlugin, toggleButtonGroupClassesPlugin]
|
|
37
|
+
plugins: [accordionSummaryClassesPlugin, alertClassesPlugin, buttonClassesPlugin, buttonGroupClassesPlugin, chipClassesPlugin, circularProgressClassesPlugin, paginationItemClassesPlugin, stepConnectorClassesPlugin, toggleButtonGroupClassesPlugin, tabClassesPlugin, tableSortLabelClassesPlugin]
|
|
32
38
|
};
|
|
@@ -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 _tabClasses.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _tabClasses = _interopRequireDefault(require("./tab-classes"));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const classes = [{
|
|
4
|
+
deprecatedClass: ' .MuiTab-iconWrapper',
|
|
5
|
+
replacementSelector: ' .MuiTab-icon'
|
|
6
|
+
}];
|
|
7
|
+
const plugin = () => {
|
|
8
|
+
return {
|
|
9
|
+
postcssPlugin: `Replace deprecated Tab classes with new classes`,
|
|
10
|
+
Rule(rule) {
|
|
11
|
+
const {
|
|
12
|
+
selector
|
|
13
|
+
} = rule;
|
|
14
|
+
classes.forEach(({
|
|
15
|
+
deprecatedClass,
|
|
16
|
+
replacementSelector
|
|
17
|
+
}) => {
|
|
18
|
+
const selectorRegex = new RegExp(`${deprecatedClass}$`);
|
|
19
|
+
if (selector.match(selectorRegex)) {
|
|
20
|
+
rule.selector = selector.replace(selectorRegex, replacementSelector);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
plugin.postcss = true;
|
|
27
|
+
module.exports = {
|
|
28
|
+
plugin,
|
|
29
|
+
classes
|
|
30
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
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\/Tab$/)).forEach(path => {
|
|
22
|
+
path.node.specifiers.forEach(specifier => {
|
|
23
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'tabClasses') {
|
|
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 = ['icon'];
|
|
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
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
const selectorRegex = new RegExp(`${replacementSelectorPrefix}${deprecatedClass}$`);
|
|
48
|
+
root.find(j.Literal, literal => typeof literal.value === 'string' && literal.value.match(selectorRegex)).forEach(path => {
|
|
49
|
+
path.replace(j.literal(path.value.value.replace(selectorRegex, `${replacementSelectorPrefix}${replacementSelector}`)));
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
return root.toSource(printOptions);
|
|
53
|
+
}
|
|
@@ -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 _tableSortLabelClasses.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _tableSortLabelClasses = _interopRequireDefault(require("./table-sort-label-classes"));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const classes = [{
|
|
4
|
+
deprecatedClass: ' .MuiTableSortLabel-iconDirectionDesc',
|
|
5
|
+
replacementSelector: '.MuiTableSortLabel-directionDesc > .MuiTableSortLabel-icon'
|
|
6
|
+
}, {
|
|
7
|
+
deprecatedClass: ' .MuiTableSortLabel-iconDirectionAsc',
|
|
8
|
+
replacementSelector: '.MuiTableSortLabel-directionAsc > .MuiTableSortLabel-icon'
|
|
9
|
+
}];
|
|
10
|
+
const plugin = () => {
|
|
11
|
+
return {
|
|
12
|
+
postcssPlugin: `Replace deprecated TableSortLabel 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,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\/TableSortLabel$/)).forEach(path => {
|
|
22
|
+
path.node.specifiers.forEach(specifier => {
|
|
23
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'tableSortLabelClasses') {
|
|
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('MuiTableSortLabel-', '').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,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _TableSortLabel = require("@mui/material/TableSortLabel");
|
|
4
|
+
'& .MuiTableSortLabel-iconDirectionDesc';
|
|
5
|
+
'& .MuiTableSortLabel-iconDirectionAsc';
|
|
6
|
+
`& .${_TableSortLabel.tableSortLabelClasses.iconDirectionDesc}`;
|
|
7
|
+
`& .${_TableSortLabel.tableSortLabelClasses.iconDirectionAsc}`;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _TableSortLabel = require("@mui/material/TableSortLabel");
|
|
4
|
+
"&.MuiTableSortLabel-directionDesc > .MuiTableSortLabel-icon";
|
|
5
|
+
"&.MuiTableSortLabel-directionAsc > .MuiTableSortLabel-icon";
|
|
6
|
+
`&.${_TableSortLabel.tableSortLabelClasses.directionDesc} > .${_TableSortLabel.tableSortLabelClasses.icon}`;
|
|
7
|
+
`&.${_TableSortLabel.tableSortLabelClasses.directionAsc} > .${_TableSortLabel.tableSortLabelClasses.icon}`;
|
|
@@ -331,25 +331,32 @@ function migrateToVariants(j, styles) {
|
|
|
331
331
|
} else if (style.body.type === 'ConditionalExpression') {
|
|
332
332
|
// skip ConditionalExpression
|
|
333
333
|
} else {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
objectExpression = objectExpression.body.find(item => item.type === 'ReturnStatement').argument;
|
|
340
|
-
}
|
|
334
|
+
const expressions = [];
|
|
335
|
+
if (style.body.type === 'ArrayExpression') {
|
|
336
|
+
expressions.push(...style.body.elements);
|
|
337
|
+
} else {
|
|
338
|
+
expressions.push(style.body);
|
|
341
339
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
340
|
+
expressions.forEach(objectExpression => {
|
|
341
|
+
let counter = 0;
|
|
342
|
+
while (objectExpression.type !== 'ObjectExpression' && counter < MAX_DEPTH) {
|
|
343
|
+
counter += 1;
|
|
344
|
+
if (objectExpression.type === 'BlockStatement') {
|
|
345
|
+
objectExpression = objectExpression.body.find(item => item.type === 'ReturnStatement').argument;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
recurseObjectExpression({
|
|
349
|
+
node: objectExpression,
|
|
350
|
+
buildStyle: createBuildStyle()
|
|
351
|
+
});
|
|
352
|
+
if (variants.length && objectExpression.type === 'ObjectExpression') {
|
|
353
|
+
objectExpression.properties.push(j.objectProperty(j.identifier('variants'), j.arrayExpression(variants.filter(variant => {
|
|
354
|
+
const props = variant.properties.find(prop => prop.key.name === 'props');
|
|
355
|
+
const styleVal = variant.properties.find(prop => prop.key.name === 'style');
|
|
356
|
+
return props && styleVal && (!styleVal.value.properties || styleVal.value.properties.length > 0) && (props.value.type === 'ArrowFunctionExpression' || props.value.properties.length > 0);
|
|
357
|
+
}))));
|
|
358
|
+
}
|
|
345
359
|
});
|
|
346
|
-
if (variants.length) {
|
|
347
|
-
objectExpression.properties.push(j.objectProperty(j.identifier('variants'), j.arrayExpression(variants.filter(variant => {
|
|
348
|
-
const props = variant.properties.find(prop => prop.key.name === 'props');
|
|
349
|
-
const styleVal = variant.properties.find(prop => prop.key.name === 'style');
|
|
350
|
-
return props && styleVal && (!styleVal.value.properties || styleVal.value.properties.length > 0) && (props.value.type === 'ArrowFunctionExpression' || props.value.properties.length > 0);
|
|
351
|
-
}))));
|
|
352
|
-
}
|
|
353
360
|
}
|
|
354
361
|
function recurseObjectExpression(data) {
|
|
355
362
|
if (data.node.type === 'ObjectExpression') {
|
|
@@ -477,7 +484,6 @@ function migrateToVariants(j, styles) {
|
|
|
477
484
|
leftName = (_getObjectKey5 = getObjectKey(data.node.test.argument)) == null ? void 0 : _getObjectKey5.name;
|
|
478
485
|
}
|
|
479
486
|
if (parameters.has(leftName) && leftName !== 'theme') {
|
|
480
|
-
var _data$parentNode;
|
|
481
487
|
let props = buildProps(data.node.test);
|
|
482
488
|
if (data.props) {
|
|
483
489
|
props = mergeProps(data.props, props);
|
|
@@ -488,32 +494,37 @@ function migrateToVariants(j, styles) {
|
|
|
488
494
|
style: styleVal
|
|
489
495
|
};
|
|
490
496
|
variants.push(buildObjectAST(variant));
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
497
|
+
if (data.node.consequent.type === 'ObjectExpression' && data.node.alternate.type === 'ObjectExpression') {
|
|
498
|
+
var _data$parentNode;
|
|
499
|
+
// create another variant with inverted condition
|
|
500
|
+
let props2 = buildProps(inverseBinaryExpression(data.node.test));
|
|
501
|
+
if (data.props) {
|
|
502
|
+
props2 = mergeProps(data.props, props2);
|
|
503
|
+
}
|
|
504
|
+
const styleVal2 = data.buildStyle(data.node.alternate);
|
|
505
|
+
const variant2 = {
|
|
506
|
+
props: props2,
|
|
507
|
+
style: styleVal2
|
|
508
|
+
};
|
|
509
|
+
variants.push(buildObjectAST(variant2));
|
|
510
|
+
if (((_data$parentNode = data.parentNode) == null ? void 0 : _data$parentNode.type) === 'ObjectExpression') {
|
|
511
|
+
removeProperty(data.parentNode, data.node);
|
|
512
|
+
}
|
|
513
|
+
} else {
|
|
514
|
+
var _data$replaceValue;
|
|
515
|
+
(_data$replaceValue = data.replaceValue) == null || _data$replaceValue.call(data, data.node.alternate);
|
|
505
516
|
}
|
|
506
517
|
}
|
|
507
518
|
if (leftName === 'theme' && ((_data$parentNode2 = data.parentNode) == null ? void 0 : _data$parentNode2.type) === 'ObjectExpression' && ((_data$node$test = data.node.test) == null ? void 0 : _data$node$test.type) === 'BinaryExpression' && isThemePaletteMode(data.node.test.left)) {
|
|
508
519
|
if (data.node.consequent.type !== 'ObjectExpression' && data.node.alternate.type !== 'ObjectExpression') {
|
|
509
|
-
var _data$
|
|
520
|
+
var _data$replaceValue2;
|
|
510
521
|
if (data.modeStyles) {
|
|
511
522
|
if (!data.modeStyles[data.node.test.right.value]) {
|
|
512
523
|
data.modeStyles[data.node.test.right.value] = [];
|
|
513
524
|
}
|
|
514
525
|
data.modeStyles[data.node.test.right.value].push(j.objectProperty(data.key, data.node.consequent));
|
|
515
526
|
}
|
|
516
|
-
(_data$
|
|
527
|
+
(_data$replaceValue2 = data.replaceValue) == null || _data$replaceValue2.call(data, data.node.alternate);
|
|
517
528
|
}
|
|
518
529
|
}
|
|
519
530
|
}
|
|
@@ -549,10 +560,10 @@ function migrateToVariants(j, styles) {
|
|
|
549
560
|
data.modeStyles[mode].push(j.objectProperty(data.key, clonedNode));
|
|
550
561
|
});
|
|
551
562
|
if (data.key) {
|
|
552
|
-
var _data$
|
|
563
|
+
var _data$replaceValue3;
|
|
553
564
|
// to remove the arrow function
|
|
554
565
|
// { ...: theme => `1px solid...` } to { ...: `1px solid...` }
|
|
555
|
-
(_data$
|
|
566
|
+
(_data$replaceValue3 = data.replaceValue) == null || _data$replaceValue3.call(data, data.node);
|
|
556
567
|
}
|
|
557
568
|
}
|
|
558
569
|
}
|
|
@@ -24,7 +24,7 @@ var _GlobalStyles = _interopRequireDefault(require("@mui/material/GlobalStyles")
|
|
|
24
24
|
var _styles = require("@mui/material/styles");
|
|
25
25
|
var _config = require("docs/config");
|
|
26
26
|
var _Link = _interopRequireDefault(require("docs/src/modules/components/Link"));
|
|
27
|
-
var _i18n = require("docs/
|
|
27
|
+
var _i18n = require("@mui/docs/i18n");
|
|
28
28
|
var _useLazyCSS = _interopRequireDefault(require("docs/src/modules/utils/useLazyCSS"));
|
|
29
29
|
var _getUrlProduct = _interopRequireDefault(require("docs/src/modules/utils/getUrlProduct"));
|
|
30
30
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -24,7 +24,7 @@ var _GlobalStyles = _interopRequireDefault(require("@mui/material/GlobalStyles")
|
|
|
24
24
|
var _styles = require("@mui/material/styles");
|
|
25
25
|
var _config = require("docs/config");
|
|
26
26
|
var _Link = _interopRequireDefault(require("docs/src/modules/components/Link"));
|
|
27
|
-
var _i18n = require("docs/
|
|
27
|
+
var _i18n = require("@mui/docs/i18n");
|
|
28
28
|
var _useLazyCSS = _interopRequireDefault(require("docs/src/modules/utils/useLazyCSS"));
|
|
29
29
|
var _getUrlProduct = _interopRequireDefault(require("docs/src/modules/utils/getUrlProduct"));
|
|
30
30
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = gridV2Props;
|
|
7
|
+
const possibleDefaultImports = ['@mui/material/Unstable_Grid2', '@mui/system/Unstable_Grid', '@mui/joy/Grid'];
|
|
8
|
+
const possibleNamedImports = {
|
|
9
|
+
'@mui/material': 'Unstable_Grid2',
|
|
10
|
+
'@mui/system': 'Unstable_Grid',
|
|
11
|
+
'@mui/joy': 'Grid'
|
|
12
|
+
};
|
|
13
|
+
const defaultBreakpoints = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
17
|
+
* @param {import('jscodeshift').API} api
|
|
18
|
+
*/
|
|
19
|
+
function gridV2Props(file, api, options) {
|
|
20
|
+
var _file$path, _file$path2, _options$muiBreakpoin;
|
|
21
|
+
if ((_file$path = file.path) != null && _file$path.endsWith('.json') || (_file$path2 = file.path) != null && _file$path2.endsWith('.d.ts')) {
|
|
22
|
+
return file.source;
|
|
23
|
+
}
|
|
24
|
+
const j = api.jscodeshift;
|
|
25
|
+
const root = j(file.source);
|
|
26
|
+
const breakpoints = ((_options$muiBreakpoin = options.muiBreakpoints) == null ? void 0 : _options$muiBreakpoin.split(',')) || defaultBreakpoints;
|
|
27
|
+
const printOptions = options.printOptions;
|
|
28
|
+
const gridLocalNames = [];
|
|
29
|
+
root.find(j.ImportDeclaration, decl => possibleDefaultImports.includes(decl.source.value)).forEach(decl => {
|
|
30
|
+
decl.node.specifiers.forEach(spec => {
|
|
31
|
+
if (spec.type === 'ImportDefaultSpecifier') {
|
|
32
|
+
gridLocalNames.push(spec.local.name);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
root.find(j.ImportDeclaration, decl => Object.keys(possibleNamedImports).includes(decl.source.value)).forEach(decl => {
|
|
37
|
+
decl.node.specifiers.forEach(spec => {
|
|
38
|
+
if (spec.type === 'ImportSpecifier') {
|
|
39
|
+
if (possibleNamedImports[decl.node.source.value] === spec.imported.name) {
|
|
40
|
+
gridLocalNames.push(spec.local.name);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
root.find(j.JSXElement, {
|
|
46
|
+
openingElement: {
|
|
47
|
+
name: {
|
|
48
|
+
name: name => gridLocalNames.includes(name)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}).forEach(el => {
|
|
52
|
+
const size = j.objectExpression([]);
|
|
53
|
+
const spreadProps = [];
|
|
54
|
+
const attributesToPrune = [];
|
|
55
|
+
el.node.openingElement.attributes.forEach(attr => {
|
|
56
|
+
if (attr.type === 'JSXSpreadAttribute') {
|
|
57
|
+
spreadProps.push(attr);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const breakpointNodes = j(el).find(j.JSXAttribute).filter(path => path.parent.parent.node === el.node && breakpoints.includes(path.node.name.name));
|
|
61
|
+
breakpointNodes.nodes().forEach(node => {
|
|
62
|
+
const breakpoint = node.name.name;
|
|
63
|
+
const nodeValue = node.value;
|
|
64
|
+
let value;
|
|
65
|
+
if (nodeValue === null) {
|
|
66
|
+
value = j.stringLiteral('grow');
|
|
67
|
+
} else if (nodeValue.type === 'JSXExpressionContainer') {
|
|
68
|
+
if (nodeValue.expression.value === true) {
|
|
69
|
+
value = j.stringLiteral('grow');
|
|
70
|
+
} else {
|
|
71
|
+
value = nodeValue.expression;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
value = nodeValue;
|
|
75
|
+
}
|
|
76
|
+
size.properties.push(j.property('init', j.identifier(breakpoint), value));
|
|
77
|
+
});
|
|
78
|
+
spreadProps.forEach(spreadProp => {
|
|
79
|
+
const spreadPropArgument = spreadProp.argument;
|
|
80
|
+
if (spreadPropArgument.type === 'ObjectExpression') {
|
|
81
|
+
const propertiesToPrune = [];
|
|
82
|
+
spreadPropArgument.properties.forEach(property => {
|
|
83
|
+
if (breakpoints.includes(property.key.name)) {
|
|
84
|
+
size.properties.push(j.property('init', property.key, property.value));
|
|
85
|
+
propertiesToPrune.push(property.key.name);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
spreadPropArgument.properties = spreadPropArgument.properties.filter(prop => !propertiesToPrune.includes(prop.key.name));
|
|
89
|
+
if (spreadPropArgument.properties.length === 0) {
|
|
90
|
+
attributesToPrune.push(spreadProp);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
if (size.properties.length) {
|
|
95
|
+
let sizePropValue = size;
|
|
96
|
+
if (size.properties.length === 1 && size.properties[0].key.name === 'xs') {
|
|
97
|
+
sizePropValue = size.properties[0].value;
|
|
98
|
+
}
|
|
99
|
+
if (sizePropValue.type !== 'StringLiteral') {
|
|
100
|
+
sizePropValue = j.jsxExpressionContainer(sizePropValue);
|
|
101
|
+
}
|
|
102
|
+
el.node.openingElement.attributes.push(j.jsxAttribute(j.jsxIdentifier('size'), sizePropValue));
|
|
103
|
+
}
|
|
104
|
+
el.node.openingElement.attributes = el.node.openingElement.attributes.filter(attr => {
|
|
105
|
+
var _attr$name;
|
|
106
|
+
return !breakpoints.includes(attr == null || (_attr$name = attr.name) == null ? void 0 : _attr$name.name);
|
|
107
|
+
});
|
|
108
|
+
const offset = j.objectExpression([]);
|
|
109
|
+
const offsetNodes = j(el).find(j.JSXAttribute).filter(path => path.parent.parent.node === el.node && path.node.name.name.endsWith('Offset') && breakpoints.includes(path.node.name.name.replace('Offset', '')));
|
|
110
|
+
offsetNodes.nodes().forEach(node => {
|
|
111
|
+
const breakpoint = node.name.name.replace('Offset', '');
|
|
112
|
+
const value = node.value.type === 'JSXExpressionContainer' ? node.value.expression : node.value;
|
|
113
|
+
offset.properties.push(j.property('init', j.identifier(breakpoint), value));
|
|
114
|
+
});
|
|
115
|
+
spreadProps.forEach(spreadProp => {
|
|
116
|
+
const spreadPropArgument = spreadProp.argument;
|
|
117
|
+
if (spreadPropArgument.type === 'ObjectExpression') {
|
|
118
|
+
const propertiesToPrune = [];
|
|
119
|
+
spreadPropArgument.properties.forEach(property => {
|
|
120
|
+
const breakpoint = property.key.name.replace('Offset', '');
|
|
121
|
+
if (property.key.name.endsWith('Offset') && breakpoints.includes(breakpoint)) {
|
|
122
|
+
offset.properties.push(j.property('init', j.identifier(breakpoint), property.value));
|
|
123
|
+
propertiesToPrune.push(property.key.name);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
spreadPropArgument.properties = spreadPropArgument.properties.filter(prop => !propertiesToPrune.includes(prop.key.name));
|
|
127
|
+
if (spreadPropArgument.properties.length === 0) {
|
|
128
|
+
attributesToPrune.push(spreadProp);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
if (offset.properties.length) {
|
|
133
|
+
let offsetPropValue = offset;
|
|
134
|
+
if (offset.properties.length === 1 && offset.properties[0].key.name === 'xs') {
|
|
135
|
+
offsetPropValue = offset.properties[0].value;
|
|
136
|
+
}
|
|
137
|
+
if (offsetPropValue.type !== 'StringLiteral') {
|
|
138
|
+
offsetPropValue = j.jsxExpressionContainer(offsetPropValue);
|
|
139
|
+
}
|
|
140
|
+
el.node.openingElement.attributes.push(j.jsxAttribute(j.jsxIdentifier('offset'), offsetPropValue));
|
|
141
|
+
}
|
|
142
|
+
el.node.openingElement.attributes = el.node.openingElement.attributes.filter(attr => {
|
|
143
|
+
var _attr$name2;
|
|
144
|
+
return !breakpoints.includes(attr == null || (_attr$name2 = attr.name) == null ? void 0 : _attr$name2.name.replace('Offset', ''));
|
|
145
|
+
});
|
|
146
|
+
el.node.openingElement.attributes = el.node.openingElement.attributes.filter(attr => !attributesToPrune.includes(attr));
|
|
147
|
+
});
|
|
148
|
+
return root.toSource(printOptions);
|
|
149
|
+
}
|
|
@@ -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 _gridV2Props.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _gridV2Props = _interopRequireDefault(require("./grid-v2-props"));
|