Skip to content

Commit

Permalink
[codemod] Cover edge case for theme-spacing mui#28400
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored Sep 20, 2021
1 parent 6976c2e commit 1f2bb89
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/mui-codemod/src/v5.0.0/theme-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function transformer(file) {
return (
file.source
// `${theme.spacing(2)}px` -> theme.spacing(2)
.replace(/`\${((theme\.spacing|spacing)\([^{}]*\))}px`/gm, '$1')
.replace(/`(-?)\${(-?)(theme\.spacing|spacing)\(([^{}]*)\)}px`/gm, '$3($1$2$4)')
// `${theme.spacing(2)}px ${theme.spacing(4)}px` -> `${theme.spacing(2)} ${theme.spacing(4)}`
.replace(/(?<={(theme\.spacing|spacing)\(.*\)})px/gm, '')
.replace(/((theme\.spacing|spacing)\(.*\))\s*\+\s*'px'/gm, '$1')
Expand Down
4 changes: 3 additions & 1 deletion packages/mui-codemod/src/v5.0.0/theme-spacing.test/actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ spacing(gap) + 'px'
`calc(100% - ${spacing(itemHorzPadding * 2)}px)`
`calc(100% - ${theme.spacing(itemHorzPadding * 2)}px)`
padding: `${theme.spacing(2) - 1}px 0`
`calc(100% - ${theme.spacing(itemHorzPadding) * 0.3}px)`
`calc(100% - ${theme.spacing(itemHorzPadding) * 0.3}px)`
`${-theme.spacing(1)}px`
`-${theme.spacing(1)}px`
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ spacing(gap)
`calc(100% - ${spacing(itemHorzPadding * 2)})`
`calc(100% - ${theme.spacing(itemHorzPadding * 2)})`
padding: `calc(${theme.spacing(2)} - 1px) 0`
`calc(100% - calc(${theme.spacing(itemHorzPadding)} * 0.3))`
`calc(100% - calc(${theme.spacing(itemHorzPadding)} * 0.3))`
theme.spacing(-1)
theme.spacing(-1)

0 comments on commit 1f2bb89

Please sign in to comment.