@mui/x-codemod 7.0.0-alpha.9 → 7.0.0-beta.6

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/x-codemod
2
2
 
3
- > Codemod scripts for MUI X
3
+ > Codemod scripts for MUI X
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@mui/x-codemod.svg?style=flat-square)](https://www.npmjs.com/package/@mui/x-codemod)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/@mui/x-codemod.svg?style=flat-square)](https://www.npmjs.com/package/@mui/x-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 X APIs.
9
+ [jscodeshift](https://github.com/facebook/jscodeshift) that help update MUI X APIs.
10
10
 
11
11
  ## Setup & run
12
12
 
@@ -221,6 +221,7 @@ The list includes these transformers
221
221
  - [`rename-use-tree-item`](#rename-use-tree-item)
222
222
  - [`rename-expansion-props`](#rename-expansion-props)
223
223
  - [`rename-selection-props`](#rename-selection-props)
224
+ - [`replace-transition-props-by-slot`](#replace-transition-props-by-slot)
224
225
 
225
226
  #### `rename-tree-view-simple-tree-view`
226
227
 
@@ -300,6 +301,20 @@ Rename the selection props
300
301
  />
301
302
  ```
302
303
 
304
+ #### `replace-transition-props-by-slot`
305
+
306
+ Replace the `TransitionComponent` and `TransitionProps` components with the `groupTransition` slot:
307
+
308
+ ```diff
309
+ <TreeItem
310
+ - TransitionComponent={Fade}
311
+ + slots={{ groupTransition: Fade }}
312
+
313
+ - TransitionProps={{ timeout: 600 }}
314
+ + slotProps={{ groupTransition: { timeout: 600 } }}
315
+ />
316
+ ```
317
+
303
318
  ## v6.0.0
304
319
 
305
320
  ### 🚀 `preset-safe` for v6.0.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-codemod",
3
- "version": "7.0.0-alpha.9",
3
+ "version": "7.0.0-beta.6",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",
@@ -32,9 +32,9 @@
32
32
  "url": "https://opencollective.com/mui-org"
33
33
  },
34
34
  "dependencies": {
35
- "@babel/core": "^7.23.7",
36
- "@babel/runtime": "^7.23.8",
37
- "@babel/traverse": "^7.23.7",
35
+ "@babel/core": "^7.24.0",
36
+ "@babel/runtime": "^7.24.0",
37
+ "@babel/traverse": "^7.24.0",
38
38
  "jscodeshift": "0.13.1",
39
39
  "jscodeshift-add-imports": "^1.0.10",
40
40
  "yargs": "^17.7.2"
@@ -7,11 +7,13 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = transformer;
8
8
  var _renameExpansionProps = _interopRequireDefault(require("../rename-expansion-props"));
9
9
  var _renameSelectionProps = _interopRequireDefault(require("../rename-selection-props"));
10
+ var _replaceTransitionPropsBySlot = _interopRequireDefault(require("../replace-transition-props-by-slot"));
10
11
  var _renameUseTreeItem = _interopRequireDefault(require("../rename-use-tree-item"));
11
12
  var _renameTreeViewSimpleTreeView = _interopRequireDefault(require("../rename-tree-view-simple-tree-view"));
12
13
  function transformer(file, api, options) {
13
14
  file.source = (0, _renameExpansionProps.default)(file, api, options);
14
15
  file.source = (0, _renameSelectionProps.default)(file, api, options);
16
+ file.source = (0, _replaceTransitionPropsBySlot.default)(file, api, options);
15
17
  file.source = (0, _renameUseTreeItem.default)(file, api, options);
16
18
  file.source = (0, _renameTreeViewSimpleTreeView.default)(file, api, options);
17
19
  return file.source;
@@ -0,0 +1,54 @@
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 _addComponentsSlots = require("../../../util/addComponentsSlots");
9
+ var _removeProps = _interopRequireDefault(require("../../../util/removeProps"));
10
+ const propsToSlots = {
11
+ TransitionComponent: {
12
+ prop: 'slots',
13
+ path: 'groupTransition'
14
+ },
15
+ TransitionProps: {
16
+ prop: 'slotProps',
17
+ path: 'groupTransition'
18
+ }
19
+ };
20
+ function transformer(file, api, options) {
21
+ const j = api.jscodeshift;
22
+ const root = j(file.source);
23
+ const printOptions = options.printOptions || {
24
+ quote: 'single',
25
+ trailingComma: true
26
+ };
27
+ root.find(j.JSXElement).filter(path => path.value.openingElement.name.name === 'TreeItem').forEach(path => {
28
+ const attributesToTransform = j(path).find(j.JSXAttribute).filter(attribute => Object.keys(propsToSlots).includes(attribute.value.name.name));
29
+ attributesToTransform.forEach(attribute => {
30
+ const attributeName = attribute.value.name.name;
31
+
32
+ // Get the value in case it's:
33
+ // - prop={value}
34
+ // - prop="value"
35
+ // - prop (which means true)
36
+ let value = attribute.value.value?.type === 'JSXExpressionContainer' ? attribute.value.value.expression : attribute.value.value || j.booleanLiteral(true);
37
+ if (attributeName === 'showToolbar') {
38
+ if (value.type === 'BooleanLiteral' || value.type === 'Literal' && typeof value.value === 'boolean') {
39
+ value.value = !value.value;
40
+ } else {
41
+ value = j.unaryExpression('!', value);
42
+ }
43
+ }
44
+ (0, _addComponentsSlots.transformNestedProp)(path, propsToSlots[attributeName].prop, propsToSlots[attributeName].path, value, j);
45
+ });
46
+ });
47
+ (0, _removeProps.default)({
48
+ root,
49
+ componentNames: ['TreeItem'],
50
+ props: Object.keys(propsToSlots),
51
+ j
52
+ });
53
+ return root.toSource(printOptions);
54
+ }