-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[material-ui][Grid] Deprecate
wrap
prop (#42363)
- Loading branch information
Showing
18 changed files
with
176 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/mui-codemod/src/deprecations/grid-props/grid-props.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import findComponentJSX from '../../util/findComponentJSX'; | ||
|
||
/** | ||
* @param {import('jscodeshift').FileInfo} file | ||
* @param {import('jscodeshift').API} api | ||
*/ | ||
export default function transformer(file, api, options) { | ||
const j = api.jscodeshift; | ||
const root = j(file.source); | ||
const printOptions = options.printOptions; | ||
|
||
const filterJSXAttr = (attr, name) => attr.type === 'JSXAttribute' && attr.name.name === name; | ||
|
||
findComponentJSX(j, { root, componentName: 'Grid' }, (gridElement) => { | ||
const attrs = gridElement.node.openingElement.attributes; | ||
const wrapPropIndex = attrs.findIndex((attr) => filterJSXAttr(attr, 'wrap')); | ||
|
||
if (wrapPropIndex !== -1) { | ||
if (attrs.findIndex((attr) => filterJSXAttr(attr, 'flexWrap')) !== -1) { | ||
attrs.splice(wrapPropIndex, 1); | ||
} else { | ||
attrs[wrapPropIndex].name.name = 'flexWrap'; | ||
} | ||
} | ||
}); | ||
|
||
root.find(j.ObjectProperty, { key: { name: 'MuiGrid' } }).forEach((path) => { | ||
const defaultProps = path.value.value.properties.find(({ key }) => key.name === 'defaultProps'); | ||
const props = defaultProps.value.properties; | ||
const wrapPropIndex = props.findIndex((prop) => prop.key.name === 'wrap'); | ||
|
||
if (wrapPropIndex !== -1) { | ||
if (props.findIndex((prop) => prop.key.name === 'flexWrap') !== -1) { | ||
props.splice(wrapPropIndex, 1); | ||
} else { | ||
props[wrapPropIndex].key.name = 'flexWrap'; | ||
} | ||
} | ||
}); | ||
|
||
return root.toSource(printOptions); | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/mui-codemod/src/deprecations/grid-props/grid-props.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describeJscodeshiftTransform } from '../../../testUtils'; | ||
import transform from './grid-props'; | ||
|
||
describe('@mui/codemod', () => { | ||
describe('deprecations', () => { | ||
describeJscodeshiftTransform({ | ||
transform, | ||
transformName: 'grid-props', | ||
dirname: __dirname, | ||
testCases: [ | ||
{ actual: '/test-cases/actual.js', expected: '/test-cases/expected.js' }, | ||
{ actual: '/test-cases/theme.actual.js', expected: '/test-cases/theme.expected.js' }, | ||
], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './grid-props'; |
11 changes: 11 additions & 0 deletions
11
packages/mui-codemod/src/deprecations/grid-props/test-cases/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Grid from '@mui/material/Grid'; | ||
import { Grid as MyGrid } from '@mui/material'; | ||
|
||
<Grid wrap="wrap-reverse" />; | ||
<MyGrid wrap="wrap-reverse" />; | ||
|
||
<Grid wrap="wrap-reverse" flexWrap="wrap" />; | ||
<MyGrid wrap="wrap-reverse" flexWrap="wrap" />; | ||
|
||
// should skip non MUI components | ||
<NonMuiGrid wrap="wrap-reverse" />; |
11 changes: 11 additions & 0 deletions
11
packages/mui-codemod/src/deprecations/grid-props/test-cases/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Grid from '@mui/material/Grid'; | ||
import { Grid as MyGrid } from '@mui/material'; | ||
|
||
<Grid flexWrap="wrap-reverse" />; | ||
<MyGrid flexWrap="wrap-reverse" />; | ||
|
||
<Grid flexWrap="wrap" />; | ||
<MyGrid flexWrap="wrap" />; | ||
|
||
// should skip non MUI components | ||
<NonMuiGrid wrap="wrap-reverse" />; |
24 changes: 24 additions & 0 deletions
24
packages/mui-codemod/src/deprecations/grid-props/test-cases/theme.actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
fn({ | ||
MuiGrid: { | ||
defaultProps: { | ||
wrap: 'wrap' | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiGrid: { | ||
defaultProps: { | ||
wrap: 'wrap-reverse' | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiGrid: { | ||
defaultProps: { | ||
wrap: 'wrap-reverse', | ||
flexWrap: 'wrap' | ||
}, | ||
}, | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/mui-codemod/src/deprecations/grid-props/test-cases/theme.expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
fn({ | ||
MuiGrid: { | ||
defaultProps: { | ||
flexWrap: 'wrap' | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiGrid: { | ||
defaultProps: { | ||
flexWrap: 'wrap-reverse' | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiGrid: { | ||
defaultProps: { | ||
flexWrap: 'wrap' | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters