-
-
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.
- Loading branch information
Showing
10 changed files
with
240 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './slider-props'; |
15 changes: 15 additions & 0 deletions
15
packages/mui-codemod/src/deprecations/slider-props/slider-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,15 @@ | ||
import replaceComponentsWithSlots from '../utils/replaceComponentsWithSlots'; | ||
|
||
/** | ||
* @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: 'Slider' }); | ||
|
||
return root.toSource(printOptions); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/mui-codemod/src/deprecations/slider-props/slider-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 './slider-props'; | ||
import readFile from '../../util/readFile'; | ||
|
||
function read(fileName) { | ||
return readFile(path.join(__dirname, fileName)); | ||
} | ||
|
||
describe('@mui/codemod', () => { | ||
describe('deprecations', () => { | ||
describe('slider-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] slider-props', () => { | ||
it('transforms props as needed', () => { | ||
const actual = transform( | ||
{ source: read('./test-cases/theme.actual.js') }, | ||
{ jscodeshift }, | ||
{ printOptions: { trailingComma: true } }, | ||
); | ||
|
||
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'); | ||
}); | ||
}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/mui-codemod/src/deprecations/slider-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,18 @@ | ||
import Slider from '@mui/material/Slider'; | ||
|
||
<Slider | ||
components={{ Track: ComponentsTrack }} | ||
componentsProps={{ track: componentsTrackProps }} | ||
/>; | ||
<Slider | ||
slots={{ rail: SlotsRail }} | ||
components={{ Track: ComponentsTrack }} | ||
slotProps={{ rail: slotsRailProps }} | ||
componentsProps={{ track: componentsTrackProps }} | ||
/>; | ||
<Slider | ||
slots={{ rail: SlotsRail, track: SlotsTrack }} | ||
components={{ Track: ComponentsTrack }} | ||
slotProps={{ rail: slotsRailProps, track: slotsTrackProps }} | ||
componentsProps={{ track: componentsTrackProps }} | ||
/>; |
20 changes: 20 additions & 0 deletions
20
packages/mui-codemod/src/deprecations/slider-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,20 @@ | ||
import Slider from '@mui/material/Slider'; | ||
|
||
<Slider | ||
slots={{ | ||
track: ComponentsTrack | ||
}} | ||
slotProps={{ track: componentsTrackProps }} | ||
/>; | ||
<Slider | ||
slots={{ | ||
rail: SlotsRail, | ||
track: ComponentsTrack | ||
}} | ||
slotProps={{ | ||
rail: slotsRailProps, | ||
track: componentsTrackProps | ||
}} />; | ||
<Slider | ||
slots={{ rail: SlotsRail, track: SlotsTrack }} | ||
slotProps={{ rail: slotsRailProps, track: slotsTrackProps }} />; |
30 changes: 30 additions & 0 deletions
30
packages/mui-codemod/src/deprecations/slider-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,30 @@ | ||
fn({ | ||
MuiSlider: { | ||
defaultProps: { | ||
components: { Track: ComponentsTrack }, | ||
componentsProps: { track: componentsTrackProps }, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiSlider: { | ||
defaultProps: { | ||
components: { Track: ComponentsTrack }, | ||
slots: { rail: SlotsRail }, | ||
componentsProps: { track: componentsTrackProps }, | ||
slotProps: { rail: slotsRailProps }, | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiSlider: { | ||
defaultProps: { | ||
components: { Track: ComponentsTrack }, | ||
slots: { rail: SlotsRail, track: SlotsTrack }, | ||
componentsProps: { track: componentsTrackProps }, | ||
slotProps: { rail: slotsRailProps, track: slotsTrackProps }, | ||
}, | ||
}, | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/mui-codemod/src/deprecations/slider-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,45 @@ | ||
fn({ | ||
MuiSlider: { | ||
defaultProps: { | ||
slots: { | ||
track: ComponentsTrack | ||
}, | ||
|
||
slotProps: { | ||
track: componentsTrackProps | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiSlider: { | ||
defaultProps: { | ||
slots: { | ||
track: ComponentsTrack, | ||
rail: SlotsRail | ||
}, | ||
|
||
slotProps: { | ||
track: componentsTrackProps, | ||
rail: slotsRailProps | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
fn({ | ||
MuiSlider: { | ||
defaultProps: { | ||
slots: { | ||
track: SlotsTrack, | ||
rail: SlotsRail | ||
}, | ||
|
||
slotProps: { | ||
track: slotsTrackProps, | ||
rail: slotsRailProps | ||
} | ||
}, | ||
}, | ||
}); |
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