forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: siriwatknp <siriwatkunaporn@gmail.com>
- Loading branch information
1 parent
73bc043
commit 6d681ff
Showing
16 changed files
with
490 additions
and
125 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
1 change: 1 addition & 0 deletions
1
packages/mui-codemod/src/deprecations/list-item-text-props/index.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 './list-item-text-props'; |
30 changes: 30 additions & 0 deletions
30
packages/mui-codemod/src/deprecations/list-item-text-props/list-item-text-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,30 @@ | ||
import replaceComponentsWithSlots from '../utils/replaceComponentsWithSlots'; | ||
import movePropIntoSlotProps from '../utils/movePropIntoSlotProps'; | ||
|
||
/** | ||
* @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; | ||
|
||
replaceComponentsWithSlots(j, { root, componentName: 'ListItemText' }); | ||
|
||
movePropIntoSlotProps(j, { | ||
root, | ||
componentName: 'ListItemText', | ||
propName: 'primaryTypographyProps', | ||
slotName: 'primary', | ||
}); | ||
|
||
movePropIntoSlotProps(j, { | ||
root, | ||
componentName: 'ListItemText', | ||
propName: 'secondaryTypographyProps', | ||
slotName: 'secondary', | ||
}); | ||
|
||
return root.toSource(printOptions); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/mui-codemod/src/deprecations/list-item-text-props/list-item-text-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,53 @@ | ||
import path from 'path'; | ||
import { expect } from 'chai'; | ||
import { jscodeshift } from '../../../testUtils'; | ||
import transform from './list-item-text-props'; | ||
import readFile from '../../util/readFile'; | ||
|
||
function read(fileName) { | ||
return readFile(path.join(__dirname, fileName)); | ||
} | ||
|
||
describe('@mui/codemod', () => { | ||
describe('deprecations', () => { | ||
describe('list-item-text-props', () => { | ||
it('transforms props as needed', () => { | ||
const actual = transform({ source: read('./test-cases/actual.js') }, { jscodeshift }, {}); | ||
|
||
const expected = read('./test-cases/expected.js'); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
|
||
it('should be idempotent', () => { | ||
const actual = transform({ source: read('./test-cases/expected.js') }, { jscodeshift }, {}); | ||
|
||
const expected = read('./test-cases/expected.js'); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
}); | ||
|
||
describe('[theme] list-item-text-props', () => { | ||
it('transforms props as needed', () => { | ||
const actual = transform( | ||
{ source: read('./test-cases/theme.actual.js') }, | ||
{ jscodeshift }, | ||
{ printOptions: { trailingComma: false } }, | ||
); | ||
|
||
const expected = read('./test-cases/theme.expected.js'); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
|
||
it('should be idempotent', () => { | ||
const actual = transform( | ||
{ source: read('./test-cases/theme.expected.js') }, | ||
{ jscodeshift }, | ||
{}, | ||
); | ||
|
||
const expected = read('./test-cases/theme.expected.js'); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
}); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/mui-codemod/src/deprecations/list-item-text-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,12 @@ | ||
import ListItemText from '@mui/material/ListItemText'; | ||
|
||
<ListItemText secondaryTypographyProps={secondaryTypographyProps} />; | ||
<ListItemText primaryTypographyProps={primaryTypographyProps} />; | ||
<ListItemText | ||
primaryTypographyProps={primaryTypographyProps} | ||
secondaryTypographyProps={secondaryTypographyProps} | ||
/>; | ||
<ListItemText | ||
slotProps={{ primary: primarySlotProps }} | ||
secondaryTypographyProps={secondaryTypographyProps} | ||
/>; |
18 changes: 18 additions & 0 deletions
18
packages/mui-codemod/src/deprecations/list-item-text-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,18 @@ | ||
import ListItemText from '@mui/material/ListItemText'; | ||
|
||
<ListItemText slotProps={{ | ||
secondary: secondaryTypographyProps | ||
}} />; | ||
<ListItemText slotProps={{ | ||
primary: primaryTypographyProps | ||
}} />; | ||
<ListItemText | ||
slotProps={{ | ||
primary: primaryTypographyProps, | ||
secondary: secondaryTypographyProps | ||
}} />; | ||
<ListItemText | ||
slotProps={{ | ||
primary: primarySlotProps, | ||
secondary: secondaryTypographyProps | ||
}} />; |
32 changes: 32 additions & 0 deletions
32
packages/mui-codemod/src/deprecations/list-item-text-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,32 @@ | ||
fn({ | ||
MuiListItemText: { | ||
defaultProps: { | ||
primaryTypographyProps: primaryTypographyProps, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiListItemText: { | ||
defaultProps: { | ||
secondaryTypographyProps: secondaryTypographyProps, | ||
}, | ||
}, | ||
}); | ||
fn({ | ||
MuiListItemText: { | ||
defaultProps: { | ||
primaryTypographyProps: primaryTypographyProps, | ||
secondaryTypographyProps: secondaryTypographyProps, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiListItemText: { | ||
defaultProps: { | ||
slotProps: { primary: primarySlotProps }, | ||
secondaryTypographyProps: secondaryTypographyProps, | ||
}, | ||
}, | ||
}); |
40 changes: 40 additions & 0 deletions
40
packages/mui-codemod/src/deprecations/list-item-text-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,40 @@ | ||
fn({ | ||
MuiListItemText: { | ||
defaultProps: { | ||
slotProps: { | ||
primary: primaryTypographyProps | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiListItemText: { | ||
defaultProps: { | ||
slotProps: { | ||
secondary: secondaryTypographyProps | ||
}, | ||
}, | ||
}, | ||
}); | ||
fn({ | ||
MuiListItemText: { | ||
defaultProps: { | ||
slotProps: { | ||
primary: primaryTypographyProps, | ||
secondary: secondaryTypographyProps | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiListItemText: { | ||
defaultProps: { | ||
slotProps: { | ||
primary: primarySlotProps, | ||
secondary: secondaryTypographyProps | ||
} | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.