@mui/codemod 5.7.0 → 5.8.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.
Files changed (22) hide show
  1. package/README.md +82 -0
  2. package/codemod.js +0 -0
  3. package/node/v5.0.0/jss-to-tss-react.js +457 -0
  4. package/node/v5.0.0/jss-to-tss-react.test/actual-from-material-ui-core-styles.js +52 -0
  5. package/node/v5.0.0/jss-to-tss-react.test/actual-from-material-ui-core.js +75 -0
  6. package/node/v5.0.0/jss-to-tss-react.test/actual-from-mui-styles.js +53 -0
  7. package/node/v5.0.0/jss-to-tss-react.test/actual-mixins-pattern.js +51 -0
  8. package/node/v5.0.0/jss-to-tss-react.test/actual-todo-comments.js +74 -0
  9. package/node/v5.0.0/jss-to-tss-react.test/actual-typescript-docs-example-params.js +59 -0
  10. package/node/v5.0.0/jss-to-tss-react.test/actual-typescript-docs-example.js +55 -0
  11. package/node/v5.0.0/jss-to-tss-react.test/actual-typescript.js +73 -0
  12. package/node/v5.0.0/jss-to-tss-react.test/actual-withStyles.js +123 -0
  13. package/node/v5.0.0/jss-to-tss-react.test/expected-from-material-ui-core-styles.js +56 -0
  14. package/node/v5.0.0/jss-to-tss-react.test/expected-from-material-ui-core.js +80 -0
  15. package/node/v5.0.0/jss-to-tss-react.test/expected-from-mui-styles.js +57 -0
  16. package/node/v5.0.0/jss-to-tss-react.test/expected-mixins-pattern.js +54 -0
  17. package/node/v5.0.0/jss-to-tss-react.test/expected-todo-comments.js +86 -0
  18. package/node/v5.0.0/jss-to-tss-react.test/expected-typescript-docs-example-params.js +61 -0
  19. package/node/v5.0.0/jss-to-tss-react.test/expected-typescript-docs-example.js +54 -0
  20. package/node/v5.0.0/jss-to-tss-react.test/expected-typescript.js +79 -0
  21. package/node/v5.0.0/jss-to-tss-react.test/expected-withStyles.js +124 -0
  22. package/package.json +1 -1
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = ComponentUsingStyles;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _react = _interopRequireDefault(require("react"));
13
+
14
+ var _mui = require("tss-react/mui");
15
+
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+
18
+ function mixins() {
19
+ return {
20
+ test: {
21
+ backgroundColor: "purple",
22
+ color: "white"
23
+ }
24
+ };
25
+ }
26
+
27
+ function cssProps() {
28
+ return {
29
+ paddingLeft: "8px"
30
+ };
31
+ }
32
+
33
+ const useStyles = (0, _mui.makeStyles)()(theme => {
34
+ return mixins();
35
+ });
36
+ const useStyles2 = (0, _mui.makeStyles)()(theme => (0, _extends2.default)({}, mixins(), {
37
+ test2: (0, _extends2.default)({
38
+ color: "red"
39
+ }, cssProps())
40
+ }));
41
+
42
+ function ComponentUsingStyles(props) {
43
+ const {
44
+ classes,
45
+ cx
46
+ } = useStyles();
47
+ const {
48
+ classes: classes2
49
+ } = useStyles2();
50
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
51
+ className: cx(classes.test, classes2.test2),
52
+ children: "Test"
53
+ });
54
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useExportedStyles = exports.default = void 0;
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _mui = require("tss-react/mui");
13
+
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+
16
+ var _InnerComponent;
17
+
18
+ // TODO jss-to-tss-react codemod: Unable to handle style definition reliably. ArrowFunctionExpression in CSS prop.
19
+ const useStyles = (0, _mui.makeStyles)()((_theme, _params, classes) => ({
20
+ test: {
21
+ backgroundColor: "purple",
22
+ color: "white",
23
+ [`&.${classes.qualifier}`]: {
24
+ textDecoration: props => props.textDecoration
25
+ }
26
+ },
27
+ qualifier: {}
28
+ })); // TODO jss-to-tss-react codemod: usages of this hook outside of this file will not be converted.
29
+
30
+ const useExportedStyles = (0, _mui.makeStyles)()({
31
+ test: {
32
+ backgroundColor: "purple",
33
+ color: "white"
34
+ }
35
+ }); // TODO jss-to-tss-react codemod: Unable to handle style definition reliably. Unsupported arrow function syntax.
36
+ // Arrow function has parameter type of Identifier instead of ObjectPattern (e.g. `(props) => ({...})` instead of `({color}) => ({...})`).
37
+
38
+ exports.useExportedStyles = useExportedStyles;
39
+ const useStyles2 = (0, _mui.makeStyles)()({
40
+ test2: props => ({
41
+ backgroundColor: "blue",
42
+ color: "lime"
43
+ })
44
+ }); // TODO jss-to-tss-react codemod: Unable to handle style definition reliably. Unsupported arrow function syntax.
45
+ // Arrow function has body type of BlockStatement instead of ObjectExpression.
46
+
47
+ const useStyles3 = (0, _mui.makeStyles)()({
48
+ test3: props => {
49
+ return {
50
+ backgroundColor: "blue",
51
+ color: "lime"
52
+ };
53
+ }
54
+ });
55
+
56
+ function InnerComponent() {
57
+ const {
58
+ classes
59
+ } = useStyles2();
60
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
61
+ className: classes.test2,
62
+ children: "Inner Test"
63
+ });
64
+ }
65
+
66
+ function ComponentUsingStyles(props) {
67
+ const {
68
+ classes,
69
+ cx
70
+ } = useStyles(props, {
71
+ props: props
72
+ });
73
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
74
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
75
+ className: classes.test,
76
+ children: ["Test", _InnerComponent || (_InnerComponent = /*#__PURE__*/(0, _jsxRuntime.jsx)(InnerComponent, {}))]
77
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
78
+ className: cx(classes.test, classes.qualifier),
79
+ children: "Qualifier Test"
80
+ })]
81
+ });
82
+ } // TODO jss-to-tss-react codemod: usages of this hook outside of this file will not be converted.
83
+
84
+
85
+ var _default = useStyles3;
86
+ exports.default = _default;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _mui = require("tss-react/mui");
9
+
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+
12
+ const useStyles = (0, _mui.makeStyles)({
13
+ name: 'App'
14
+ })((theme, {
15
+ color,
16
+ padding
17
+ }, classes) => ({
18
+ root: {
19
+ padding: padding,
20
+ [`&:hover .${classes.child}`]: {
21
+ backgroundColor: theme.palette[color].main
22
+ }
23
+ },
24
+ small: {},
25
+ child: {
26
+ border: '1px solid black',
27
+ height: 50,
28
+ [`&.${classes.small}`]: {
29
+ height: 30
30
+ }
31
+ }
32
+ }));
33
+
34
+ function App({
35
+ classes: classesProp
36
+ }) {
37
+ const {
38
+ classes,
39
+ cx
40
+ } = useStyles({
41
+ color: 'primary',
42
+ padding: 30
43
+ }, {
44
+ props: {
45
+ classes: classesProp
46
+ }
47
+ });
48
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
49
+ className: classes.root,
50
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
51
+ className: classes.child,
52
+ children: "The Background take the primary theme color when the mouse hovers the parent."
53
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
54
+ className: cx(classes.child, classes.small),
55
+ children: "The Background take the primary theme color when the mouse hovers the parent. I am smaller than the other child."
56
+ })]
57
+ });
58
+ }
59
+
60
+ var _default = App;
61
+ exports.default = _default;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ var _mui = require("tss-react/mui");
11
+
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+
18
+ const useStyles = (0, _mui.makeStyles)()((theme, _params, classes) => ({
19
+ parent: {
20
+ padding: 30,
21
+ [`&:hover .${classes.child}`]: {
22
+ backgroundColor: 'red'
23
+ }
24
+ },
25
+ small: {},
26
+ child: {
27
+ backgroundColor: 'blue',
28
+ height: 50,
29
+ [`&.${classes.small}`]: {
30
+ backgroundColor: 'lightblue',
31
+ height: 30
32
+ }
33
+ }
34
+ }));
35
+
36
+ function App() {
37
+ const {
38
+ classes,
39
+ cx
40
+ } = useStyles();
41
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
42
+ className: classes.parent,
43
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
44
+ className: classes.child,
45
+ children: "Background turns red when the mouse hovers over the parent."
46
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
47
+ className: cx(classes.child, classes.small),
48
+ children: "Background turns red when the mouse hovers over the parent. I am smaller than the other child."
49
+ })]
50
+ });
51
+ }
52
+
53
+ var _default = App;
54
+ exports.default = _default;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MergeClassesNoParams = MergeClassesNoParams;
7
+ exports.default = ComponentUsingStyles;
8
+
9
+ var React = _interopRequireWildcard(require("react"));
10
+
11
+ var _mui = require("tss-react/mui");
12
+
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+
15
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
+
17
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
+
19
+ /*
20
+ Sandboxes for verifying correct behavior:
21
+ JSS - https://codesandbox.io/s/typescript-case-bt065c?file=/demo.tsx
22
+ TSS - https://codesandbox.io/s/typescript-case-7jwpms?file=/demo.tsx
23
+ */
24
+ const useStyles = (0, _mui.makeStyles)()((theme, _params, classes) => ({
25
+ test: {
26
+ backgroundColor: "purple",
27
+ color: "white",
28
+ [`& .${classes.test2}`]: {
29
+ backgroundColor: "lime",
30
+ color: "blue"
31
+ }
32
+ },
33
+ test2: {
34
+ backgroundColor: "blue",
35
+ color: "lime"
36
+ }
37
+ }));
38
+
39
+ function MergeClassesNoParams({
40
+ classes: classesProp
41
+ }) {
42
+ const {
43
+ classes
44
+ } = useStyles(undefined, {
45
+ props: {
46
+ classes: classesProp
47
+ }
48
+ });
49
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
50
+ className: classes.test,
51
+ children: "Test useStyles without params but with classes prop"
52
+ });
53
+ }
54
+
55
+ function InnerComponent({
56
+ classes
57
+ }) {
58
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
59
+ className: classes.test2,
60
+ children: "Inner Test2"
61
+ });
62
+ }
63
+
64
+ function ComponentUsingStyles() {
65
+ const {
66
+ classes
67
+ } = useStyles();
68
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
69
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
70
+ className: classes.test,
71
+ children: ["Test", /*#__PURE__*/(0, _jsxRuntime.jsx)(InnerComponent, {
72
+ classes: classes
73
+ })]
74
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
75
+ className: classes.test2,
76
+ children: "Outer Test2"
77
+ })]
78
+ });
79
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = App;
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _mui = require("tss-react/mui");
13
+
14
+ var _clsx = _interopRequireDefault(require("clsx"));
15
+
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+
18
+ var _StyledComp, _StyledComp2, _StyledComp3a, _StyledComp3b, _StyledComp3c;
19
+
20
+ const styles1 = {
21
+ test: {
22
+ backgroundColor: "purple",
23
+ color: "white"
24
+ }
25
+ };
26
+
27
+ function Comp1({
28
+ classes
29
+ }) {
30
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
31
+ className: classes.test,
32
+ children: "Comp1"
33
+ });
34
+ }
35
+
36
+ const StyledComp1 = (0, _mui.withStyles)(Comp1, styles1);
37
+
38
+ const styles2 = (_theme, _params, classes) => ({
39
+ test: {
40
+ backgroundColor: "black",
41
+ color: "lime"
42
+ },
43
+ test2: {
44
+ backgroundColor: "white",
45
+ color: "purple",
46
+ [`&.${classes.test}`]: {
47
+ backgroundColor: "pink",
48
+ color: "blue"
49
+ }
50
+ }
51
+ });
52
+
53
+ function Comp2({
54
+ classes
55
+ }) {
56
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
57
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
58
+ className: classes.test,
59
+ children: "Comp2 test"
60
+ }), _StyledComp || (_StyledComp = /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledComp1, {})), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
61
+ className: classes.test2,
62
+ children: "Comp2 test2"
63
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
64
+ className: (0, _clsx.default)(classes.test, classes.test2),
65
+ children: "Comp2 test and test2"
66
+ })]
67
+ });
68
+ }
69
+
70
+ const StyledComp2 = (0, _mui.withStyles)(Comp2, styles2);
71
+
72
+ function Comp3({
73
+ classes
74
+ }) {
75
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
76
+ className: classes.test,
77
+ children: ["Inline Styles", /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
78
+ className: classes.test2,
79
+ children: "Nested Inline Styles"
80
+ })]
81
+ });
82
+ }
83
+
84
+ const StyledComp3a = (0, _mui.withStyles)(Comp3, {
85
+ test: {
86
+ backgroundColor: "yellow"
87
+ }
88
+ });
89
+ const StyledComp3b = (0, _mui.withStyles)(Comp3, (_theme, _params, classes) => ({
90
+ test: {
91
+ backgroundColor: "yellow",
92
+ color: "lime",
93
+ [`& .${classes.test2}`]: {
94
+ backgroundColor: "orange"
95
+ }
96
+ },
97
+ test2: {}
98
+ }));
99
+
100
+ const styles3c = (theme, _params, classes) => {
101
+ const bgColor1 = theme.palette.primary.main;
102
+ const color1 = theme.palette.primary.contrastText;
103
+ const bgColor2 = theme.palette.secondary.main;
104
+ const color2 = theme.palette.secondary.contrastText;
105
+ return {
106
+ test: {
107
+ backgroundColor: bgColor1,
108
+ color: color1,
109
+ [`& .${classes.test2}`]: {
110
+ backgroundColor: bgColor2,
111
+ color: color2
112
+ }
113
+ },
114
+ test2: {}
115
+ };
116
+ };
117
+
118
+ const StyledComp3c = (0, _mui.withStyles)(Comp3, styles3c);
119
+
120
+ function App() {
121
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
122
+ children: [_StyledComp2 || (_StyledComp2 = /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledComp2, {})), _StyledComp3a || (_StyledComp3a = /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledComp3a, {})), _StyledComp3b || (_StyledComp3b = /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledComp3b, {})), _StyledComp3c || (_StyledComp3c = /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledComp3c, {}))]
123
+ });
124
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "5.7.0",
3
+ "version": "5.8.0",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",