@mui/codemod 6.0.0-beta.1 → 6.0.0-beta.3-dev.20240725-084532-7340f56bef

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 CHANGED
@@ -61,7 +61,7 @@ npx @mui/codemod@next <transform> <path> --jscodeshift="--printOptions='{\"quote
61
61
 
62
62
  ## Included scripts
63
63
 
64
- - [Deprecation](#deprecations)
64
+ - [Deprecations](#deprecations)
65
65
  - [v6](#v600)
66
66
  - [v5](#v500)
67
67
  - [v4](#v400)
@@ -1117,6 +1117,63 @@ npx @mui/codemod@next deprecations/list-item-props <path>
1117
1117
  npx @mui/codemod@next deprecations/grid-props <path>
1118
1118
  ```
1119
1119
 
1120
+ #### `image-list-item-bar-classes`
1121
+
1122
+ JS transforms:
1123
+
1124
+ ```diff
1125
+ import { imageListItemBarClasses } from '@mui/material/ImageListItemBar';
1126
+
1127
+ MuiImageListItemBar: {
1128
+ styleOverrides: {
1129
+ root: {
1130
+ - [`& .${imageListItemBarClasses.titleWrapBelow}`]: {
1131
+ + [`&.${imageListItemBarClasses.positionBelow} > .${imageListItemBarClasses.titleWrap}`]: {
1132
+ color: 'red',
1133
+ },
1134
+ - [`& .${imageListItemBarClasses.titleWrapActionPosLeft}`]: {
1135
+ + [`&.${imageListItemBarClasses.actionPositionLeft} > .${imageListItemBarClasses.titleWrap}`]: {
1136
+ color: 'red',
1137
+ },
1138
+ - [`& .${imageListItemBarClasses.titleWrapActionPosRight}`]: {
1139
+ + [`&.${imageListItemBarClasses.actionPositionRight} > .${imageListItemBarClasses.titleWrap}`]: {
1140
+ color: 'red',
1141
+ },
1142
+ - [`& .${imageListItemBarClasses.actionIconActionPosLeft}`]: {
1143
+ + [`&.${imageListItemBarClasses.actionPositionLeft} > .${imageListItemBarClasses.actionIcon}`]: {
1144
+ color: 'red',
1145
+ },
1146
+ },
1147
+ },
1148
+ },
1149
+ ```
1150
+
1151
+ CSS transforms:
1152
+
1153
+ ```diff
1154
+ - .MuiImageListItemBar-titleWrapBelow
1155
+ +.MuiImageListItemBar-positionBelow > .MuiImageListItemBar-titleWrap
1156
+ ```
1157
+
1158
+ ```diff
1159
+ - .MuiImageListItemBar-titleWrapActionPosLeft
1160
+ +.MuiImageListItemBar-actionPositionLeft > .MuiImageListItemBar-titleWrap
1161
+ ```
1162
+
1163
+ ```diff
1164
+ - .MuiImageListItemBar-titleWrapActionPosRight
1165
+ +.MuiImageListItemBar-actionPositionRight > .MuiImageListItemBar-titleWrap
1166
+ ```
1167
+
1168
+ ```diff
1169
+ - .MuiImageListItemBar-actionIconActionPosLeft
1170
+ +.MuiImageListItemBar-actionPositionLeft > .MuiImageListItemBar-actionIcon
1171
+ ```
1172
+
1173
+ ```bash
1174
+ npx @mui/codemod@next deprecations/image-list-item-bar-classes <path>
1175
+ ```
1176
+
1120
1177
  #### `input-base-props`
1121
1178
 
1122
1179
  ```diff
@@ -1585,6 +1642,28 @@ CSS transforms:
1585
1642
  npx @mui/codemod@next deprecations/table-sort-label-classes <path>
1586
1643
  ```
1587
1644
 
1645
+ #### `typography-props`
1646
+
1647
+ ```diff
1648
+ <Typography
1649
+ - paragraph
1650
+ + sx={{ marginBottom: '16px' }}
1651
+ />
1652
+ ```
1653
+
1654
+ ```diff
1655
+ MuiTypography: {
1656
+ defaultProps: {
1657
+ - paragraph: true
1658
+ + sx: { marginBottom: '16px' },
1659
+ },
1660
+ },
1661
+ ```
1662
+
1663
+ ```bash
1664
+ npx @mui/codemod@next deprecations/typography-props <path>
1665
+ ```
1666
+
1588
1667
  ### v6.0.0
1589
1668
 
1590
1669
  #### `sx-prop`
@@ -18,6 +18,7 @@ var _dividerProps = _interopRequireDefault(require("../divider-props"));
18
18
  var _filledInputProps = _interopRequireDefault(require("../filled-input-props"));
19
19
  var _formControlLabelProps = _interopRequireDefault(require("../form-control-label-props"));
20
20
  var _gridProps = _interopRequireDefault(require("../grid-props"));
21
+ var _imageListItemBarClasses = _interopRequireDefault(require("../image-list-item-bar-classes"));
21
22
  var _inputBaseProps = _interopRequireDefault(require("../input-base-props"));
22
23
  var _inputProps = _interopRequireDefault(require("../input-props"));
23
24
  var _modalProps = _interopRequireDefault(require("../modal-props"));
@@ -47,6 +48,7 @@ function deprecationsAll(file, api, options) {
47
48
  file.source = (0, _filledInputProps.default)(file, api, options);
48
49
  file.source = (0, _formControlLabelProps.default)(file, api, options);
49
50
  file.source = (0, _gridProps.default)(file, api, options);
51
+ file.source = (0, _imageListItemBarClasses.default)(file, api, options);
50
52
  file.source = (0, _inputBaseProps.default)(file, api, options);
51
53
  file.source = (0, _inputProps.default)(file, api, options);
52
54
  file.source = (0, _modalProps.default)(file, api, options);
@@ -20,30 +20,36 @@ function transformer(file, api, options) {
20
20
  root,
21
21
  componentName: 'Divider'
22
22
  }, elementPath => {
23
- const hasLightProp = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'light') !== -1;
24
- if (hasLightProp) {
25
- elementPath.node.openingElement.attributes = elementPath.node.openingElement.attributes.filter(attr => {
26
- if (attr.type === 'JSXAttribute' && attr.name.name === 'light') {
27
- return false;
28
- }
29
- return true;
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
- const sxIndex = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'sx');
32
- if (sxIndex === -1) {
33
- (0, _appendAttribute.default)(j, {
34
- target: elementPath.node,
35
- attributeName: 'sx',
36
- expression: j.objectExpression([j.objectProperty(j.identifier('opacity'), j.literal('0.6'))])
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 hasLightProp = defaultPropsObject.value.properties.findIndex(prop => prop.key.name === 'light') !== -1;
57
- if (hasLightProp) {
58
- defaultPropsObject.value.properties = defaultPropsObject.value.properties.filter(prop => {
59
- var _prop$key;
60
- return !['light'].includes(prop == null || (_prop$key = prop.key) == null ? void 0 : _prop$key.name);
61
- });
62
- const sxIndex = defaultPropsObject.value.properties.findIndex(prop => prop.key.name === 'sx');
63
- if (sxIndex === -1) {
64
- defaultPropsObject.value.properties.push(j.objectProperty(j.identifier('sx'), j.objectExpression([j.objectProperty(j.identifier('opacity'), j.literal('0.6'))])));
65
- } else {
66
- const opacityIndex = defaultPropsObject.value.properties[sxIndex].value.properties.findIndex(key => key.key.name === 'opacity');
67
- if (opacityIndex === -1) {
68
- defaultPropsObject.value.properties[sxIndex].value.properties.push(j.objectProperty(j.identifier('opacity'), j.literal('0.6')));
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",
@@ -1,5 +1,20 @@
1
1
  "use strict";
2
2
 
3
+ fn({
4
+ MuiDivider: {
5
+ defaultProps: {
6
+ light: false
7
+ }
8
+ }
9
+ });
10
+ fn({
11
+ MuiDivider: {
12
+ defaultProps: {
13
+ light: false,
14
+ className: 'my-class'
15
+ }
16
+ }
17
+ });
3
18
  fn({
4
19
  MuiDivider: {
5
20
  defaultProps: {
@@ -1,5 +1,17 @@
1
1
  "use strict";
2
2
 
3
+ fn({
4
+ MuiDivider: {
5
+ defaultProps: {}
6
+ }
7
+ });
8
+ fn({
9
+ MuiDivider: {
10
+ defaultProps: {
11
+ className: 'my-class'
12
+ }
13
+ }
14
+ });
3
15
  fn({
4
16
  MuiDivider: {
5
17
  defaultProps: {
@@ -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\/ImageListItemBar$/)).forEach(path => {
22
+ path.node.specifiers.forEach(specifier => {
23
+ if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'imageListItemBarClasses') {
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('MuiImageListItemBar-', '').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,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 _imageListItemBarClasses.default;
11
+ }
12
+ });
13
+ var _imageListItemBarClasses = _interopRequireDefault(require("./image-list-item-bar-classes"));
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ const classes = [{
4
+ deprecatedClass: ' .MuiImageListItemBar-titleWrapBelow',
5
+ replacementSelector: '.MuiImageListItemBar-positionBelow > .MuiImageListItemBar-titleWrap'
6
+ }, {
7
+ deprecatedClass: ' .MuiImageListItemBar-titleWrapActionPosLeft',
8
+ replacementSelector: '.MuiImageListItemBar-actionPositionLeft > .MuiImageListItemBar-titleWrap'
9
+ }, {
10
+ deprecatedClass: ' .MuiImageListItemBar-titleWrapActionPosRight',
11
+ replacementSelector: '.MuiImageListItemBar-actionPositionRight > .MuiImageListItemBar-titleWrap'
12
+ }, {
13
+ deprecatedClass: ' .MuiImageListItemBar-actionIconActionPosLeft',
14
+ replacementSelector: '.MuiImageListItemBar-actionPositionLeft > .MuiImageListItemBar-actionIcon'
15
+ }];
16
+ const plugin = () => {
17
+ return {
18
+ postcssPlugin: `Replace deprecated ImageListItemBar classes with new classes`,
19
+ Rule(rule) {
20
+ const {
21
+ selector
22
+ } = rule;
23
+ classes.forEach(({
24
+ deprecatedClass,
25
+ replacementSelector
26
+ }) => {
27
+ const selectorRegex = new RegExp(`${deprecatedClass}$`);
28
+ if (selector.match(selectorRegex)) {
29
+ rule.selector = selector.replace(selectorRegex, replacementSelector);
30
+ }
31
+ });
32
+ }
33
+ };
34
+ };
35
+ plugin.postcss = true;
36
+ module.exports = {
37
+ plugin,
38
+ classes
39
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ const {
4
+ plugin
5
+ } = require('./postcss-plugin');
6
+ module.exports = {
7
+ plugins: [plugin]
8
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ var _ImageListItemBar = require("@mui/material/ImageListItemBar");
4
+ '& .MuiImageListItemBar-titleWrapBelow';
5
+ '& .MuiImageListItemBar-titleWrapActionPosLeft';
6
+ '& .MuiImageListItemBar-titleWrapActionPosRight';
7
+ '& .MuiImageListItemBar-actionIconActionPosLeft';
8
+ `& .${_ImageListItemBar.imageListItemBarClasses.titleWrapBelow}`;
9
+ `& .${_ImageListItemBar.imageListItemBarClasses.titleWrapActionPosLeft}`;
10
+ `& .${_ImageListItemBar.imageListItemBarClasses.titleWrapActionPosRight}`;
11
+ `& .${_ImageListItemBar.imageListItemBarClasses.actionIconActionPosLeft}`;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ var _ImageListItemBar = require("@mui/material/ImageListItemBar");
4
+ "&.MuiImageListItemBar-positionBelow > .MuiImageListItemBar-titleWrap";
5
+ "&.MuiImageListItemBar-actionPositionLeft > .MuiImageListItemBar-titleWrap";
6
+ "&.MuiImageListItemBar-actionPositionRight > .MuiImageListItemBar-titleWrap";
7
+ "&.MuiImageListItemBar-actionPositionLeft > .MuiImageListItemBar-actionIcon";
8
+ `&.${_ImageListItemBar.imageListItemBarClasses.positionBelow} > .${_ImageListItemBar.imageListItemBarClasses.titleWrap}`;
9
+ `&.${_ImageListItemBar.imageListItemBarClasses.actionPositionLeft} > .${_ImageListItemBar.imageListItemBarClasses.titleWrap}`;
10
+ `&.${_ImageListItemBar.imageListItemBarClasses.actionPositionRight} > .${_ImageListItemBar.imageListItemBarClasses.titleWrap}`;
11
+ `&.${_ImageListItemBar.imageListItemBarClasses.actionPositionLeft} > .${_ImageListItemBar.imageListItemBarClasses.actionIcon}`;
@@ -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.1",
3
+ "version": "6.0.0-beta.3-dev.20240725-084532-7340f56bef",
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.8",
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.10",
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": ">=12.0.0"
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'",