Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ A combination of all deprecations.
npx @mui/codemod@latest deprecations/accordion-props <path>
```

#### `divider-props`

```diff
<Divider
- light
/>
```

```bash
npx @mui/codemod@latest deprecations/divider-props <path>
```

### v5.0.0

#### `base-use-named-exports`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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;

findComponentJSX(j, { root, componentName: 'Divider' }, (elementPath) => {
elementPath.node.openingElement.attributes = elementPath.node.openingElement.attributes.filter(
(attr) => {
if (attr.type === 'JSXAttribute' && attr.name.name === 'light') {
return false;
}
return true;
},
);
});

root.find(j.ObjectProperty, { key: { name: 'MuiDivider' } }).forEach((path) => {
const defaultPropsObject = path.value.value.properties.find(
(key) => key.key.name === 'defaultProps',
);

defaultPropsObject.value.properties = defaultPropsObject.value.properties.filter(
(prop) => !['light'].includes(prop?.key?.name),
);
});

return root.toSource(printOptions);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import path from 'path';
import { expect } from 'chai';
import { jscodeshift } from '../../../testUtils';
import transform from './divider-props';
import readFile from '../../util/readFile';

function read(fileName) {
return readFile(path.join(__dirname, fileName));
}

describe('@mui/codemod', () => {
describe('deprecations', () => {
describe('divider-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');
});

it('actual.js should not be equal to expected.js', () => {
const actual = read('./test-cases/actual.js');
const expected = read('./test-cases/expected.js');
expect(actual).to.not.equal(expected);
});
});

describe('[theme] divider-props', () => {
it('transforms props as needed', () => {
const actual = transform(
{ source: read('./test-cases/theme.actual.js') },
{ jscodeshift },
{},
);

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');
});

it('theme.actual.js should not be equal to theme.expected.js', () => {
const actual = read('./test-cases/theme.actual.js');
const expected = read('./test-cases/theme.expected.js');
expect(actual).to.not.equal(expected);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './divider-props';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Divider from '@mui/material/Divider';
import { Divider as MyDivider } from '@mui/material';

<Divider light />;
<MyDivider light />;
<Divider light={false} />;
<MyDivider light={false} />;
<Divider light={light} />;
<MyDivider light={light} />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Divider from '@mui/material/Divider';
import { Divider as MyDivider } from '@mui/material';

<Divider />;
<MyDivider />;
<Divider />;
<MyDivider />;
<Divider />;
<MyDivider />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fn({
MuiDivider: {
defaultProps: {
light: true,
},
},
});
fn({
MuiDivider: {
defaultProps: {
light: true,
className: 'my-class',
},
},
});
fn({
MuiDivider: {
defaultProps: {
light,
className: 'my-class',
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fn({
MuiDivider: {
defaultProps: {},
},
});
fn({
MuiDivider: {
defaultProps: {
className: 'my-class'
},
},
});
fn({
MuiDivider: {
defaultProps: {
className: 'my-class'
},
},
});