@mui/codemod 6.0.0-alpha.8 → 6.0.0-alpha.9
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 +219 -45
- package/node/deprecations/all/deprecations-all.js +4 -0
- package/node/deprecations/avatar-group-props/avatar-group-props.js +87 -0
- package/node/deprecations/avatar-group-props/index.js +13 -0
- package/node/deprecations/avatar-group-props/test-cases/actual.js +56 -0
- package/node/deprecations/avatar-group-props/test-cases/expected.js +58 -0
- package/node/deprecations/avatar-group-props/test-cases/theme.actual.js +48 -0
- package/node/deprecations/avatar-group-props/test-cases/theme.expected.js +50 -0
- package/node/deprecations/grid-props/grid-props.js +51 -0
- package/node/deprecations/grid-props/index.js +13 -0
- package/node/deprecations/grid-props/test-cases/actual.js +25 -0
- package/node/deprecations/grid-props/test-cases/expected.js +23 -0
- package/node/deprecations/grid-props/test-cases/theme.actual.js +24 -0
- package/node/deprecations/grid-props/test-cases/theme.expected.js +23 -0
- package/node/deprecations/list-item-props/index.js +13 -0
- package/node/deprecations/list-item-props/list-item-props.js +22 -0
- package/node/deprecations/list-item-props/test-cases/actual.js +43 -0
- package/node/deprecations/list-item-props/test-cases/expected.js +40 -0
- package/node/deprecations/list-item-props/test-cases/theme.actual.js +56 -0
- package/node/deprecations/list-item-props/test-cases/theme.expected.js +53 -0
- package/node/deprecations/popper-props/index.js +13 -0
- package/node/deprecations/popper-props/popper-props.js +22 -0
- package/node/deprecations/popper-props/test-cases/actual.js +27 -0
- package/node/deprecations/popper-props/test-cases/expected.js +24 -0
- package/node/deprecations/popper-props/test-cases/theme.actual.js +32 -0
- package/node/deprecations/popper-props/test-cases/theme.expected.js +29 -0
- package/node/deprecations/tooltip-props/index.js +13 -0
- package/node/deprecations/tooltip-props/test-cases/actual.js +92 -0
- package/node/deprecations/tooltip-props/test-cases/expected.js +84 -0
- package/node/deprecations/tooltip-props/test-cases/theme.actual.js +73 -0
- package/node/deprecations/tooltip-props/test-cases/theme.expected.js +65 -0
- package/node/deprecations/tooltip-props/tooltip-props.js +22 -0
- package/node/util/migrateToVariants.js +156 -98
- package/node/v6.0.0/sx-prop/index.js +13 -0
- package/node/v6.0.0/sx-prop/sx-v6.js +355 -0
- package/node/v6.0.0/sx-prop/test-cases/basic-sx.actual.js +36 -0
- package/node/v6.0.0/sx-prop/test-cases/basic-sx.expected.js +46 -0
- package/node/v6.0.0/sx-prop/test-cases/sx-css-vars.actual.js +41 -0
- package/node/v6.0.0/sx-prop/test-cases/sx-css-vars.expected.js +71 -0
- package/node/v6.0.0/sx-prop/test-cases/sx-dynamic.actual.js +87 -0
- package/node/v6.0.0/sx-prop/test-cases/sx-dynamic.expected.js +102 -0
- package/node/v6.0.0/sx-prop/test-cases/sx-dynamic2.actual.js +49 -0
- package/node/v6.0.0/sx-prop/test-cases/sx-dynamic2.expected.js +64 -0
- package/node/v6.0.0/system-props/index.js +13 -0
- package/node/v6.0.0/system-props/removeSystemProps.js +242 -0
- package/node/v6.0.0/system-props/test-cases/system-props.actual.js +79 -0
- package/node/v6.0.0/system-props/test-cases/system-props.expected.js +92 -0
- package/node/v6.0.0/theme-v6/theme-v6.js +2 -2
- package/package.json +4 -4
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _Tooltip = _interopRequireDefault(require("@mui/material/Tooltip"));
|
|
5
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
6
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
7
|
+
slots: {
|
|
8
|
+
arrow: ComponentsArrow,
|
|
9
|
+
popper: ComponentsPopper,
|
|
10
|
+
tooltip: ComponentsTooltip,
|
|
11
|
+
transition: ComponentsTransition
|
|
12
|
+
},
|
|
13
|
+
slotProps: {
|
|
14
|
+
arrow: componentsArrowProps,
|
|
15
|
+
popper: componentsPopperProps,
|
|
16
|
+
tooltip: componentsTooltipProps,
|
|
17
|
+
transition: componentsTransitionProps
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
21
|
+
slots: {
|
|
22
|
+
tooltip: SlotsTooltip,
|
|
23
|
+
arrow: ComponentsArrow
|
|
24
|
+
},
|
|
25
|
+
slotProps: {
|
|
26
|
+
tooltip: slotsTooltipProps,
|
|
27
|
+
arrow: componentsArrowProps
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
31
|
+
slots: {
|
|
32
|
+
tooltip: SlotsTooltip,
|
|
33
|
+
arrow: SlotsArrow
|
|
34
|
+
},
|
|
35
|
+
slotProps: {
|
|
36
|
+
tooltip: slotsTooltipProps,
|
|
37
|
+
arrow: {
|
|
38
|
+
...componentsArrowProps,
|
|
39
|
+
...slotsArrowProps
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
44
|
+
slots: {
|
|
45
|
+
tooltip: SlotsTooltip,
|
|
46
|
+
arrow: SlotsArrow
|
|
47
|
+
},
|
|
48
|
+
slotProps: {
|
|
49
|
+
arrow: {
|
|
50
|
+
...componentsArrowProps,
|
|
51
|
+
...slotsArrowProps
|
|
52
|
+
},
|
|
53
|
+
tooltip: {
|
|
54
|
+
...componentsTooltipProps,
|
|
55
|
+
...slotsTooltipProps
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
60
|
+
slots: {
|
|
61
|
+
arrow: SlotsArrow,
|
|
62
|
+
popper: SlotsPopper,
|
|
63
|
+
tooltip: SlotsTooltip,
|
|
64
|
+
transition: SlotsTransition
|
|
65
|
+
},
|
|
66
|
+
slotProps: {
|
|
67
|
+
arrow: {
|
|
68
|
+
...componentsArrowProps,
|
|
69
|
+
...slotsArrowProps
|
|
70
|
+
},
|
|
71
|
+
popper: {
|
|
72
|
+
...componentsPopperProps,
|
|
73
|
+
...slotsPopperProps
|
|
74
|
+
},
|
|
75
|
+
tooltip: {
|
|
76
|
+
...componentsTooltipProps,
|
|
77
|
+
...slotsTooltipProps
|
|
78
|
+
},
|
|
79
|
+
transition: {
|
|
80
|
+
...componentsTransitionProps,
|
|
81
|
+
...slotsTransitionProps
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
fn({
|
|
4
|
+
MuiTooltip: {
|
|
5
|
+
defaultProps: {
|
|
6
|
+
components: {
|
|
7
|
+
Arrow: ComponentsArrow
|
|
8
|
+
},
|
|
9
|
+
componentsProps: {
|
|
10
|
+
arrow: componentsArrowProps
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
fn({
|
|
16
|
+
MuiTooltip: {
|
|
17
|
+
defaultProps: {
|
|
18
|
+
components: {
|
|
19
|
+
Arrow: ComponentsArrow
|
|
20
|
+
},
|
|
21
|
+
slots: {
|
|
22
|
+
tooltip: SlotsTooltip
|
|
23
|
+
},
|
|
24
|
+
componentsProps: {
|
|
25
|
+
arrow: componentsArrowProps
|
|
26
|
+
},
|
|
27
|
+
slotProps: {
|
|
28
|
+
tooltip: slotsTooltipProps
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
fn({
|
|
34
|
+
MuiTooltip: {
|
|
35
|
+
defaultProps: {
|
|
36
|
+
components: {
|
|
37
|
+
Arrow: ComponentsArrow
|
|
38
|
+
},
|
|
39
|
+
slots: {
|
|
40
|
+
tooltip: SlotsTooltip,
|
|
41
|
+
arrow: SlotsArrow
|
|
42
|
+
},
|
|
43
|
+
componentsProps: {
|
|
44
|
+
arrow: componentsArrowProps
|
|
45
|
+
},
|
|
46
|
+
slotProps: {
|
|
47
|
+
tooltip: slotsTooltipProps,
|
|
48
|
+
arrow: slotsArrowProps
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
fn({
|
|
54
|
+
MuiTooltip: {
|
|
55
|
+
defaultProps: {
|
|
56
|
+
components: {
|
|
57
|
+
Arrow: ComponentsArrow
|
|
58
|
+
},
|
|
59
|
+
slots: {
|
|
60
|
+
tooltip: SlotsTooltip,
|
|
61
|
+
arrow: SlotsArrow
|
|
62
|
+
},
|
|
63
|
+
componentsProps: {
|
|
64
|
+
arrow: componentsArrowProps,
|
|
65
|
+
tooltip: componentsTooltipProps
|
|
66
|
+
},
|
|
67
|
+
slotProps: {
|
|
68
|
+
tooltip: slotsTooltipProps,
|
|
69
|
+
arrow: slotsArrowProps
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
fn({
|
|
4
|
+
MuiTooltip: {
|
|
5
|
+
defaultProps: {
|
|
6
|
+
slots: {
|
|
7
|
+
arrow: ComponentsArrow
|
|
8
|
+
},
|
|
9
|
+
slotProps: {
|
|
10
|
+
arrow: componentsArrowProps
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
fn({
|
|
16
|
+
MuiTooltip: {
|
|
17
|
+
defaultProps: {
|
|
18
|
+
slots: {
|
|
19
|
+
arrow: ComponentsArrow,
|
|
20
|
+
tooltip: SlotsTooltip
|
|
21
|
+
},
|
|
22
|
+
slotProps: {
|
|
23
|
+
arrow: componentsArrowProps,
|
|
24
|
+
tooltip: slotsTooltipProps
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
fn({
|
|
30
|
+
MuiTooltip: {
|
|
31
|
+
defaultProps: {
|
|
32
|
+
slots: {
|
|
33
|
+
arrow: SlotsArrow,
|
|
34
|
+
tooltip: SlotsTooltip
|
|
35
|
+
},
|
|
36
|
+
slotProps: {
|
|
37
|
+
arrow: {
|
|
38
|
+
...componentsArrowProps,
|
|
39
|
+
...slotsArrowProps
|
|
40
|
+
},
|
|
41
|
+
tooltip: slotsTooltipProps
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
fn({
|
|
47
|
+
MuiTooltip: {
|
|
48
|
+
defaultProps: {
|
|
49
|
+
slots: {
|
|
50
|
+
arrow: SlotsArrow,
|
|
51
|
+
tooltip: SlotsTooltip
|
|
52
|
+
},
|
|
53
|
+
slotProps: {
|
|
54
|
+
arrow: {
|
|
55
|
+
...componentsArrowProps,
|
|
56
|
+
...slotsArrowProps
|
|
57
|
+
},
|
|
58
|
+
tooltip: {
|
|
59
|
+
...componentsTooltipProps,
|
|
60
|
+
...slotsTooltipProps
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
var _replaceComponentsWithSlots = _interopRequireDefault(require("../utils/replaceComponentsWithSlots"));
|
|
9
|
+
/**
|
|
10
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
11
|
+
* @param {import('jscodeshift').API} api
|
|
12
|
+
*/
|
|
13
|
+
function transformer(file, api, options) {
|
|
14
|
+
const j = api.jscodeshift;
|
|
15
|
+
const root = j(file.source);
|
|
16
|
+
const printOptions = options.printOptions;
|
|
17
|
+
(0, _replaceComponentsWithSlots.default)(j, {
|
|
18
|
+
root,
|
|
19
|
+
componentName: 'Tooltip'
|
|
20
|
+
});
|
|
21
|
+
return root.toSource(printOptions);
|
|
22
|
+
}
|
|
@@ -4,87 +4,168 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = migrateToVariants;
|
|
7
|
+
exports.getCreateBuildStyle = exports.getBuildArrowFunctionAST = exports.getAppendPaletteModeStyles = void 0;
|
|
8
|
+
exports.getIdentifierKey = getIdentifierKey;
|
|
9
|
+
exports.getObjectKey = getObjectKey;
|
|
10
|
+
exports.getObjectToArrowFunction = void 0;
|
|
11
|
+
exports.isThemePaletteMode = isThemePaletteMode;
|
|
12
|
+
exports.removeProperty = removeProperty;
|
|
7
13
|
const MAX_DEPTH = 20;
|
|
14
|
+
|
|
8
15
|
/**
|
|
9
|
-
*
|
|
10
16
|
* @param {import('jscodeshift').API['j']} j
|
|
11
|
-
* @
|
|
17
|
+
* @returns
|
|
12
18
|
*/
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (key) {
|
|
20
|
-
|
|
21
|
-
return upperBuildStyle(j.objectExpression([j.objectProperty(key, styleExpression)]));
|
|
22
|
-
}
|
|
23
|
-
if (key.type === 'TemplateLiteral' || key.type === 'CallExpression') {
|
|
24
|
-
return upperBuildStyle(j.objectExpression([{
|
|
25
|
-
...j.objectProperty(key, styleExpression),
|
|
26
|
-
computed: true
|
|
27
|
-
}]));
|
|
28
|
-
}
|
|
19
|
+
const getCreateBuildStyle = j => function createBuildStyle(key, upperBuildStyle, applyStylesMode) {
|
|
20
|
+
if (applyStylesMode) {
|
|
21
|
+
upperBuildStyle = styleExpression => j.objectExpression([j.spreadElement(j.callExpression(j.memberExpression(j.identifier('theme'), j.identifier('applyStyles')), [j.stringLiteral(applyStylesMode), styleExpression]))]);
|
|
22
|
+
}
|
|
23
|
+
return function buildStyle(styleExpression) {
|
|
24
|
+
if (key) {
|
|
25
|
+
if (key.type === 'Identifier' || key.type === 'StringLiteral') {
|
|
26
|
+
return upperBuildStyle(j.objectExpression([j.objectProperty(key, styleExpression)]));
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
if (key.type === 'TemplateLiteral' || key.type === 'CallExpression') {
|
|
29
|
+
return upperBuildStyle(j.objectExpression([{
|
|
30
|
+
...j.objectProperty(key, styleExpression),
|
|
31
|
+
computed: true
|
|
32
|
+
}]));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return upperBuildStyle ? upperBuildStyle(styleExpression) : styleExpression;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {import('jscodeshift').API['j']} j
|
|
41
|
+
*/
|
|
42
|
+
exports.getCreateBuildStyle = getCreateBuildStyle;
|
|
43
|
+
const getAppendPaletteModeStyles = j =>
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {{ properties: any[] }} node
|
|
47
|
+
* @param {Record<string, any[] | import('jscodeshift').ObjectExpression>} modeStyles
|
|
48
|
+
*/
|
|
49
|
+
function appendPaletteModeStyles(node, modeStyles) {
|
|
50
|
+
Object.entries(modeStyles).forEach(([mode, objectStyles]) => {
|
|
51
|
+
node.properties.push(j.spreadElement(j.callExpression(j.memberExpression(j.identifier('theme'), j.identifier('applyStyles')), [j.stringLiteral(mode), Array.isArray(objectStyles) ? j.objectExpression(objectStyles) : objectStyles])));
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param {import('jscodeshift').MemberExpression | import('jscodeshift').Identifier} node
|
|
58
|
+
*/
|
|
59
|
+
exports.getAppendPaletteModeStyles = getAppendPaletteModeStyles;
|
|
60
|
+
function getIdentifierKey(node) {
|
|
61
|
+
if (node.type === 'MemberExpression') {
|
|
62
|
+
return node.property;
|
|
32
63
|
}
|
|
64
|
+
return node;
|
|
65
|
+
}
|
|
33
66
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @param {import('jscodeshift').UnaryExpression | import('jscodeshift').MemberExpression | import('jscodeshift').Identifier} node
|
|
70
|
+
*/
|
|
71
|
+
function getObjectKey(node) {
|
|
72
|
+
let tempNode = {
|
|
73
|
+
...node
|
|
74
|
+
};
|
|
75
|
+
while (tempNode.type === 'UnaryExpression') {
|
|
76
|
+
tempNode = tempNode.argument;
|
|
43
77
|
}
|
|
78
|
+
while (tempNode.type === 'MemberExpression' || tempNode.type === 'OptionMemberExpression') {
|
|
79
|
+
tempNode = tempNode.object;
|
|
80
|
+
}
|
|
81
|
+
return tempNode;
|
|
82
|
+
}
|
|
44
83
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
while (tempNode.type === 'UnaryExpression') {
|
|
54
|
-
tempNode = tempNode.argument;
|
|
55
|
-
}
|
|
56
|
-
while (tempNode.type === 'MemberExpression') {
|
|
57
|
-
tempNode = tempNode.object;
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @param {import('jscodeshift').ObjectExpression} node
|
|
87
|
+
*/
|
|
88
|
+
function removeProperty(parentNode, child) {
|
|
89
|
+
if (parentNode) {
|
|
90
|
+
if (parentNode.type === 'ObjectExpression') {
|
|
91
|
+
parentNode.properties = parentNode.properties.filter(prop => prop !== child && prop.value !== child);
|
|
58
92
|
}
|
|
59
|
-
return tempNode;
|
|
60
93
|
}
|
|
94
|
+
}
|
|
61
95
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
96
|
+
/**
|
|
97
|
+
* @param {import('jscodeshift').API['j']} j
|
|
98
|
+
*/
|
|
99
|
+
const getBuildArrowFunctionAST = j =>
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param {Set<string> | import('jscodeshift').Expression[]} params
|
|
103
|
+
* @param {import('jscodeshift').BlockStatement} body
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
function buildArrowFunctionAST(params, body) {
|
|
107
|
+
const destructured = [...params].every(param => typeof param === 'string');
|
|
108
|
+
return j.arrowFunctionExpression(destructured ? [j.objectPattern([...params].map(k => ({
|
|
109
|
+
...j.objectProperty(j.identifier(k), j.identifier(k)),
|
|
110
|
+
shorthand: true
|
|
111
|
+
})))] : params, body);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param {import('jscodeshift').API['j']} j
|
|
116
|
+
*/
|
|
117
|
+
exports.getBuildArrowFunctionAST = getBuildArrowFunctionAST;
|
|
118
|
+
const getObjectToArrowFunction = j => {
|
|
119
|
+
const buildArrowFunctionAST = getBuildArrowFunctionAST(j);
|
|
120
|
+
return (
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* @param {import('jscodeshift').ObjectExpression} objectExpression
|
|
124
|
+
* @param {import('jscodeshift').BinaryExpression} addtional
|
|
125
|
+
*/
|
|
126
|
+
function objectToArrowFunction(objectExpression, addtional) {
|
|
127
|
+
const paramKeys = new Set();
|
|
128
|
+
let left;
|
|
129
|
+
objectExpression.properties.forEach((prop, index) => {
|
|
130
|
+
paramKeys.add(prop.key.name);
|
|
131
|
+
const result = j.binaryExpression('===', prop.key, prop.value);
|
|
132
|
+
if (index === 0) {
|
|
133
|
+
left = result;
|
|
134
|
+
} else {
|
|
135
|
+
left = j.logicalExpression('&&', left, result);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
if (addtional) {
|
|
139
|
+
paramKeys.add(getObjectKey(addtional.left).name);
|
|
77
140
|
}
|
|
78
|
-
|
|
79
|
-
if (addtional) {
|
|
80
|
-
paramKeys.add(getObjectKey(addtional.left).name);
|
|
141
|
+
return buildArrowFunctionAST(paramKeys, addtional ? j.logicalExpression('&&', left, addtional) : left);
|
|
81
142
|
}
|
|
82
|
-
|
|
83
|
-
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
*
|
|
148
|
+
* @param {undefined | null | import('jscodeshift').Expression} node
|
|
149
|
+
*/
|
|
150
|
+
exports.getObjectToArrowFunction = getObjectToArrowFunction;
|
|
151
|
+
function isThemePaletteMode(node) {
|
|
152
|
+
return (node == null ? void 0 : node.type) === 'MemberExpression' && node.object.type === 'MemberExpression' && node.object.object.name === 'theme' && node.object.property.name === 'palette' && node.property.name === 'mode';
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
*
|
|
157
|
+
* @param {import('jscodeshift').API['j']} j
|
|
158
|
+
* @param {any[]} styles
|
|
159
|
+
*/
|
|
160
|
+
function migrateToVariants(j, styles) {
|
|
161
|
+
const createBuildStyle = getCreateBuildStyle(j);
|
|
162
|
+
const appendPaletteModeStyles = getAppendPaletteModeStyles(j);
|
|
163
|
+
const buildArrowFunctionAST = getBuildArrowFunctionAST(j);
|
|
164
|
+
const objectToArrowFunction = getObjectToArrowFunction(j);
|
|
84
165
|
|
|
85
166
|
/**
|
|
86
167
|
*
|
|
87
|
-
* @param {import('
|
|
168
|
+
* @param {import('jscodeshift').Identifier | import('jscodeshift').BinaryExpression | import('jscodeshift').UnaryExpression | import('jscodeshift').MemberExpression} node
|
|
88
169
|
*/
|
|
89
170
|
function inverseBinaryExpression(node) {
|
|
90
171
|
if (node.type === 'Identifier' || node.type === 'MemberExpression') {
|
|
@@ -111,18 +192,6 @@ function migrateToVariants(j, styles) {
|
|
|
111
192
|
}
|
|
112
193
|
return node;
|
|
113
194
|
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
*
|
|
117
|
-
* @param {import('ast-types').namedTypes.ObjectExpression} node
|
|
118
|
-
*/
|
|
119
|
-
function removeProperty(parentNode, child) {
|
|
120
|
-
if (parentNode) {
|
|
121
|
-
if (parentNode.type === 'ObjectExpression') {
|
|
122
|
-
parentNode.properties = parentNode.properties.filter(prop => prop !== child && prop.value !== child);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
195
|
function buildObjectAST(jsObject) {
|
|
127
196
|
const result = j.objectExpression([]);
|
|
128
197
|
Object.entries(jsObject).forEach(([key, value]) => {
|
|
@@ -130,27 +199,10 @@ function migrateToVariants(j, styles) {
|
|
|
130
199
|
});
|
|
131
200
|
return result;
|
|
132
201
|
}
|
|
133
|
-
function buildArrowFunctionAST(params, body) {
|
|
134
|
-
return j.arrowFunctionExpression([j.objectPattern([...params].map(k => ({
|
|
135
|
-
...j.objectProperty(j.identifier(k), j.identifier(k)),
|
|
136
|
-
shorthand: true
|
|
137
|
-
})))], body);
|
|
138
|
-
}
|
|
139
202
|
|
|
140
203
|
/**
|
|
141
204
|
*
|
|
142
|
-
* @param {
|
|
143
|
-
* @param {Record<string, any[] | import('ast-types').namedTypes.ObjectExpression>} modeStyles
|
|
144
|
-
*/
|
|
145
|
-
function appendPaletteModeStyles(node, modeStyles) {
|
|
146
|
-
Object.entries(modeStyles).forEach(([mode, objectStyles]) => {
|
|
147
|
-
node.properties.push(j.spreadElement(j.callExpression(j.memberExpression(j.identifier('theme'), j.identifier('applyStyles')), [j.stringLiteral(mode), Array.isArray(objectStyles) ? j.objectExpression(objectStyles) : objectStyles])));
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
*
|
|
153
|
-
* @param {import('ast-types').namedTypes.LogicalExpression | import('ast-types').namedTypes.BinaryExpression | import('ast-types').namedTypes.UnaryExpression | import('ast-types').namedTypes.MemberExpression} node
|
|
205
|
+
* @param {import('jscodeshift').LogicalExpression | import('jscodeshift').BinaryExpression | import('jscodeshift').UnaryExpression | import('jscodeshift').MemberExpression} node
|
|
154
206
|
*/
|
|
155
207
|
function buildProps(node) {
|
|
156
208
|
const properties = [];
|
|
@@ -219,9 +271,6 @@ function migrateToVariants(j, styles) {
|
|
|
219
271
|
});
|
|
220
272
|
return buildArrowFunctionAST(variables, j.logicalExpression('&&', parentArrow.body, currentArrow.body));
|
|
221
273
|
}
|
|
222
|
-
function isThemePaletteMode(node) {
|
|
223
|
-
return node.type === 'MemberExpression' && node.object.type === 'MemberExpression' && node.object.object.name === 'theme' && node.object.property.name === 'palette' && node.property.name === 'mode';
|
|
224
|
-
}
|
|
225
274
|
|
|
226
275
|
// 2. Find logical spread expressions to convert to variants
|
|
227
276
|
styles.forEach(style => {
|
|
@@ -232,10 +281,13 @@ function migrateToVariants(j, styles) {
|
|
|
232
281
|
parameters.add(prop.key.name);
|
|
233
282
|
});
|
|
234
283
|
}
|
|
284
|
+
if (param.type === 'Identifier') {
|
|
285
|
+
parameters.add(param.name);
|
|
286
|
+
}
|
|
235
287
|
});
|
|
236
288
|
const variants = [];
|
|
237
289
|
if (style.body.type === 'LogicalExpression') {
|
|
238
|
-
if (style.params[0] && style.params[0].type === 'ObjectPattern' && style.params[0].properties.some(prop => prop.key.name !== 'theme')) {
|
|
290
|
+
if (style.params[0] && (style.params[0].type === 'Identifier' || style.params[0].type === 'ObjectPattern' && style.params[0].properties.some(prop => prop.key.name !== 'theme'))) {
|
|
239
291
|
// case: ({ theme, ownerState }) => ownerState.variant === 'regular' && theme.mixins.toolbar
|
|
240
292
|
style.body = j.objectExpression([j.objectProperty(j.identifier('variants'), j.arrayExpression([j.objectExpression([j.objectProperty(j.identifier('props'), buildProps(style.body.left)), j.objectProperty(j.identifier('style'), style.body.right)])]))]);
|
|
241
293
|
}
|
|
@@ -459,6 +511,12 @@ function migrateToVariants(j, styles) {
|
|
|
459
511
|
}
|
|
460
512
|
data.modeStyles[mode].push(j.objectProperty(data.key, clonedNode));
|
|
461
513
|
});
|
|
514
|
+
if (data.key) {
|
|
515
|
+
var _data$replaceValue2;
|
|
516
|
+
// to remove the arrow function
|
|
517
|
+
// { ...: theme => `1px solid...` } to { ...: `1px solid...` }
|
|
518
|
+
(_data$replaceValue2 = data.replaceValue) == null || _data$replaceValue2.call(data, data.node);
|
|
519
|
+
}
|
|
462
520
|
}
|
|
463
521
|
}
|
|
464
522
|
}
|
|
@@ -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 _sxV.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _sxV = _interopRequireDefault(require("./sx-v6"));
|