@mui/codemod 5.15.9 → 5.15.10

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
@@ -1,12 +1,12 @@
1
1
  # @mui/codemod
2
2
 
3
- > Codemod scripts for MUI
3
+ > Codemod scripts for Material UI, Base UI, MUI System, Joy UI.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@mui/codemod.svg?style=flat-square)](https://www.npmjs.com/package/@mui/codemod)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/@mui/codemod.svg?style=flat-square)](https://www.npmjs.com/package/@mui/codemod)
7
7
 
8
8
  This repository contains a collection of codemod scripts based for use with
9
- [jscodeshift](https://github.com/facebook/jscodeshift) that help update MUI APIs.
9
+ [jscodeshift](https://github.com/facebook/jscodeshift) that help update the APIs.
10
10
 
11
11
  ## Setup & run
12
12
 
@@ -91,6 +91,22 @@ A combination of all deprecations.
91
91
  npx @mui/codemod@latest deprecations/accordion-props <path>
92
92
  ```
93
93
 
94
+ #### `avatar-props`
95
+
96
+ ```diff
97
+ <Avatar
98
+ - imgProps={{
99
+ - onError: () => {},
100
+ - onLoad: () => {},
101
+ + slotProps={{
102
+ + img: {
103
+ + onError: () => {},
104
+ + onLoad: () => {},
105
+ + }
106
+ }}
107
+ />;
108
+ ```
109
+
94
110
  #### `divider-props`
95
111
 
96
112
  ```diff
@@ -5,12 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = deprecationsAll;
8
- var _accordionProps = _interopRequireDefault(require("../accordion-props/accordion-props"));
8
+ var _accordionProps = _interopRequireDefault(require("../accordion-props"));
9
+ var _avatarProps = _interopRequireDefault(require("../avatar-props"));
10
+ var _dividerProps = _interopRequireDefault(require("../divider-props"));
9
11
  /**
10
12
  * @param {import('jscodeshift').FileInfo} file
11
13
  * @param {import('jscodeshift').API} api
12
14
  */
13
15
  function deprecationsAll(file, api, options) {
14
16
  file.source = (0, _accordionProps.default)(file, api, options);
17
+ file.source = (0, _avatarProps.default)(file, api, options);
18
+ file.source = (0, _dividerProps.default)(file, api, options);
15
19
  return file.source;
16
20
  }
@@ -0,0 +1,58 @@
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 _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
9
+ var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
10
+ var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
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: 'Avatar'
22
+ }, elementPath => {
23
+ const index = elementPath.node.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === 'imgProps');
24
+ if (index !== -1) {
25
+ const removed = elementPath.node.openingElement.attributes.splice(index, 1);
26
+ let hasNode = false;
27
+ elementPath.node.openingElement.attributes.forEach(attr => {
28
+ var _attr$name;
29
+ if (((_attr$name = attr.name) == null ? void 0 : _attr$name.name) === 'slotProps') {
30
+ hasNode = true;
31
+ (0, _assignObject.default)(j, {
32
+ target: attr,
33
+ key: 'img',
34
+ expression: removed[0].value.expression
35
+ });
36
+ }
37
+ });
38
+ if (!hasNode) {
39
+ (0, _appendAttribute.default)(j, {
40
+ target: elementPath.node,
41
+ attributeName: 'slotProps',
42
+ expression: j.objectExpression([j.objectProperty(j.identifier('img'), removed[0].value.expression)])
43
+ });
44
+ }
45
+ }
46
+ });
47
+ root.find(j.ObjectProperty, {
48
+ key: {
49
+ name: 'imgProps'
50
+ }
51
+ }).forEach(path => {
52
+ var _path$parent;
53
+ if (((_path$parent = path.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.parent) == null || (_path$parent = _path$parent.node.key) == null ? void 0 : _path$parent.name) === 'MuiAvatar') {
54
+ path.replace(j.property('init', j.identifier('slotProps'), j.objectExpression([j.objectProperty(j.identifier('img'), path.node.value)])));
55
+ }
56
+ });
57
+ return root.toSource(printOptions);
58
+ }
@@ -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 _avatarProps.default;
11
+ }
12
+ });
13
+ var _avatarProps = _interopRequireDefault(require("./avatar-props"));
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Avatar = _interopRequireDefault(require("@mui/material/Avatar"));
5
+ var _material = require("@mui/material");
6
+ var _jsxRuntime = require("react/jsx-runtime");
7
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
8
+ imgProps: {
9
+ onError: () => {},
10
+ onLoad: () => {}
11
+ }
12
+ });
13
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Avatar, {
14
+ imgProps: {
15
+ onError: () => {},
16
+ onLoad: () => {}
17
+ }
18
+ });
19
+
20
+ // should skip non MUI components
21
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(NonMuiAvatar, {
22
+ imgProps: {
23
+ onError: () => {},
24
+ onLoad: () => {}
25
+ }
26
+ });
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _Avatar = _interopRequireDefault(require("@mui/material/Avatar"));
5
+ var _material = require("@mui/material");
6
+ var _jsxRuntime = require("react/jsx-runtime");
7
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
8
+ slotProps: {
9
+ img: {
10
+ onError: () => {},
11
+ onLoad: () => {}
12
+ }
13
+ }
14
+ });
15
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Avatar, {
16
+ slotProps: {
17
+ img: {
18
+ onError: () => {},
19
+ onLoad: () => {}
20
+ }
21
+ }
22
+ });
23
+
24
+ // should skip non MUI components
25
+ /*#__PURE__*/(0, _jsxRuntime.jsx)(NonMuiAvatar, {
26
+ imgProps: {
27
+ onError: () => {},
28
+ onLoad: () => {}
29
+ }
30
+ });
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ fn({
4
+ MuiAvatar: {
5
+ defaultProps: {
6
+ imgProps: {
7
+ onError: () => {},
8
+ onLoad: () => {}
9
+ }
10
+ }
11
+ }
12
+ });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ fn({
4
+ MuiAvatar: {
5
+ defaultProps: {
6
+ slotProps: {
7
+ img: {
8
+ onError: () => {},
9
+ onLoad: () => {}
10
+ }
11
+ }
12
+ }
13
+ }
14
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "5.15.9",
3
+ "version": "5.15.10",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",