@mui/codemod 6.1.8 → 6.1.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 CHANGED
@@ -1669,6 +1669,13 @@ npx @mui/codemod@latest deprecations/table-sort-label-classes <path>
1669
1669
  />
1670
1670
  ```
1671
1671
 
1672
+ ```diff
1673
+ <Typography
1674
+ - paragraph={isTypographyParagraph}
1675
+ + sx={isTypographyParagraph ? { marginBottom: '16px' } : undefined}
1676
+ />
1677
+ ```
1678
+
1672
1679
  ```diff
1673
1680
  MuiTypography: {
1674
1681
  defaultProps: {
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "6.1.8",
3
+ "version": "6.1.9",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",