@mui/codemod 6.0.0-beta.1 → 6.0.0-beta.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 +23 -1
- package/node/deprecations/divider-props/divider-props.js +48 -36
- package/node/deprecations/divider-props/test-cases/expected.js +2 -8
- package/node/deprecations/divider-props/test-cases/theme.actual.js +15 -0
- package/node/deprecations/divider-props/test-cases/theme.expected.js +12 -0
- package/node/deprecations/typography-props/index.js +13 -0
- package/node/deprecations/typography-props/test-cases/actual.js +80 -0
- package/node/deprecations/typography-props/test-cases/expected.js +86 -0
- package/node/deprecations/typography-props/test-cases/theme.actual.js +85 -0
- package/node/deprecations/typography-props/test-cases/theme.expected.js +86 -0
- package/node/deprecations/typography-props/typography-props.js +86 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ npx @mui/codemod@next <transform> <path> --jscodeshift="--printOptions='{\"quote
|
|
|
61
61
|
|
|
62
62
|
## Included scripts
|
|
63
63
|
|
|
64
|
-
- [
|
|
64
|
+
- [Deprecations](#deprecations)
|
|
65
65
|
- [v6](#v600)
|
|
66
66
|
- [v5](#v500)
|
|
67
67
|
- [v4](#v400)
|
|
@@ -1585,6 +1585,28 @@ CSS transforms:
|
|
|
1585
1585
|
npx @mui/codemod@next deprecations/table-sort-label-classes <path>
|
|
1586
1586
|
```
|
|
1587
1587
|
|
|
1588
|
+
#### `typography-props`
|
|
1589
|
+
|
|
1590
|
+
```diff
|
|
1591
|
+
<Typography
|
|
1592
|
+
- paragraph
|
|
1593
|
+
+ sx={{ marginBottom: '16px' }}
|
|
1594
|
+
/>
|
|
1595
|
+
```
|
|
1596
|
+
|
|
1597
|
+
```diff
|
|
1598
|
+
MuiTypography: {
|
|
1599
|
+
defaultProps: {
|
|
1600
|
+
- paragraph: true
|
|
1601
|
+
+ sx: { marginBottom: '16px' },
|
|
1602
|
+
},
|
|
1603
|
+
},
|
|
1604
|
+
```
|
|
1605
|
+
|
|
1606
|
+
```bash
|
|
1607
|
+
npx @mui/codemod@next deprecations/typography-props <path>
|
|
1608
|
+
```
|
|
1609
|
+
|
|
1588
1610
|
### v6.0.0
|
|
1589
1611
|
|
|
1590
1612
|
#### `sx-prop`
|
|
@@ -20,30 +20,36 @@ function transformer(file, api, options) {
|
|
|
20
20
|
root,
|
|
21
21
|
componentName: 'Divider'
|
|
22
22
|
}, elementPath => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
var _lightProp$value;
|
|
24
|
+
const lightProp = elementPath.node.openingElement.attributes.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'light');
|
|
25
|
+
if (!lightProp) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
elementPath.node.openingElement.attributes = elementPath.node.openingElement.attributes.filter(attr => {
|
|
29
|
+
if (attr.type === 'JSXAttribute' && attr.name.name === 'light') {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
const isLightPropTruthy = ((_lightProp$value = lightProp.value) == null ? void 0 : _lightProp$value.expression.value) !== false;
|
|
35
|
+
if (!isLightPropTruthy) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const sxIndex = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'sx');
|
|
39
|
+
if (sxIndex === -1) {
|
|
40
|
+
(0, _appendAttribute.default)(j, {
|
|
41
|
+
target: elementPath.node,
|
|
42
|
+
attributeName: 'sx',
|
|
43
|
+
expression: j.objectExpression([j.objectProperty(j.identifier('opacity'), j.literal('0.6'))])
|
|
30
44
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
} else {
|
|
46
|
+
const opacityIndex = elementPath.node.openingElement.attributes[sxIndex].value.expression.properties.findIndex(key => key.key.name === 'opacity');
|
|
47
|
+
if (opacityIndex === -1) {
|
|
48
|
+
(0, _assignObject.default)(j, {
|
|
49
|
+
target: elementPath.node.openingElement.attributes[sxIndex],
|
|
50
|
+
key: 'opacity',
|
|
51
|
+
expression: j.literal('0.6')
|
|
37
52
|
});
|
|
38
|
-
} else {
|
|
39
|
-
const opacityIndex = elementPath.node.openingElement.attributes[sxIndex].value.expression.properties.findIndex(key => key.key.name === 'opacity');
|
|
40
|
-
if (opacityIndex === -1) {
|
|
41
|
-
(0, _assignObject.default)(j, {
|
|
42
|
-
target: elementPath.node.openingElement.attributes[sxIndex],
|
|
43
|
-
key: 'opacity',
|
|
44
|
-
expression: j.literal('0.6')
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
});
|
|
@@ -52,21 +58,27 @@ function transformer(file, api, options) {
|
|
|
52
58
|
name: 'MuiDivider'
|
|
53
59
|
}
|
|
54
60
|
}).forEach(path => {
|
|
61
|
+
var _lightProp$value2;
|
|
55
62
|
const defaultPropsObject = path.value.value.properties.find(key => key.key.name === 'defaultProps');
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
const lightProp = defaultPropsObject.value.properties.find(prop => prop.key.name === 'light');
|
|
64
|
+
if (!lightProp) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
defaultPropsObject.value.properties = defaultPropsObject.value.properties.filter(prop => {
|
|
68
|
+
var _prop$key;
|
|
69
|
+
return !['light'].includes(prop == null || (_prop$key = prop.key) == null ? void 0 : _prop$key.name);
|
|
70
|
+
});
|
|
71
|
+
const isLightPropTruthy = ((_lightProp$value2 = lightProp.value) == null ? void 0 : _lightProp$value2.value) !== false;
|
|
72
|
+
if (!isLightPropTruthy) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const sxIndex = defaultPropsObject.value.properties.findIndex(prop => prop.key.name === 'sx');
|
|
76
|
+
if (sxIndex === -1) {
|
|
77
|
+
defaultPropsObject.value.properties.push(j.objectProperty(j.identifier('sx'), j.objectExpression([j.objectProperty(j.identifier('opacity'), j.literal('0.6'))])));
|
|
78
|
+
} else {
|
|
79
|
+
const opacityIndex = defaultPropsObject.value.properties[sxIndex].value.properties.findIndex(key => key.key.name === 'opacity');
|
|
80
|
+
if (opacityIndex === -1) {
|
|
81
|
+
defaultPropsObject.value.properties[sxIndex].value.properties.push(j.objectProperty(j.identifier('opacity'), j.literal('0.6')));
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
84
|
});
|
|
@@ -17,16 +17,10 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
|
|
20
|
-
className: "test"
|
|
21
|
-
sx: {
|
|
22
|
-
opacity: "0.6"
|
|
23
|
-
}
|
|
20
|
+
className: "test"
|
|
24
21
|
});
|
|
25
22
|
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
|
|
26
|
-
className: "test"
|
|
27
|
-
sx: {
|
|
28
|
-
opacity: "0.6"
|
|
29
|
-
}
|
|
23
|
+
className: "test"
|
|
30
24
|
});
|
|
31
25
|
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
|
|
32
26
|
className: "test",
|
|
@@ -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 _typographyProps.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _typographyProps = _interopRequireDefault(require("./typography-props"));
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
|
|
5
|
+
var _material = require("@mui/material");
|
|
6
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {});
|
|
8
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {});
|
|
9
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
10
|
+
className: "my-class"
|
|
11
|
+
});
|
|
12
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
13
|
+
className: "my-class"
|
|
14
|
+
});
|
|
15
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
16
|
+
paragraph: true
|
|
17
|
+
});
|
|
18
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
19
|
+
paragraph: true
|
|
20
|
+
});
|
|
21
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
22
|
+
paragraph: true,
|
|
23
|
+
className: "my-class"
|
|
24
|
+
});
|
|
25
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
26
|
+
paragraph: true,
|
|
27
|
+
className: "my-class"
|
|
28
|
+
});
|
|
29
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
30
|
+
paragraph: false,
|
|
31
|
+
className: "my-class"
|
|
32
|
+
});
|
|
33
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
34
|
+
paragraph: false,
|
|
35
|
+
className: "my-class"
|
|
36
|
+
});
|
|
37
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
38
|
+
paragraph: paragraph,
|
|
39
|
+
className: "my-class"
|
|
40
|
+
});
|
|
41
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
42
|
+
paragraph: paragraph,
|
|
43
|
+
className: "my-class"
|
|
44
|
+
});
|
|
45
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
46
|
+
paragraph: true,
|
|
47
|
+
sx: {
|
|
48
|
+
marginBottom: "32px"
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
52
|
+
paragraph: true,
|
|
53
|
+
sx: {
|
|
54
|
+
marginBottom: "32px"
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
58
|
+
paragraph: true,
|
|
59
|
+
sx: {
|
|
60
|
+
mb: "32px"
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
64
|
+
paragraph: true,
|
|
65
|
+
sx: {
|
|
66
|
+
mb: "32px"
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
70
|
+
paragraph: true,
|
|
71
|
+
sx: {
|
|
72
|
+
color: "black"
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
76
|
+
paragraph: true,
|
|
77
|
+
sx: {
|
|
78
|
+
color: "black"
|
|
79
|
+
}
|
|
80
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
|
|
5
|
+
var _material = require("@mui/material");
|
|
6
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {});
|
|
8
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {});
|
|
9
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
10
|
+
className: "my-class"
|
|
11
|
+
});
|
|
12
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
13
|
+
className: "my-class"
|
|
14
|
+
});
|
|
15
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
16
|
+
sx: {
|
|
17
|
+
marginBottom: "16px"
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
21
|
+
sx: {
|
|
22
|
+
marginBottom: "16px"
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
26
|
+
className: "my-class",
|
|
27
|
+
sx: {
|
|
28
|
+
marginBottom: "16px"
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
32
|
+
className: "my-class",
|
|
33
|
+
sx: {
|
|
34
|
+
marginBottom: "16px"
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
38
|
+
className: "my-class"
|
|
39
|
+
});
|
|
40
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
41
|
+
className: "my-class"
|
|
42
|
+
});
|
|
43
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
44
|
+
className: "my-class",
|
|
45
|
+
sx: {
|
|
46
|
+
marginBottom: "16px"
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
50
|
+
className: "my-class",
|
|
51
|
+
sx: {
|
|
52
|
+
marginBottom: "16px"
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
56
|
+
sx: {
|
|
57
|
+
marginBottom: "32px"
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
61
|
+
sx: {
|
|
62
|
+
marginBottom: "32px"
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
66
|
+
sx: {
|
|
67
|
+
mb: "32px"
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
71
|
+
sx: {
|
|
72
|
+
mb: "32px"
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
76
|
+
sx: {
|
|
77
|
+
color: "black",
|
|
78
|
+
marginBottom: "16px"
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
82
|
+
sx: {
|
|
83
|
+
color: "black",
|
|
84
|
+
marginBottom: "16px"
|
|
85
|
+
}
|
|
86
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
fn({
|
|
4
|
+
MuiTypography: {
|
|
5
|
+
defaultProps: {}
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
fn({
|
|
9
|
+
MuiTypography: {
|
|
10
|
+
defaultProps: {
|
|
11
|
+
className: "my-class"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
fn({
|
|
16
|
+
MuiTypography: {
|
|
17
|
+
defaultProps: {
|
|
18
|
+
paragraph: false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
fn({
|
|
23
|
+
MuiTypography: {
|
|
24
|
+
defaultProps: {
|
|
25
|
+
paragraph: false,
|
|
26
|
+
className: "my-class"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
fn({
|
|
31
|
+
MuiTypography: {
|
|
32
|
+
defaultProps: {
|
|
33
|
+
paragraph: true
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
fn({
|
|
38
|
+
MuiTypography: {
|
|
39
|
+
defaultProps: {
|
|
40
|
+
paragraph: true,
|
|
41
|
+
className: "my-class"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
fn({
|
|
46
|
+
MuiTypography: {
|
|
47
|
+
defaultProps: {
|
|
48
|
+
paragraph,
|
|
49
|
+
className: "my-class"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
fn({
|
|
54
|
+
MuiTypography: {
|
|
55
|
+
defaultProps: {
|
|
56
|
+
paragraph,
|
|
57
|
+
className: "my-class",
|
|
58
|
+
sx: {
|
|
59
|
+
marginBottom: "32px"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
fn({
|
|
65
|
+
MuiTypography: {
|
|
66
|
+
defaultProps: {
|
|
67
|
+
paragraph,
|
|
68
|
+
className: "my-class",
|
|
69
|
+
sx: {
|
|
70
|
+
mb: "32px"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
fn({
|
|
76
|
+
MuiTypography: {
|
|
77
|
+
defaultProps: {
|
|
78
|
+
paragraph,
|
|
79
|
+
className: "my-class",
|
|
80
|
+
sx: {
|
|
81
|
+
color: "black"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
fn({
|
|
4
|
+
MuiTypography: {
|
|
5
|
+
defaultProps: {}
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
fn({
|
|
9
|
+
MuiTypography: {
|
|
10
|
+
defaultProps: {
|
|
11
|
+
className: "my-class"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
fn({
|
|
16
|
+
MuiTypography: {
|
|
17
|
+
defaultProps: {}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
fn({
|
|
21
|
+
MuiTypography: {
|
|
22
|
+
defaultProps: {
|
|
23
|
+
className: "my-class"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
fn({
|
|
28
|
+
MuiTypography: {
|
|
29
|
+
defaultProps: {
|
|
30
|
+
sx: {
|
|
31
|
+
marginBottom: "16px"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
fn({
|
|
37
|
+
MuiTypography: {
|
|
38
|
+
defaultProps: {
|
|
39
|
+
className: "my-class",
|
|
40
|
+
sx: {
|
|
41
|
+
marginBottom: "16px"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
fn({
|
|
47
|
+
MuiTypography: {
|
|
48
|
+
defaultProps: {
|
|
49
|
+
className: "my-class",
|
|
50
|
+
sx: {
|
|
51
|
+
marginBottom: "16px"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
fn({
|
|
57
|
+
MuiTypography: {
|
|
58
|
+
defaultProps: {
|
|
59
|
+
className: "my-class",
|
|
60
|
+
sx: {
|
|
61
|
+
marginBottom: "32px"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
fn({
|
|
67
|
+
MuiTypography: {
|
|
68
|
+
defaultProps: {
|
|
69
|
+
className: "my-class",
|
|
70
|
+
sx: {
|
|
71
|
+
mb: "32px"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
fn({
|
|
77
|
+
MuiTypography: {
|
|
78
|
+
defaultProps: {
|
|
79
|
+
className: "my-class",
|
|
80
|
+
sx: {
|
|
81
|
+
color: "black",
|
|
82
|
+
marginBottom: "16px"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
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 _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
|
|
9
|
+
var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
|
|
10
|
+
var _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
|
|
11
|
+
/**
|
|
12
|
+
* @param {import('jscodeshift').FileInfo} file
|
|
13
|
+
* @param {import('jscodeshift').API} api
|
|
14
|
+
*/
|
|
15
|
+
function transformer(file, api, options) {
|
|
16
|
+
const j = api.jscodeshift;
|
|
17
|
+
const root = j(file.source);
|
|
18
|
+
const printOptions = options.printOptions;
|
|
19
|
+
(0, _findComponentJSX.default)(j, {
|
|
20
|
+
root,
|
|
21
|
+
componentName: 'Typography'
|
|
22
|
+
}, elementPath => {
|
|
23
|
+
var _paragraphProp$value;
|
|
24
|
+
const paragraphProp = elementPath.node.openingElement.attributes.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'paragraph');
|
|
25
|
+
if (!paragraphProp) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
elementPath.node.openingElement.attributes = elementPath.node.openingElement.attributes.filter(attr => {
|
|
29
|
+
if (attr.type === 'JSXAttribute' && attr.name.name === 'paragraph') {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
const isParagraphPropTruthy = ((_paragraphProp$value = paragraphProp.value) == null ? void 0 : _paragraphProp$value.expression.value) !== false;
|
|
35
|
+
if (!isParagraphPropTruthy) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const sxIndex = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'sx');
|
|
39
|
+
if (sxIndex === -1) {
|
|
40
|
+
(0, _appendAttribute.default)(j, {
|
|
41
|
+
target: elementPath.node,
|
|
42
|
+
attributeName: 'sx',
|
|
43
|
+
expression: j.objectExpression([j.objectProperty(j.identifier('marginBottom'), j.literal('16px'))])
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
const hasMarginBottom = elementPath.node.openingElement.attributes[sxIndex].value.expression.properties.some(key => key.key.name === 'marginBottom' || key.key.name === 'mb');
|
|
47
|
+
if (!hasMarginBottom) {
|
|
48
|
+
(0, _assignObject.default)(j, {
|
|
49
|
+
target: elementPath.node.openingElement.attributes[sxIndex],
|
|
50
|
+
key: 'marginBottom',
|
|
51
|
+
expression: j.literal('16px')
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
root.find(j.ObjectProperty, {
|
|
57
|
+
key: {
|
|
58
|
+
name: 'MuiTypography'
|
|
59
|
+
}
|
|
60
|
+
}).forEach(path => {
|
|
61
|
+
var _paragraphProp$value2;
|
|
62
|
+
const defaultPropsObject = path.value.value.properties.find(key => key.key.name === 'defaultProps');
|
|
63
|
+
const paragraphProp = defaultPropsObject.value.properties.find(prop => prop.key.name === 'paragraph');
|
|
64
|
+
if (!paragraphProp) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
defaultPropsObject.value.properties = defaultPropsObject.value.properties.filter(prop => {
|
|
68
|
+
var _prop$key;
|
|
69
|
+
return !['paragraph'].includes(prop == null || (_prop$key = prop.key) == null ? void 0 : _prop$key.name);
|
|
70
|
+
});
|
|
71
|
+
const isParagraphPropTruthy = ((_paragraphProp$value2 = paragraphProp.value) == null ? void 0 : _paragraphProp$value2.value) !== false;
|
|
72
|
+
if (!isParagraphPropTruthy) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const sxIndex = defaultPropsObject.value.properties.findIndex(prop => prop.key.name === 'sx');
|
|
76
|
+
if (sxIndex === -1) {
|
|
77
|
+
defaultPropsObject.value.properties.push(j.objectProperty(j.identifier('sx'), j.objectExpression([j.objectProperty(j.identifier('marginBottom'), j.literal('16px'))])));
|
|
78
|
+
} else {
|
|
79
|
+
const hasMarginBottom = defaultPropsObject.value.properties[sxIndex].value.properties.some(key => key.key.name === 'marginBottom' || key.key.name === 'mb');
|
|
80
|
+
if (!hasMarginBottom) {
|
|
81
|
+
defaultPropsObject.value.properties[sxIndex].value.properties.push(j.objectProperty(j.identifier('marginBottom'), j.literal('16px')));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return root.toSource(printOptions);
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/codemod",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.3",
|
|
4
4
|
"bin": "./codemod.js",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "MUI Team",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"url": "https://opencollective.com/mui-org"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@babel/core": "^7.24.
|
|
27
|
+
"@babel/core": "^7.24.9",
|
|
28
28
|
"@babel/runtime": "^7.24.8",
|
|
29
29
|
"@babel/traverse": "^7.24.8",
|
|
30
30
|
"jscodeshift": "^0.16.1",
|
|
31
|
-
"jscodeshift-add-imports": "^1.0.
|
|
31
|
+
"jscodeshift-add-imports": "^1.0.11",
|
|
32
32
|
"postcss": "^8.4.39",
|
|
33
33
|
"postcss-cli": "^11.0.0",
|
|
34
34
|
"yargs": "^17.7.2"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"directory": "build"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
47
|
+
"node": ">=14.0.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/mui-codemod/**/*.test.js'",
|