@mui/codemod 6.0.0-alpha.1 → 6.0.0-alpha.3

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 (56) hide show
  1. package/README.md +153 -2
  2. package/node/deprecations/accordion-props/accordion-props.js +11 -71
  3. package/node/deprecations/accordion-props/test-cases/actual.js +16 -0
  4. package/node/deprecations/accordion-props/test-cases/expected.js +14 -0
  5. package/node/deprecations/accordion-props/test-cases/theme.actual.js +24 -0
  6. package/node/deprecations/accordion-props/test-cases/theme.expected.js +24 -0
  7. package/node/deprecations/all/deprecations-all.js +4 -0
  8. package/node/deprecations/all/postcss.config.js +7 -1
  9. package/node/deprecations/avatar-props/avatar-props.js +5 -39
  10. package/node/deprecations/avatar-props/test-cases/actual.js +10 -0
  11. package/node/deprecations/avatar-props/test-cases/expected.js +10 -0
  12. package/node/deprecations/avatar-props/test-cases/theme.actual.js +14 -0
  13. package/node/deprecations/avatar-props/test-cases/theme.expected.js +15 -0
  14. package/node/deprecations/backdrop-props/backdrop-props.js +5 -61
  15. package/node/deprecations/backdrop-props/test-cases/actual.js +8 -7
  16. package/node/deprecations/backdrop-props/test-cases/expected.js +7 -7
  17. package/node/deprecations/backdrop-props/test-cases/theme.actual.js +11 -0
  18. package/node/deprecations/backdrop-props/test-cases/theme.expected.js +12 -2
  19. package/node/deprecations/step-connector-classes/index.js +13 -0
  20. package/node/deprecations/step-connector-classes/postcss-plugin.js +33 -0
  21. package/node/deprecations/step-connector-classes/postcss.config.js +8 -0
  22. package/node/deprecations/step-connector-classes/step-connector-classes.js +77 -0
  23. package/node/deprecations/step-connector-classes/test-cases/actual.js +7 -0
  24. package/node/deprecations/step-connector-classes/test-cases/expected.js +7 -0
  25. package/node/deprecations/step-label-props/step-label-props.js +14 -0
  26. package/node/deprecations/step-label-props/test-cases/actual.js +23 -0
  27. package/node/deprecations/step-label-props/test-cases/expected.js +24 -0
  28. package/node/deprecations/step-label-props/test-cases/theme.actual.js +22 -0
  29. package/node/deprecations/step-label-props/test-cases/theme.expected.js +25 -0
  30. package/node/deprecations/toggle-button-group-classes/index.js +13 -0
  31. package/node/deprecations/toggle-button-group-classes/postcss-plugin.js +33 -0
  32. package/node/deprecations/toggle-button-group-classes/postcss.config.js +8 -0
  33. package/node/deprecations/toggle-button-group-classes/test-cases/actual.js +7 -0
  34. package/node/deprecations/toggle-button-group-classes/test-cases/expected.js +7 -0
  35. package/node/deprecations/toggle-button-group-classes/toggle-button-group-classes.js +77 -0
  36. package/node/deprecations/utils/movePropIntoSlotProps.js +111 -0
  37. package/node/deprecations/utils/movePropIntoSlots.js +101 -0
  38. package/node/v5.0.0/base-remove-unstyled-suffix.js +4 -4
  39. package/node/v5.0.0/styled-engine-provider.test/theme-provider.expected.js +3 -3
  40. package/node/v6.0.0/styled/index.js +13 -0
  41. package/node/v6.0.0/styled/styled-v6.js +478 -0
  42. package/node/v6.0.0/styled/test-cases/BasicStyled.actual.js +54 -0
  43. package/node/v6.0.0/styled/test-cases/BasicStyled.expected.js +104 -0
  44. package/node/v6.0.0/styled/test-cases/ConditionalStyled.actual.js +115 -0
  45. package/node/v6.0.0/styled/test-cases/ConditionalStyled.expected.js +206 -0
  46. package/node/v6.0.0/styled/test-cases/LogicalStyled.actual.js +28 -0
  47. package/node/v6.0.0/styled/test-cases/LogicalStyled.expected.js +52 -0
  48. package/node/v6.0.0/styled/test-cases/NestedSpread.actual.js +42 -0
  49. package/node/v6.0.0/styled/test-cases/NestedSpread.expected.js +85 -0
  50. package/node/v6.0.0/styled/test-cases/ObjectMap.actual.js +36 -0
  51. package/node/v6.0.0/styled/test-cases/ObjectMap.expected.js +109 -0
  52. package/node/v6.0.0/styled/test-cases/ThemePaletteMode.actual.js +62 -0
  53. package/node/v6.0.0/styled/test-cases/ThemePaletteMode.expected.js +76 -0
  54. package/node/v6.0.0/styled/test-cases/VariantAndModeStyled.actual.js +11 -0
  55. package/node/v6.0.0/styled/test-cases/VariantAndModeStyled.expected.js +19 -0
  56. package/package.json +3 -3
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = movePropIntoSlots;
8
+ var _findComponentJSX = _interopRequireDefault(require("../../util/findComponentJSX"));
9
+ var _findComponentDefaultProps = _interopRequireDefault(require("../../util/findComponentDefaultProps"));
10
+ var _assignObject = _interopRequireDefault(require("../../util/assignObject"));
11
+ var _appendAttribute = _interopRequireDefault(require("../../util/appendAttribute"));
12
+ function moveJsxPropIntoSlots(j, element, propName, slotName) {
13
+ const index = element.openingElement.attributes.findIndex(attr => attr.type === 'JSXAttribute' && attr.name.name === propName);
14
+ if (index !== -1) {
15
+ const removedValue = element.openingElement.attributes.splice(index, 1)[0].value.expression;
16
+ let hasSlots = false;
17
+ element.openingElement.attributes.forEach(attr => {
18
+ var _attr$name;
19
+ if (((_attr$name = attr.name) == null ? void 0 : _attr$name.name) === 'slots') {
20
+ hasSlots = true;
21
+ const slotIndex = attr.value.expression.properties.findIndex(prop => {
22
+ var _prop$key;
23
+ return (prop == null || (_prop$key = prop.key) == null ? void 0 : _prop$key.name) === slotName;
24
+ });
25
+ if (slotIndex === -1) {
26
+ (0, _assignObject.default)(j, {
27
+ target: attr,
28
+ key: slotName,
29
+ expression: removedValue
30
+ });
31
+ }
32
+ }
33
+ });
34
+ if (!hasSlots) {
35
+ (0, _appendAttribute.default)(j, {
36
+ target: element,
37
+ attributeName: 'slots',
38
+ expression: j.objectExpression([j.objectProperty(j.identifier(slotName), removedValue)])
39
+ });
40
+ }
41
+ }
42
+ }
43
+ function moveDefaultPropsPropIntoSlots(j, defaultPropsPathCollection, propName, slotName) {
44
+ defaultPropsPathCollection.find(j.ObjectProperty, {
45
+ key: {
46
+ name: propName
47
+ }
48
+ }).forEach(path => {
49
+ const removedValue = path.value.value;
50
+ const defaultProps = path.parent.value;
51
+ let hasSlots = false;
52
+ defaultProps.properties.forEach(property => {
53
+ var _property$key;
54
+ if (((_property$key = property.key) == null ? void 0 : _property$key.name) === 'slots') {
55
+ hasSlots = true;
56
+ const slots = property.value;
57
+ const slotIndex = slots.properties.findIndex(prop => {
58
+ var _prop$key2;
59
+ return (prop == null || (_prop$key2 = prop.key) == null ? void 0 : _prop$key2.name) === slotName;
60
+ });
61
+ if (slotIndex === -1) {
62
+ slots.properties.push(j.objectProperty(j.identifier(slotName), removedValue));
63
+ }
64
+ }
65
+ });
66
+ if (!hasSlots) {
67
+ defaultProps.properties.push(j.property('init', j.identifier('slots'), j.objectExpression([j.objectProperty(j.identifier(slotName), removedValue)])));
68
+ }
69
+ path.prune();
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Moves prop into slots.
75
+ * If the slots prop exists, it will add the prop to the slots.
76
+ * If there are duplicated values, the slots values will be used.
77
+ *
78
+ * @param {import('jscodeshift')} j
79
+ * @param {{ root: import('jscodeshift').Collection; componentName: string, propName: string, slotName: string }} options
80
+ *
81
+ * @example <Component TransitionComponent={CustomTransition} /> => <Component slots={{ transition: CustomTransition }} />
82
+ */
83
+ function movePropIntoSlots(j, options) {
84
+ const {
85
+ root,
86
+ componentName,
87
+ propName,
88
+ slotName
89
+ } = options;
90
+ (0, _findComponentJSX.default)(j, {
91
+ root,
92
+ componentName
93
+ }, elementPath => {
94
+ moveJsxPropIntoSlots(j, elementPath.node, propName, slotName);
95
+ });
96
+ const defaultPropsPathCollection = (0, _findComponentDefaultProps.default)(j, {
97
+ root,
98
+ componentName
99
+ });
100
+ moveDefaultPropsPropIntoSlots(j, defaultPropsPathCollection, propName, slotName);
101
+ }
@@ -15,12 +15,12 @@ function transformer(file, api) {
15
15
  node
16
16
  }) => {
17
17
  const sourceVal = node.source.value;
18
- if (sourceVal.startsWith('@mui/base')) {
19
- node.source.value = sourceVal.replace(/unstyled/im, '');
20
- node.source.raw = sourceVal.replace(/unstyled/im, '');
21
- }
22
18
  return sourceVal.startsWith('@mui/base');
23
19
  }).forEach(path => {
20
+ const sourceVal = path.node.source.value;
21
+ if (sourceVal.startsWith('@mui/base')) {
22
+ path.node.source = j.stringLiteral(sourceVal.replace(/unstyled/im, ''));
23
+ }
24
24
  const specifiers = [];
25
25
  path.node.specifiers.forEach(elementNode => {
26
26
  var _elementNode$imported;
@@ -14,14 +14,14 @@ var _OtherProvider;
14
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
15
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
16
  const App = () => {
17
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.StyledEngineProvider, {
17
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.StyledEngineProvider, {
18
18
  injectFirst: true,
19
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.ThemeProvider, {
19
+ children: ["(", /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.ThemeProvider, {
20
20
  theme: (0, _styles.createTheme)(),
21
21
  children: _OtherProvider || (_OtherProvider = /*#__PURE__*/(0, _jsxRuntime.jsx)(_contexts.OtherProvider, {
22
22
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_pages.default, {})
23
23
  }))
24
- })
24
+ }), ")"]
25
25
  });
26
26
  };
27
27
  var _default = exports.default = App;
@@ -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 _styledV.default;
11
+ }
12
+ });
13
+ var _styledV = _interopRequireDefault(require("./styled-v6"));
@@ -0,0 +1,478 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = styledV6;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ const MAX_DEPTH = 20;
10
+
11
+ /**
12
+ * @param {import('jscodeshift').FileInfo} file
13
+ * @param {import('jscodeshift').API} api
14
+ */
15
+ function styledV6(file, api, options) {
16
+ const j = api.jscodeshift;
17
+ const root = j(file.source);
18
+ const printOptions = options.printOptions;
19
+
20
+ /**
21
+ *
22
+ * @param {import('ast-types').namedTypes.MemberExpression | import('ast-types').namedTypes.Identifier} node
23
+ */
24
+ function getIdentifierKey(node) {
25
+ if (node.type === 'MemberExpression') {
26
+ return node.property;
27
+ }
28
+ return node;
29
+ }
30
+
31
+ /**
32
+ *
33
+ * @param {import('ast-types').namedTypes.UnaryExpression | import('ast-types').namedTypes.MemberExpression | import('ast-types').namedTypes.Identifier} node
34
+ */
35
+ function getObjectKey(node) {
36
+ let tempNode = (0, _extends2.default)({}, node);
37
+ while (tempNode.type === 'UnaryExpression') {
38
+ tempNode = tempNode.argument;
39
+ }
40
+ while (tempNode.type === 'MemberExpression') {
41
+ tempNode = tempNode.object;
42
+ }
43
+ return tempNode;
44
+ }
45
+
46
+ /**
47
+ *
48
+ * @param {import('ast-types').namedTypes.ObjectExpression} objectExpression
49
+ * @param {import('ast-types').namedTypes.BinaryExpression} addtional
50
+ */
51
+ function objectToArrowFunction(objectExpression, addtional) {
52
+ const paramKeys = new Set();
53
+ let left;
54
+ objectExpression.properties.forEach((prop, index) => {
55
+ paramKeys.add(prop.key.name);
56
+ const result = j.binaryExpression('===', prop.key, prop.value);
57
+ if (index === 0) {
58
+ left = result;
59
+ } else {
60
+ left = j.logicalExpression('&&', left, result);
61
+ }
62
+ });
63
+ if (addtional) {
64
+ paramKeys.add(getObjectKey(addtional.left).name);
65
+ }
66
+ return buildArrowFunctionAST(paramKeys, addtional ? j.logicalExpression('&&', left, addtional) : left);
67
+ }
68
+
69
+ /**
70
+ *
71
+ * @param {import('ast-types').namedTypes.Identifier | import('ast-types').namedTypes.BinaryExpression | import('ast-types').namedTypes.UnaryExpression} node
72
+ */
73
+ function inverseBinaryExpression(node) {
74
+ if (node.type === 'Identifier') {
75
+ return j.unaryExpression('!', node);
76
+ }
77
+ if (node.operator === '===') {
78
+ return (0, _extends2.default)({}, node, {
79
+ operator: '!=='
80
+ });
81
+ }
82
+ if (node.operator === '!==') {
83
+ return (0, _extends2.default)({}, node, {
84
+ operator: '==='
85
+ });
86
+ }
87
+ if (node.operator === '!') {
88
+ var _node$argument;
89
+ if (((_node$argument = node.argument) == null ? void 0 : _node$argument.operator) === '!') {
90
+ return node.argument;
91
+ }
92
+ return j.unaryExpression('!', node);
93
+ }
94
+ return node;
95
+ }
96
+
97
+ /**
98
+ *
99
+ * @param {import('ast-types').namedTypes.ObjectExpression} node
100
+ */
101
+ function removeProperty(parentNode, child) {
102
+ if (parentNode) {
103
+ if (parentNode.type === 'ObjectExpression') {
104
+ parentNode.properties = parentNode.properties.filter(prop => prop !== child && prop.value !== child);
105
+ }
106
+ }
107
+ }
108
+ function buildObjectAST(jsObject) {
109
+ const result = j.objectExpression([]);
110
+ Object.entries(jsObject).forEach(([key, value]) => {
111
+ result.properties.push(j.objectProperty(j.identifier(key), value));
112
+ });
113
+ return result;
114
+ }
115
+ function buildArrowFunctionAST(params, body) {
116
+ return j.arrowFunctionExpression([j.objectPattern([...params].map(k => (0, _extends2.default)({}, j.objectProperty(j.identifier(k), j.identifier(k)), {
117
+ shorthand: true
118
+ })))], body);
119
+ }
120
+
121
+ /**
122
+ *
123
+ * @param {{ properties: any[] }} node
124
+ * @param {Record<string, any[]>} modeStyles
125
+ */
126
+ function appendPaletteModeStyles(node, modeStyles) {
127
+ Object.entries(modeStyles).forEach(([mode, objectStyles]) => {
128
+ node.properties.push(j.spreadElement(j.callExpression(j.memberExpression(j.identifier('theme'), j.identifier('applyStyles')), [j.stringLiteral(mode), j.objectExpression(objectStyles)])));
129
+ });
130
+ }
131
+
132
+ /**
133
+ *
134
+ * @param {import('ast-types').namedTypes.LogicalExpression | import('ast-types').namedTypes.BinaryExpression | import('ast-types').namedTypes.UnaryExpression | import('ast-types').namedTypes.MemberExpression} node
135
+ */
136
+ function buildProps(node) {
137
+ const properties = [];
138
+ const variables = new Set();
139
+ let isAllEqual = true;
140
+ let tempNode = (0, _extends2.default)({}, node);
141
+ function assignProperties(_node) {
142
+ if (_node.type === 'BinaryExpression') {
143
+ variables.add(getObjectKey(_node.left).name);
144
+ if (_node.operator === '===') {
145
+ properties.push(j.objectProperty(getIdentifierKey(_node.left), _node.right));
146
+ } else {
147
+ isAllEqual = false;
148
+ }
149
+ }
150
+ if (_node.type === 'MemberExpression' || _node.type === 'Identifier') {
151
+ isAllEqual = false;
152
+ variables.add(getObjectKey(_node).name);
153
+ }
154
+ if (_node.type === 'UnaryExpression') {
155
+ isAllEqual = false;
156
+ if (_node.argument.type === 'UnaryExpression') {
157
+ // handle `!!variable`
158
+ variables.add(getObjectKey(_node.argument.argument).name);
159
+ } else {
160
+ // handle `!variable`
161
+ variables.add(getObjectKey(_node.argument).name);
162
+ }
163
+ }
164
+ }
165
+ let counter = 0;
166
+ if (tempNode.type !== 'LogicalExpression') {
167
+ assignProperties(tempNode);
168
+ } else {
169
+ while (tempNode.type === 'LogicalExpression' && counter < MAX_DEPTH) {
170
+ counter += 1;
171
+ if (tempNode.operator !== '&&') {
172
+ isAllEqual = false;
173
+ }
174
+ assignProperties(tempNode.right);
175
+ if (tempNode.left.type !== 'LogicalExpression') {
176
+ assignProperties(tempNode.left);
177
+ break;
178
+ }
179
+ tempNode = (0, _extends2.default)({}, tempNode.left);
180
+ }
181
+ }
182
+ if (!isAllEqual) {
183
+ return buildArrowFunctionAST(variables, node);
184
+ }
185
+ return j.objectExpression(properties);
186
+ }
187
+ function mergeProps(parentProps, currentProps) {
188
+ if (parentProps.type === 'ObjectExpression' && currentProps.type === 'ObjectExpression') {
189
+ return j.objectExpression([...parentProps.properties, ...currentProps.properties]);
190
+ }
191
+ const parentArrow = parentProps.type === 'ObjectExpression' ? objectToArrowFunction(parentProps) : parentProps;
192
+ const currentArrow = currentProps.type === 'ObjectExpression' ? objectToArrowFunction(currentProps) : currentProps;
193
+ const variables = new Set();
194
+ [...parentArrow.params[0].properties, ...currentArrow.params[0].properties].forEach(param => {
195
+ variables.add(param.key.name);
196
+ });
197
+ return buildArrowFunctionAST(variables, j.logicalExpression('&&', parentArrow.body, currentArrow.body));
198
+ }
199
+ function isThemePaletteMode(node) {
200
+ return node.type === 'MemberExpression' && node.object.type === 'MemberExpression' && node.object.object.name === 'theme' && node.object.property.name === 'palette' && node.property.name === 'mode';
201
+ }
202
+ let shouldTransform = false;
203
+ root.find(j.CallExpression).forEach(path => {
204
+ const styles = [];
205
+ let args = [];
206
+
207
+ // styled('div')(...arguments)
208
+ if (path.node.callee.type === 'Identifier' && path.node.callee.name === 'styled' && path.parentPath.node.type === 'CallExpression') {
209
+ args = path.parentPath.node.arguments;
210
+ }
211
+
212
+ // styled.div(...arguments)
213
+ if (path.node.callee.type === 'MemberExpression' && path.node.callee.object.type === 'Identifier' && path.node.callee.object.name === 'styled') {
214
+ args = path.node.arguments;
215
+ }
216
+
217
+ // 1. collecting styles that should be tranformed
218
+ args.forEach(arg => {
219
+ if (arg.type === 'ArrowFunctionExpression' && arg.params[0] && arg.params[0].type === 'ObjectPattern') {
220
+ styles.push(arg);
221
+ }
222
+ });
223
+ if (!shouldTransform && styles.length > 0) {
224
+ shouldTransform = true;
225
+ }
226
+
227
+ // 2. Find logical spread expressions to convert to variants
228
+ styles.forEach(style => {
229
+ const parameters = new Set();
230
+ style.params.forEach(param => {
231
+ if (param.type === 'ObjectPattern') {
232
+ param.properties.forEach(prop => {
233
+ parameters.add(prop.key.name);
234
+ });
235
+ }
236
+ });
237
+ const variants = [];
238
+ if (style.body.type === 'LogicalExpression') {
239
+ if (style.params[0] && style.params[0].type === 'ObjectPattern' && style.params[0].properties.some(prop => prop.key.name !== 'theme')) {
240
+ // case: ({ theme, ownerState }) => ownerState.variant === 'regular' && theme.mixins.toolbar
241
+ style.body = j.objectExpression([j.objectProperty(j.identifier('variants'), j.arrayExpression([j.objectExpression([j.objectProperty(j.identifier('props'), buildProps(style.body.left)), j.objectProperty(j.identifier('style'), style.body.right)])]))]);
242
+ }
243
+ } else if (style.body.type === 'ConditionalExpression') {
244
+ // skip ConditionalExpression
245
+ } else {
246
+ let objectExpression = style.body;
247
+ let counter = 0;
248
+ while (objectExpression.type !== 'ObjectExpression' && counter < MAX_DEPTH) {
249
+ counter += 1;
250
+ if (objectExpression.type === 'BlockStatement') {
251
+ objectExpression = objectExpression.body.find(item => item.type === 'ReturnStatement').argument;
252
+ }
253
+ }
254
+ recurseObjectExpression({
255
+ node: objectExpression
256
+ });
257
+ if (variants.length) {
258
+ objectExpression.properties.push(j.objectProperty(j.identifier('variants'), j.arrayExpression(variants.filter(variant => {
259
+ const props = variant.properties.find(prop => prop.key.name === 'props');
260
+ const styleVal = variant.properties.find(prop => prop.key.name === 'style');
261
+ return props && styleVal && styleVal.value.properties.length > 0 && (props.value.type === 'ArrowFunctionExpression' || props.value.properties.length > 0);
262
+ }))));
263
+ }
264
+ }
265
+ function recurseObjectExpression(data) {
266
+ if (data.node.type === 'ObjectExpression') {
267
+ const modeStyles = {}; // to collect styles from `theme.palette.mode === '...'`
268
+ data.node.properties.forEach(prop => {
269
+ if (prop.type === 'ObjectProperty') {
270
+ recurseObjectExpression((0, _extends2.default)({}, data, {
271
+ node: prop.value,
272
+ parentNode: data.node,
273
+ key: prop.key,
274
+ replaceValue: newValue => {
275
+ prop.value = newValue;
276
+ },
277
+ modeStyles
278
+ }));
279
+ } else {
280
+ recurseObjectExpression((0, _extends2.default)({}, data, {
281
+ node: prop,
282
+ parentNode: data.node
283
+ }));
284
+ }
285
+ });
286
+ appendPaletteModeStyles(data.node, modeStyles);
287
+ }
288
+ if (data.node.type === 'SpreadElement') {
289
+ if (data.node.argument.type === 'LogicalExpression') {
290
+ var _getObjectKey;
291
+ const paramName = (_getObjectKey = getObjectKey(data.node.argument.left)) == null ? void 0 : _getObjectKey.name;
292
+ if (paramName && !parameters.has(paramName)) {
293
+ return;
294
+ }
295
+ const scopeProps = buildProps(data.node.argument.left);
296
+ const variant = {
297
+ props: data.props ? mergeProps(data.props, scopeProps) : scopeProps,
298
+ style: data.node.argument.right
299
+ };
300
+ const modeStyles = {}; // to collect styles from `theme.palette.mode === '...'`
301
+ variant.style.properties.forEach(prop => {
302
+ if (prop.type === 'ObjectProperty') {
303
+ recurseObjectExpression((0, _extends2.default)({}, data, {
304
+ node: prop.value,
305
+ parentNode: variant.style,
306
+ props: variant.props,
307
+ key: prop.key,
308
+ replaceValue: newValue => {
309
+ prop.value = newValue;
310
+ },
311
+ modeStyles
312
+ }));
313
+ } else {
314
+ recurseObjectExpression((0, _extends2.default)({}, data, {
315
+ node: prop,
316
+ parentNode: variant.style,
317
+ props: variant.props
318
+ }));
319
+ }
320
+ });
321
+ appendPaletteModeStyles(variant.style, modeStyles);
322
+ variants.push(buildObjectAST(variant));
323
+ removeProperty(data.parentNode, data.node);
324
+ }
325
+ if (data.node.argument.type === 'ConditionalExpression') {
326
+ recurseObjectExpression((0, _extends2.default)({}, data, {
327
+ node: data.node.argument,
328
+ parentNode: data.node
329
+ }));
330
+ removeProperty(data.parentNode, data.node);
331
+ }
332
+ }
333
+ if (data.node.type === 'ConditionalExpression') {
334
+ if (data.node.test.type === 'BinaryExpression' || data.node.test.type === 'UnaryExpression' || data.node.test.type === 'Identifier') {
335
+ var _getObjectKey2, _data$parentNode2, _data$node$test;
336
+ let leftName = (_getObjectKey2 = getObjectKey(data.node.test)) == null ? void 0 : _getObjectKey2.name;
337
+ if (data.node.test.left) {
338
+ var _getObjectKey3;
339
+ leftName = (_getObjectKey3 = getObjectKey(data.node.test.left)) == null ? void 0 : _getObjectKey3.name;
340
+ }
341
+ if (data.node.test.argument) {
342
+ var _getObjectKey4;
343
+ leftName = (_getObjectKey4 = getObjectKey(data.node.test.argument)) == null ? void 0 : _getObjectKey4.name;
344
+ }
345
+ if (parameters.has(leftName) && leftName !== 'theme') {
346
+ var _data$parentNode;
347
+ let props = buildProps(data.node.test);
348
+ if (data.props) {
349
+ props = mergeProps(data.props, props);
350
+ }
351
+ const styleVal = data.node.consequent;
352
+ let newStyle = styleVal;
353
+ if (data.key && (data.key.type === 'Identifier' || data.key.type === 'StringLiteral')) {
354
+ newStyle = j.objectExpression([j.objectProperty(data.key, styleVal)]);
355
+ }
356
+ const variant = {
357
+ props,
358
+ style: newStyle
359
+ };
360
+ variants.push(buildObjectAST(variant));
361
+
362
+ // create another variant with inverted condition
363
+ let props2 = buildProps(inverseBinaryExpression(data.node.test));
364
+ if (data.props) {
365
+ props2 = mergeProps(data.props, props2);
366
+ }
367
+ const styleVal2 = data.node.alternate;
368
+ let newStyle2 = styleVal2;
369
+ if (data.key && (data.key.type === 'Identifier' || data.key.type === 'StringLiteral')) {
370
+ newStyle2 = j.objectExpression([j.objectProperty(data.key, styleVal2)]);
371
+ }
372
+ const variant2 = {
373
+ props: props2,
374
+ style: newStyle2
375
+ };
376
+ variants.push(buildObjectAST(variant2));
377
+ if (((_data$parentNode = data.parentNode) == null ? void 0 : _data$parentNode.type) === 'ObjectExpression') {
378
+ removeProperty(data.parentNode, data.node);
379
+ }
380
+ }
381
+ if (leftName === 'theme' && ((_data$parentNode2 = data.parentNode) == null ? void 0 : _data$parentNode2.type) === 'ObjectExpression' && ((_data$node$test = data.node.test) == null ? void 0 : _data$node$test.type) === 'BinaryExpression' && isThemePaletteMode(data.node.test.left)) {
382
+ if (data.node.consequent.type !== 'ObjectExpression' && data.node.alternate.type !== 'ObjectExpression') {
383
+ var _data$replaceValue;
384
+ if (data.modeStyles) {
385
+ if (!data.modeStyles[data.node.test.right.value]) {
386
+ data.modeStyles[data.node.test.right.value] = [];
387
+ }
388
+ data.modeStyles[data.node.test.right.value].push(j.objectProperty(data.key, data.node.consequent));
389
+ }
390
+ (_data$replaceValue = data.replaceValue) == null || _data$replaceValue.call(data, data.node.alternate);
391
+ }
392
+ }
393
+ }
394
+ }
395
+ if (data.node.type === 'TemplateLiteral') {
396
+ var _data$parentNode3;
397
+ if (((_data$parentNode3 = data.parentNode) == null ? void 0 : _data$parentNode3.type) === 'ObjectExpression') {
398
+ const modeStyles = {};
399
+ data.node.expressions.forEach((expression, index) => {
400
+ recurseObjectExpression((0, _extends2.default)({}, data, {
401
+ node: expression,
402
+ parentNode: data.parentNode,
403
+ key: data.key,
404
+ replaceValue: newValue => {
405
+ data.node.expressions[index] = newValue;
406
+ },
407
+ modeStyles
408
+ }));
409
+ });
410
+ if (data.modeStyles) {
411
+ Object.entries(modeStyles).forEach(([mode, objectStyles]) => {
412
+ const clonedNode = (0, _extends2.default)({}, data.node, {
413
+ expressions: data.node.expressions.map(expression => (0, _extends2.default)({}, expression))
414
+ });
415
+ clonedNode.expressions = objectStyles.map(item => item.value);
416
+ if (!data.modeStyles[mode]) {
417
+ data.modeStyles[mode] = [];
418
+ }
419
+ data.modeStyles[mode].push(j.objectProperty(data.key, clonedNode));
420
+ });
421
+ }
422
+ }
423
+ }
424
+ if (data.key && data.key.type === 'Identifier' && data.node.type === 'MemberExpression' && data.node.object.type === 'ObjectExpression' && parameters.has(getObjectKey(data.node.property).name)) {
425
+ data.node.object.properties.forEach(prop => {
426
+ variants.push(buildObjectAST({
427
+ props: j.objectExpression([j.objectProperty(getIdentifierKey(data.node.property), j.stringLiteral(prop.key.name))]),
428
+ style: j.objectExpression([j.objectProperty(data.key, prop.value)])
429
+ }));
430
+ });
431
+ removeProperty(data.parentNode, data.node);
432
+ }
433
+ }
434
+ style.params.forEach(param => {
435
+ if (param.type === 'ObjectPattern') {
436
+ param.properties = param.properties.filter(prop => prop.key.name === 'theme');
437
+ }
438
+ });
439
+ });
440
+
441
+ // Replace arrow function with object expression if the arg properties is empty
442
+ args.forEach((arg, index) => {
443
+ if (arg.type === 'ArrowFunctionExpression' && arg.params[0] && arg.params[0].type === 'ObjectPattern' && arg.params[0].properties.length === 0) {
444
+ if (arg.body.type === 'ObjectExpression') {
445
+ args[index] = arg.body;
446
+ }
447
+ if (arg.body.type === 'BlockStatement') {
448
+ const returnStatement = arg.body.body.find(item => item.type === 'ReturnStatement');
449
+ if (returnStatement) {
450
+ args[index] = returnStatement.argument;
451
+ }
452
+ }
453
+ }
454
+ });
455
+ });
456
+ const transformed = root.toSource(printOptions);
457
+ if (shouldTransform) {
458
+ // recast adds extra newlines that we don't want, https://github.com/facebook/jscodeshift/issues/249
459
+ // need to remove them manually
460
+ const lines = [];
461
+ let isInStyled = false;
462
+ transformed.split('\n').forEach((line, index, array) => {
463
+ if (!isInStyled) {
464
+ lines.push(line);
465
+ } else if (line !== '' || line === '' && array[index + 1] && array[index + 1].includes('return')) {
466
+ if (line.match(/^}\)+(\({}\)|\(\))?;?$/) || line.match(/^\);?$/)) {
467
+ isInStyled = false;
468
+ }
469
+ lines.push(line);
470
+ }
471
+ if (line.includes('styled.') || line.includes('styled(')) {
472
+ isInStyled = true;
473
+ }
474
+ });
475
+ return lines.join('\n');
476
+ }
477
+ return transformed;
478
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
5
+ const FormHelperTextRoot = styled('p')(({
6
+ theme,
7
+ ownerState,
8
+ disabled
9
+ }) => (0, _extends2.default)({
10
+ color: (theme.vars || theme).palette.text.secondary
11
+ }, theme.typography.caption, {
12
+ textAlign: 'left',
13
+ [`&.${formHelperTextClasses.disabled}`]: {
14
+ color: (theme.vars || theme).palette.text.disabled
15
+ }
16
+ }, ownerState.size === 'small' && {
17
+ marginTop: 4
18
+ }, ownerState.size === 'small' && ownerState.variant === 'contained' && {
19
+ marginTop: 6
20
+ }, ownerState.size === 'small' && ownerState.variant === 'contained' && disabled && {
21
+ marginTop: 6
22
+ }, ownerState.size !== 'small' && {
23
+ marginBottom: 4
24
+ }, ownerState.size !== 'small' && ownerState.variant !== 'contained' && !disabled && {
25
+ marginBottom: 6
26
+ }, ownerState.contained && {
27
+ marginLeft: 14,
28
+ marginRight: 14
29
+ }, !ownerState.contained && {
30
+ marginTop: 14,
31
+ marginBottom: 14
32
+ }, !!ownerState.disabled && {
33
+ opacity: 0.5
34
+ }));
35
+ const Component = styled.div(({
36
+ theme,
37
+ ownerState
38
+ }) => (0, _extends2.default)({}, theme.typography.caption, ownerState.size === 'small' && {
39
+ marginTop: (theme.vars || theme).spacing(1)
40
+ }));
41
+ const ImageListRoot = styled('ul')(({
42
+ ownerState
43
+ }) => {
44
+ return (0, _extends2.default)({
45
+ display: 'grid',
46
+ overflowY: 'auto',
47
+ listStyle: 'none',
48
+ padding: 0,
49
+ // Add iOS momentum scrolling for iOS < 13.0
50
+ WebkitOverflowScrolling: 'touch'
51
+ }, ownerState.variant === 'masonry' && {
52
+ display: 'block'
53
+ });
54
+ });