@mui/codemod 6.1.8 → 6.2.0

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
@@ -1107,6 +1107,32 @@ npx @mui/codemod@latest deprecations/form-control-label-props <path>
1107
1107
  npx @mui/codemod@latest deprecations/list-item-props <path>
1108
1108
  ```
1109
1109
 
1110
+ #### `list-item-text-props`
1111
+
1112
+ ```diff
1113
+ <ListItemText
1114
+ - primaryTypographyProps={primaryTypographyProps}
1115
+ + slotProps={{ primary: primaryTypographyProps }}
1116
+ - secondaryTypographyProps={secondaryTypographyProps}
1117
+ + slotProps={{ secondary: secondaryTypographyProps }}
1118
+ />
1119
+ ```
1120
+
1121
+ ```diff
1122
+ MuiListItemText: {
1123
+ defaultProps: {
1124
+ - primaryTypographyProps:primaryTypographyProps
1125
+ + slotProps:{ primary: primaryTypographyProps }
1126
+ - secondaryTypographyProps:secondaryTypographyProps
1127
+ + slotProps:{ secondary: secondaryTypographyProps }
1128
+ },
1129
+ },
1130
+ ```
1131
+
1132
+ ```bash
1133
+ npx @mui/codemod@latest deprecations/list-item-text-props <path>
1134
+ ```
1135
+
1110
1136
  #### `image-list-item-bar-classes`
1111
1137
 
1112
1138
  JS transforms:
@@ -1669,6 +1695,13 @@ npx @mui/codemod@latest deprecations/table-sort-label-classes <path>
1669
1695
  />
1670
1696
  ```
1671
1697
 
