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

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.
@@ -16,6 +16,21 @@ function styledV6(file, api, options) {
16
16
  const j = api.jscodeshift;
17
17
  const root = j(file.source);
18
18
  const printOptions = options.printOptions;
19
+ function createBuildStyle(key, upperBuildStyle) {
20
+ return function buildStyle(styleExpression) {
21
+ if (key) {
22
+ if (key.type === 'Identifier' || key.type === 'StringLiteral') {
23
+ return upperBuildStyle(j.objectExpression([j.objectProperty(key, styleExpression)]));
24
+ }
25
+ if (key.type === 'TemplateLiteral') {
26
+ return upperBuildStyle(j.objectExpression([(0, _extends2.default)({}, j.objectProperty(key, styleExpression), {
27
+ computed: true
28
+ })]));
29
+ }
30
+ }
31
+ return upperBuildStyle ? upperBuildStyle(styleExpression) : styleExpression;
32
+ };
33
+ }
19
34
 
20
35
  /**
21
36
  *
@@ -252,7 +267,8 @@ function styledV6(file, api, options) {
252
267
  }
253
268
  }
254
269
  recurseObjectExpression({
255
- node: objectExpression
270
+ node: objectExpression,
271
+ buildStyle: createBuildStyle()
256
272
  });
257
273
  if (variants.length) {
258
274
  objectExpression.properties.push(j.objectProperty(j.identifier('variants'), j.arrayExpression(variants.filter(variant => {
@@ -271,6 +287,7 @@ function styledV6(file, api, options) {
271
287
  node: prop.value,
272
288
  parentNode: data.node,
273
289
  key: prop.key,
290
+ buildStyle: createBuildStyle(prop.key, data.buildStyle),
274
291
  replaceValue: newValue => {
275
292
  prop.value = newValue;
276
293
  },
@@ -279,7 +296,8 @@ function styledV6(file, api, options) {
279
296
  } else {
280
297
  recurseObjectExpression((0, _extends2.default)({}, data, {
281
298
  node: prop,
282
- parentNode: data.node
299
+ parentNode: data.node,
300
+ buildStyle: createBuildStyle(prop.key, data.buildStyle)
283
301
  }));
284
302
  }
285
303
  });
@@ -297,6 +315,8 @@ function styledV6(file, api, options) {
297
315
  props: data.props ? mergeProps(data.props, scopeProps) : scopeProps,
298
316
  style: data.node.argument.right
299
317
  };
318
+ const lastLength = variants.push({}); // preserve the order of the recursive calls
319
+
300
320
  const modeStyles = {}; // to collect styles from `theme.palette.mode === '...'`
301
321
  variant.style.properties.forEach(prop => {
302
322
  if (prop.type === 'ObjectProperty') {
@@ -305,6 +325,7 @@ function styledV6(file, api, options) {
305
325
  parentNode: variant.style,
306
326
  props: variant.props,
307
327
  key: prop.key,
328
+ buildStyle: createBuildStyle(prop.key, data.buildStyle),
308
329
  replaceValue: newValue => {
309
330
  prop.value = newValue;
310
331
  },
@@ -314,12 +335,14 @@ function styledV6(file, api, options) {
314
335
  recurseObjectExpression((0, _extends2.default)({}, data, {
315
336
  node: prop,
316
337
  parentNode: variant.style,
317
- props: variant.props
338
+ props: variant.props,
339
+ buildStyle: createBuildStyle(prop.key, data.buildStyle)
318
340
  }));
319
341
  }
320
342
  });
321
343
  appendPaletteModeStyles(variant.style, modeStyles);
322
- variants.push(buildObjectAST(variant));
344
+ variant.style = data.buildStyle(variant.style);
345
+ variants[lastLength - 1] = buildObjectAST(variant);
323
346
  removeProperty(data.parentNode, data.node);
324
347
  }
325
348
  if (data.node.argument.type === 'ConditionalExpression') {
@@ -348,14 +371,10 @@ function styledV6(file, api, options) {
348
371
  if (data.props) {
349
372
  props = mergeProps(data.props, props);
350
373
  }
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
- }
374
+ const styleVal = data.buildStyle(data.node.consequent);
356
375
  const variant = {
357
376
  props,
358
- style: newStyle
377
+ style: styleVal
359
378
  };
360
379
  variants.push(buildObjectAST(variant));
361
380
 
@@ -364,14 +383,10 @@ function styledV6(file, api, options) {
364
383
  if (data.props) {
365
384
  props2 = mergeProps(data.props, props2);
366
385
  }
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
- }
386
+ const styleVal2 = data.buildStyle(data.node.alternate);
372
387
  const variant2 = {
373
388
  props: props2,
374
- style: newStyle2
389
+ style: styleVal2
375
390
  };
376
391
  variants.push(buildObjectAST(variant2));
377
392
  if (((_data$parentNode = data.parentNode) == null ? void 0 : _data$parentNode.type) === 'ObjectExpression') {
@@ -400,7 +415,7 @@ function styledV6(file, api, options) {
400
415
  recurseObjectExpression((0, _extends2.default)({}, data, {
401
416
  node: expression,
402
417
  parentNode: data.parentNode,
403
- key: data.key,
418
+ buildStyle: createBuildStyle(data.key, data.buildStyle),
404
419
  replaceValue: newValue => {
405
420
  data.node.expressions[index] = newValue;
406
421
  },
@@ -425,7 +440,7 @@ function styledV6(file, api, options) {
425
440
  data.node.object.properties.forEach(prop => {
426
441
  variants.push(buildObjectAST({
427
442
  props: j.objectExpression([j.objectProperty(getIdentifierKey(data.node.property), j.stringLiteral(prop.key.name))]),
428
- style: j.objectExpression([j.objectProperty(data.key, prop.value)])
443
+ style: data.buildStyle(prop.value)
429
444
  }));
430
445
  });
431
446
  removeProperty(data.parentNode, data.node);
@@ -51,4 +51,28 @@ const ImageListRoot = styled('ul')(({
51
51
  }, ownerState.variant === 'masonry' && {
52
52
  display: 'block'
53
53
  });
54
- });
54
+ });
55
+ const ImageListItemRoot = styled('li')(({
56
+ ownerState
57
+ }) => ({
58
+ display: 'block',
59
+ position: 'relative',
60
+ [`& .${imageListItemClasses.img}`]: (0, _extends2.default)({
61
+ objectFit: 'cover',
62
+ width: '100%',
63
+ height: '100%',
64
+ display: 'block'
65
+ }, ownerState.variant === 'standard' && {
66
+ height: 'auto',
67
+ flexGrow: 1
68
+ }, {
69
+ '&:hover': {
70
+ '&[data-shape="circular"]': (0, _extends2.default)({
71
+ borderRadius: '50%'
72
+ }, ownerState.variant === 'unique' && {
73
+ height: 'auto',
74
+ flexGrow: 1
75
+ })
76
+ }
77
+ })
78
+ }));
@@ -101,4 +101,44 @@ const ImageListRoot = styled('ul')({
101
101
  display: 'block'
102
102
  }
103
103
  }]
104
+ });
105
+ const ImageListItemRoot = styled('li')({
106
+ display: 'block',
107
+ position: 'relative',
108
+ [`& .${imageListItemClasses.img}`]: {
109
+ objectFit: 'cover',
110
+ width: '100%',
111
+ height: '100%',
112
+ display: 'block',
113
+ '&:hover': {
114
+ '&[data-shape="circular"]': {
115
+ borderRadius: '50%'
116
+ }
117
+ }
118
+ },
119
+ variants: [{
120
+ props: {
121
+ variant: 'standard'
122
+ },
123
+ style: {
124
+ [`& .${imageListItemClasses.img}`]: {
125
+ height: 'auto',
126
+ flexGrow: 1
127
+ }
128
+ }
129
+ }, {
130
+ props: {
131
+ variant: 'unique'
132
+ },
133
+ style: {
134
+ [`& .${imageListItemClasses.img}`]: {
135
+ '&:hover': {
136
+ '&[data-shape="circular"]': {
137
+ height: 'auto',
138
+ flexGrow: 1
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }]
104
144
  });
@@ -18,6 +18,13 @@ const LinearProgressBar1 = styled('span', {
18
18
  theme
19
19
  }) => ({
20
20
  variants: [{
21
+ props: {
22
+ variant: 'buffer'
23
+ },
24
+ style: {
25
+ '&:hover': {}
26
+ }
27
+ }, {
21
28
  props: ({
22
29
  variant,
23
30
  ownerState
@@ -53,13 +60,6 @@ const LinearProgressBar1 = styled('span', {
53
60
  backgroundColor: 'currentColor'
54
61
  }
55
62
  }
56
- }, {
57
- props: {
58
- variant: 'buffer'
59
- },
60
- style: {
61
- '&:hover': {}
62
- }
63
63
  }, {
64
64
  props: ({
65
65
  ownerState,
@@ -59,6 +59,13 @@ const Component = styled('div')(({
59
59
  style: {
60
60
  marginRight: -12
61
61
  }
62
+ }, {
63
+ props: ({
64
+ ownerState
65
+ }) => ownerState.color !== 'inherit' && ownerState.color !== 'default',
66
+ style: {
67
+ color: palette == null ? void 0 : palette.main
68
+ }
62
69
  }, {
63
70
  props: ({
64
71
  ownerState
@@ -73,13 +80,6 @@ const Component = styled('div')(({
73
80
  }
74
81
  })
75
82
  }
76
- }, {
77
- props: ({
78
- ownerState
79
- }) => ownerState.color !== 'inherit' && ownerState.color !== 'default',
80
- style: {
81
- color: palette == null ? void 0 : palette.main
82
- }
83
83
  }]
84
84
  };
85
85
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/codemod",
3
- "version": "6.0.0-alpha.3",
3
+ "version": "6.0.0-alpha.4",
4
4
  "bin": "./codemod.js",
5
5
  "private": false,
6
6
  "author": "MUI Team",