@mui/codemod 6.0.0-beta.4 → 6.0.0-beta.4-dev.20240802-144226-85a3b55d22

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.
@@ -8,6 +8,7 @@ exports.default = transformer;
8
8
  var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
9
9
  var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
10
10
  var _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
11
+ var _findComponentDefaultProps = _interopRequireDefault(require("../../util/findComponentDefaultProps"));
11
12
  /**
12
13
  * @param {import('jscodeshift').FileInfo} file
13
14
  * @param {import('jscodeshift').API} api
@@ -53,34 +54,30 @@ function transformer(file, api, options) {
53
54
  }
54
55
  }
55
56
  });
56
- root.find(j.ObjectProperty, {
57
+ const defaultPropsPathCollection = (0, _findComponentDefaultProps.default)(j, {
58
+ root,
59
+ componentName: 'Divider'
60
+ });
61
+ defaultPropsPathCollection.find(j.ObjectProperty, {
57
62
  key: {
58
- name: 'MuiDivider'
63
+ name: 'light'
59
64
  }
60
65
  }).forEach(path => {
61
- var _lightProp$value2;
62
- const defaultPropsObject = path.value.value.properties.find(key => key.key.name === 'defaultProps');
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) {
66
+ var _path$value;
67
+ const {
68
+ properties: defaultPropsProperties
69
+ } = path.parent.value;
70
+ if (((_path$value = path.value) == null ? void 0 : _path$value.value.value) === false) {
71
+ path.prune();
73
72
  return;
74
73
  }
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')));
82
- }
74
+ const existingSx = defaultPropsProperties.find(prop => prop.key.name === 'sx');
75
+ if (!existingSx) {
76
+ defaultPropsProperties.push(j.property('init', j.identifier('sx'), j.objectExpression([j.objectProperty(j.identifier('opacity'), j.literal('0.6'))])));
77
+ } else if (!existingSx.value.properties.find(prop => prop.key.name === 'opacity')) {
78
+ existingSx.value.properties.push(j.property('init', j.identifier('opacity'), j.literal('0.6')));
83
79
  }
80
+ path.prune();
84
81
  });
85
82
  return root.toSource(printOptions);
86
83
  }
@@ -66,4 +66,10 @@ fn({
66
66
  className: 'my-class'
67
67
  }
68
68
  }
69
+ });
70
+ fn({
71
+ MuiDivider: {}
72
+ });
73
+ fn({
74
+ MuiDivider: 123
69
75
  });
@@ -68,4 +68,10 @@ fn({
68
68
  className: 'my-class'
69
69
  }
70
70
  }
71
+ });
72
+ fn({
73
+ MuiDivider: {}
74
+ });
75
+ fn({
76
+ MuiDivider: 123
71
77
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "6.0.0-beta.4",
3
+ "version": "6.0.0-beta.4-dev.20240802-144226-85a3b55d22",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",