1698
+ ```diff
1699
+ <Typography
1700
+ - paragraph={isTypographyParagraph}
1701
+ + sx={isTypographyParagraph ? { marginBottom: '16px' } : undefined}
1702
+ />
1703
+ ```
1704
+
1672
1705
  ```diff
1673
1706
  MuiTypography: {
1674
1707
  defaultProps: {
@@ -22,6 +22,7 @@ var _formControlLabelProps = _interopRequireDefault(require("../form-control-lab
22
22
  var _imageListItemBarClasses = _interopRequireDefault(require("../image-list-item-bar-classes"));
23
23
  var _inputBaseProps = _interopRequireDefault(require("../input-base-props"));
24
24
  var _inputProps = _interopRequireDefault(require("../input-props"));
25
+ var _listItemTextProps = _interopRequireDefault(require("../list-item-text-props"));
25
26
  var _modalProps = _interopRequireDefault(require("../modal-props"));
26
27
  var _outlinedInputProps = _interopRequireDefault(require("../outlined-input-props"));
27
28
  var _paginationItemClasses = _interopRequireDefault(require("../pagination-item-classes"));
@@ -55,6 +56,7 @@ function deprecationsAll(file, api, options) {
55
56
  file.source = (0, _imageListItemBarClasses.default)(file, api, options);
56
57
  file.source = (0, _inputBaseProps.default)(file, api, options);
57
58
  file.source = (0, _inputProps.default)(file, api, options);
59
+ file.source = (0, _listItemTextProps.default)(file, api, options);
58
60
  file.source = (0, _modalProps.default)(file, api, options);
59
61
  file.source = (0, _outlinedInputProps.default)(file, api, options);
60
62
  file.source = (0, _paginationItemClasses.default)(file, api, options);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "default", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _listItemTextProps.default;
11
+ }
12
+ });
13
+ var _listItemTextProps = _interopRequireDefault(require("./list-item-text-props"));
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _replaceComponentsWithSlots = _interopRequireDefault(require("../utils/replaceComponentsWithSlots"));
9
+ var _movePropIntoSlotProps = _interopRequireDefault(require("../utils/movePropIntoSlotProps"));
10
+ /**
11
+ * @param {import('jscodeshift').FileInfo} file
12
+ * @param {import('jscodeshift').API} api
13
+ */
14
+ function transformer(file, api, options) {
15
+ const j = api.jscodeshift;
16
+ const root = j(file.source);
17
+ const printOptions = options.printOptions;
18
+ (0, _replaceComponentsWithSlots.default)(j, {
19
+ root,
20
+ componentName: 'ListItemText'
21
+ });
22
+ (0, _movePropIntoSlotProps.default)(j, {
23
+ root,
24
+ componentName: 'ListItemText',
25
+ propName: 'primaryTypographyProps',
26
+ slotName: 'primary'
27
+ });
28
+ (0, _movePropIntoSlotProps.default)(j, {
29
+ root,
30
+ componentName: 'ListItemText',
31
+ propName: 'secondaryTypographyProps',
32
+ slotName: 'secondary'
33
+ });
34
+ return root.toSource(printOptions);
35
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _ListItemText = _interopRequireDefault(require("@mui/material/ListItemText"));
5
+ var _jsxRuntime = require("react/jsx-runtime");
6
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
7
+ secondaryTypographyProps: secondaryTypographyProps
8
+ });
9
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
10
+ primaryTypographyProps: primaryTypographyProps
11
+ });
12
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
13
+ primaryTypographyProps: primaryTypographyProps,
14
+ secondaryTypographyProps: secondaryTypographyProps
15
+ });
16
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
17
+ slotProps: {
18
+ primary: primarySlotProps
19
+ },
20
+ secondaryTypographyProps: secondaryTypographyProps
21
+ });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _ListItemText = _interopRequireDefault(require("@mui/material/ListItemText"));
5
+ var _jsxRuntime = require("react/jsx-runtime");
6
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
7
+ slotProps: {
8
+ secondary: secondaryTypographyProps
9
+ }
10
+ });
11
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
12
+ slotProps: {
13
+ primary: primaryTypographyProps
14
+ }
15
+ });
16
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
17
+ slotProps: {
18
+ primary: primaryTypographyProps,
19
+ secondary: secondaryTypographyProps
20
+ }
21
+ });
22
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListItemText.default, {
23
+ slotProps: {
24
+ primary: primarySlotProps,
25
+ secondary: secondaryTypographyProps
26
+ }
27
+ });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ fn({
4
+ MuiListItemText: {
5
+ defaultProps: {
6
+ primaryTypographyProps: primaryTypographyProps
7
+ }
8
+ }
9
+ });
10
+ fn({
11
+ MuiListItemText: {
12
+ defaultProps: {
13
+ secondaryTypographyProps: secondaryTypographyProps
14
+ }
15
+ }
16
+ });
17
+ fn({
18
+ MuiListItemText: {
19
+ defaultProps: {
20
+ primaryTypographyProps: primaryTypographyProps,
21
+ secondaryTypographyProps: secondaryTypographyProps
22
+ }
23
+ }
24
+ });
25
+ fn({
26
+ MuiListItemText: {
27
+ defaultProps: {
28
+ slotProps: {
29
+ primary: primarySlotProps
30
+ },
31
+ secondaryTypographyProps: secondaryTypographyProps
32
+ }
33
+ }
34
+ });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ fn({
4
+ MuiListItemText: {
5
+ defaultProps: {
6
+ slotProps: {
7
+ primary: primaryTypographyProps
8
+ }
9
+ }
10
+ }
11
+ });
12
+ fn({
13
+ MuiListItemText: {
14
+ defaultProps: {
15
+ slotProps: {
16
+ secondary: secondaryTypographyProps
17
+ }
18
+ }
19
+ }
20
+ });
21
+ fn({
22
+ MuiListItemText: {
23
+ defaultProps: {
24
+ slotProps: {
25
+ primary: primaryTypographyProps,
26
+ secondary: secondaryTypographyProps
27
+ }
28
+ }
29
+ }
30
+ });
31
+ fn({
32
+ MuiListItemText: {
33
+ defaultProps: {
34
+ slotProps: {
35
+ primary: primarySlotProps,
36
+ secondary: secondaryTypographyProps
37
+ }
38
+ }
39
+ }
40
+ });
@@ -34,6 +34,14 @@ var _jsxRuntime = require("react/jsx-runtime");
34
34
  paragraph: false,
35
35
  className: "my-class"
36
36
  });
37
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
38
+ paragraph: true,
39
+ className: "my-class"
40
+ });
41
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
42
+ paragraph: true,
43
+ className: "my-class"
44
+ });
37
45
  /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
38
46
  paragraph: paragraph,
39
47
  className: "my-class"
@@ -52,6 +52,18 @@ var _jsxRuntime = require("react/jsx-runtime");
52
52
  marginBottom: "16px"
53
53
  }
54
54
  });
55
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
56
+ className: "my-class",
57
+ sx: paragraph ? {
58
+ marginBottom: "16px"
59
+ } : undefined
60
+ });
61
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
62
+ className: "my-class",
63
+ sx: paragraph ? {
64
+ marginBottom: "16px"
65
+ } : undefined
66
+ });
55
67
  /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
56
68
  sx: {
57
69
  marginBottom: "32px"
@@ -30,16 +30,18 @@ function transformer(file, api, options) {
30
30
  }
31
31
  return true;
32
32
  });
33
- const isParagraphPropTruthy = paragraphProp.value?.expression.value !== false;
34
- if (!isParagraphPropTruthy) {
33
+ const isParagraphPropPresent = paragraphProp.value?.expression.value !== false;
34
+ if (!isParagraphPropPresent) {
35
35
  return;
36
36
  }
37
+ const isParagraphPropTrue = paragraphProp.value == null || paragraphProp.value.expression.value === true;
38
+ const paragraphExpression = expression => isParagraphPropTrue ? expression : j.conditionalExpression(paragraphProp.value.expression, expression, j.identifier('undefined'));
37
39
  const sxIndex = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'sx');
38
40
  if (sxIndex === -1) {
39
41
  (0, _appendAttribute.default)(j, {
40
42
  target: elementPath.node,
41
43
  attributeName: 'sx',
42
- expression: j.objectExpression([j.objectProperty(j.identifier('marginBottom'), j.literal('16px'))])
44
+ expression: paragraphExpression(j.objectExpression([j.objectProperty(j.identifier('marginBottom'), j.literal('16px'))]))
43
45
  });
44
46
  } else {
45
47
  const hasMarginBottom = elementPath.node.openingElement.attributes[sxIndex].value.expression.properties.some(key => key.key.name === 'marginBottom' || key.key.name === 'mb');
@@ -47,7 +49,7 @@ function transformer(file, api, options) {
47
49
  (0, _assignObject.default)(j, {
48
50
  target: elementPath.node.openingElement.attributes[sxIndex],
49
51
  key: 'marginBottom',
50
- expression: j.literal('16px')
52
+ expression: paragraphExpression(j.literal('16px'))
51
53
  });
52
54
  }
53
55
  }
@@ -8,5 +8,7 @@ exports.default = transformer;
8
8
  * @param {import('jscodeshift').FileInfo} file
9
9
  */
10
10
  function transformer(file) {
11
- return file.source.replace(/\n?import.*core\/RootRef['"];?/gm, '').replace(/\n?import {\s?RootRef\s?} from ['"]@material-ui\/core\/?['"];?/gm, '').replace(/({.*)(RootRef,?)(.*})/gm, '$1$3').replace(/<RootRef.*>/gm, '<>').replace(/<\/RootRef>/gm, '</>');
11
+ // The regexes below have a negative lookahead to prevent ReDoS
12
+ // See https://github.com/mui/material-ui/issues/44078
13
+ return file.source.replace(/\n?import(?!import).*core\/RootRef['"];?/gm, '').replace(/\n?import {\s?RootRef\s?} from ['"]@material-ui\/core\/?['"];?/gm, '').replace(/({.*)(RootRef,?)(.*})/gm, '$1$3').replace(/<RootRef(?!<RootRef).*>/gm, '<>').replace(/<\/RootRef>/gm, '</>');
12
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "6.1.8",
3
+ "version": "6.2.0",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",