@mui/codemod 6.0.0-alpha.0 → 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.
- package/README.md +182 -2
- package/node/deprecations/accordion-props/accordion-props.js +11 -71
- package/node/deprecations/accordion-props/test-cases/actual.js +16 -0
- package/node/deprecations/accordion-props/test-cases/expected.js +14 -0
- package/node/deprecations/accordion-props/test-cases/theme.actual.js +24 -0
- package/node/deprecations/accordion-props/test-cases/theme.expected.js +24 -0
- package/node/deprecations/all/deprecations-all.js +4 -0
- package/node/deprecations/all/postcss.config.js +7 -1
- package/node/deprecations/avatar-props/avatar-props.js +5 -39
- package/node/deprecations/avatar-props/test-cases/actual.js +10 -0
- package/node/deprecations/avatar-props/test-cases/expected.js +10 -0
- package/node/deprecations/avatar-props/test-cases/theme.actual.js +14 -0
- package/node/deprecations/avatar-props/test-cases/theme.expected.js +15 -0
- package/node/deprecations/backdrop-props/backdrop-props.js +5 -61
- package/node/deprecations/backdrop-props/test-cases/actual.js +8 -7
- package/node/deprecations/backdrop-props/test-cases/expected.js +7 -7
- package/node/deprecations/backdrop-props/test-cases/theme.actual.js +11 -0
- package/node/deprecations/backdrop-props/test-cases/theme.expected.js +12 -2
- package/node/deprecations/badge-props/badge-props.js +22 -0
- package/node/deprecations/badge-props/index.js +13 -0
- package/node/deprecations/badge-props/test-cases/actual.js +59 -0
- package/node/deprecations/badge-props/test-cases/expected.js +44 -0
- package/node/deprecations/badge-props/test-cases/theme.actual.js +73 -0
- package/node/deprecations/badge-props/test-cases/theme.expected.js +58 -0
- package/node/deprecations/step-connector-classes/index.js +13 -0
- package/node/deprecations/step-connector-classes/postcss-plugin.js +33 -0
- package/node/deprecations/step-connector-classes/postcss.config.js +8 -0
- package/node/deprecations/step-connector-classes/step-connector-classes.js +77 -0
- package/node/deprecations/step-connector-classes/test-cases/actual.js +7 -0
- package/node/deprecations/step-connector-classes/test-cases/expected.js +7 -0
- package/node/deprecations/step-label-props/step-label-props.js +14 -0
- package/node/deprecations/step-label-props/test-cases/actual.js +23 -0
- package/node/deprecations/step-label-props/test-cases/expected.js +24 -0
- package/node/deprecations/step-label-props/test-cases/theme.actual.js +22 -0
- package/node/deprecations/step-label-props/test-cases/theme.expected.js +25 -0
- package/node/deprecations/toggle-button-group-classes/index.js +13 -0
- package/node/deprecations/toggle-button-group-classes/postcss-plugin.js +33 -0
- package/node/deprecations/toggle-button-group-classes/postcss.config.js +8 -0
- package/node/deprecations/toggle-button-group-classes/test-cases/actual.js +7 -0
- package/node/deprecations/toggle-button-group-classes/test-cases/expected.js +7 -0
- package/node/deprecations/toggle-button-group-classes/toggle-button-group-classes.js +77 -0
- package/node/deprecations/utils/movePropIntoSlotProps.js +111 -0
- package/node/deprecations/utils/movePropIntoSlots.js +101 -0
- package/node/v5.0.0/base-remove-unstyled-suffix.js +4 -4
- package/node/v5.0.0/styled-engine-provider.test/theme-provider.expected.js +3 -3
- package/node/v6.0.0/all/index.js +13 -0
- package/node/v6.0.0/all/postcss.config.js +9 -0
- package/node/v6.0.0/all/v6-all.js +17 -0
- package/node/v6.0.0/styled/index.js +13 -0
- package/node/v6.0.0/styled/styled-v6.js +478 -0
- package/node/v6.0.0/styled/test-cases/BasicStyled.actual.js +54 -0
- package/node/v6.0.0/styled/test-cases/BasicStyled.expected.js +104 -0
- package/node/v6.0.0/styled/test-cases/ConditionalStyled.actual.js +115 -0
- package/node/v6.0.0/styled/test-cases/ConditionalStyled.expected.js +206 -0
- package/node/v6.0.0/styled/test-cases/LogicalStyled.actual.js +28 -0
- package/node/v6.0.0/styled/test-cases/LogicalStyled.expected.js +52 -0
- package/node/v6.0.0/styled/test-cases/NestedSpread.actual.js +42 -0
- package/node/v6.0.0/styled/test-cases/NestedSpread.expected.js +85 -0
- package/node/v6.0.0/styled/test-cases/ObjectMap.actual.js +36 -0
- package/node/v6.0.0/styled/test-cases/ObjectMap.expected.js +109 -0
- package/node/v6.0.0/styled/test-cases/ThemePaletteMode.actual.js +62 -0
- package/node/v6.0.0/styled/test-cases/ThemePaletteMode.expected.js +76 -0
- package/node/v6.0.0/styled/test-cases/VariantAndModeStyled.actual.js +11 -0
- package/node/v6.0.0/styled/test-cases/VariantAndModeStyled.expected.js +19 -0
- package/package.json +8 -8
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
}) => (0, _extends2.default)({
|
|
8
|
+
color: (theme.vars || theme).palette.text.secondary
|
|
9
|
+
}, theme.typography.caption, {
|
|
10
|
+
textAlign: 'left',
|
|
11
|
+
[`&.${formHelperTextClasses.disabled}`]: {
|
|
12
|
+
color: (theme.vars || theme).palette.text.disabled
|
|
13
|
+
},
|
|
14
|
+
variants: [{
|
|
15
|
+
props: {
|
|
16
|
+
size: 'small'
|
|
17
|
+
},
|
|
18
|
+
style: {
|
|
19
|
+
marginTop: 4
|
|
20
|
+
}
|
|
21
|
+
}, {
|
|
22
|
+
props: {
|
|
23
|
+
variant: 'contained',
|
|
24
|
+
size: 'small'
|
|
25
|
+
},
|
|
26
|
+
style: {
|
|
27
|
+
marginTop: 6
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
props: ({
|
|
31
|
+
disabled,
|
|
32
|
+
ownerState
|
|
33
|
+
}) => ownerState.size === 'small' && ownerState.variant === 'contained' && disabled,
|
|
34
|
+
style: {
|
|
35
|
+
marginTop: 6
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
props: ({
|
|
39
|
+
ownerState
|
|
40
|
+
}) => ownerState.size !== 'small',
|
|
41
|
+
style: {
|
|
42
|
+
marginBottom: 4
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
props: ({
|
|
46
|
+
disabled,
|
|
47
|
+
ownerState
|
|
48
|
+
}) => ownerState.size !== 'small' && ownerState.variant !== 'contained' && !disabled,
|
|
49
|
+
style: {
|
|
50
|
+
marginBottom: 6
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
props: ({
|
|
54
|
+
ownerState
|
|
55
|
+
}) => ownerState.contained,
|
|
56
|
+
style: {
|
|
57
|
+
marginLeft: 14,
|
|
58
|
+
marginRight: 14
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
props: ({
|
|
62
|
+
ownerState
|
|
63
|
+
}) => !ownerState.contained,
|
|
64
|
+
style: {
|
|
65
|
+
marginTop: 14,
|
|
66
|
+
marginBottom: 14
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
props: ({
|
|
70
|
+
ownerState
|
|
71
|
+
}) => !!ownerState.disabled,
|
|
72
|
+
style: {
|
|
73
|
+
opacity: 0.5
|
|
74
|
+
}
|
|
75
|
+
}]
|
|
76
|
+
}));
|
|
77
|
+
const Component = styled.div(({
|
|
78
|
+
theme
|
|
79
|
+
}) => (0, _extends2.default)({}, theme.typography.caption, {
|
|
80
|
+
variants: [{
|
|
81
|
+
props: {
|
|
82
|
+
size: 'small'
|
|
83
|
+
},
|
|
84
|
+
style: {
|
|
85
|
+
marginTop: (theme.vars || theme).spacing(1)
|
|
86
|
+
}
|
|
87
|
+
}]
|
|
88
|
+
}));
|
|
89
|
+
const ImageListRoot = styled('ul')({
|
|
90
|
+
display: 'grid',
|
|
91
|
+
overflowY: 'auto',
|
|
92
|
+
listStyle: 'none',
|
|
93
|
+
padding: 0,
|
|
94
|
+
// Add iOS momentum scrolling for iOS < 13.0
|
|
95
|
+
WebkitOverflowScrolling: 'touch',
|
|
96
|
+
variants: [{
|
|
97
|
+
props: {
|
|
98
|
+
variant: 'masonry'
|
|
99
|
+
},
|
|
100
|
+
style: {
|
|
101
|
+
display: 'block'
|
|
102
|
+
}
|
|
103
|
+
}]
|
|
104
|
+
});
|