Skip to content

Commit

Permalink
use regex
Browse files Browse the repository at this point in the history
  • Loading branch information
sai6855 committed Feb 29, 2024
1 parent 78b8474 commit 0a6182b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,17 @@ export default function transformer(file, api, options) {
});
});

const selector = `${replacementSelectorPrefix}${deprecatedClass}`;
const selectorRegex = new RegExp(`${replacementSelectorPrefix}${deprecatedClass}($)`);
root
.find(j.Literal, (literal) => typeof literal.value === 'string' && literal.value === selector)
.find(
j.Literal,
(literal) => typeof literal.value === 'string' && literal.value.match(selectorRegex),
)
.forEach((path) => {
path.replace(
j.literal(
path.value.value.replace(
selector,
selectorRegex,
`${replacementSelectorPrefix}${replacementSelector}`,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('@mui/codemod', () => {
const actual = jsTransform(
{ source: read('./test-cases/actual.js') },
{ jscodeshift },
{ printOptions: { quote: 'double', trailingComma: true } },
{ printOptions: { quote: 'single', trailingComma: true } },
);

const expected = read('./test-cases/expected.js');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { buttonGroupClasses } from '@mui/material/ButtonGroup';

("&.MuiButtonGroup-horizontal > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-vertical > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-text > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-text.MuiButtonGroup-horizontal > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-text.MuiButtonGroup-vertical > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-text.MuiButtonGroup-colorPrimary > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-text.MuiButtonGroup-colorSecondary > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-outlined > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-outlined.MuiButtonGroup-horizontal > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-outlined.MuiButtonGroup-vertical > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-outlined.MuiButtonGroup-colorPrimary > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-outlined.MuiButtonGroup-colorSecondary > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-contained > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-contained.MuiButtonGroup-horizontal > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-contained.MuiButtonGroup-vertical > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-contained.MuiButtonGroup-colorPrimary > .MuiButtonGroup-grouped");
("&.MuiButtonGroup-contained.MuiButtonGroup-colorSecondary > .MuiButtonGroup-grouped");
('&.MuiButtonGroup-horizontal > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-vertical > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-text > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-text.MuiButtonGroup-horizontal > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-text.MuiButtonGroup-vertical > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-text.MuiButtonGroup-colorPrimary > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-text.MuiButtonGroup-colorSecondary > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-outlined > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-outlined.MuiButtonGroup-horizontal > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-outlined.MuiButtonGroup-vertical > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-outlined.MuiButtonGroup-colorPrimary > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-outlined.MuiButtonGroup-colorSecondary > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-contained > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-contained.MuiButtonGroup-horizontal > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-contained.MuiButtonGroup-vertical > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-contained.MuiButtonGroup-colorPrimary > .MuiButtonGroup-grouped');
('&.MuiButtonGroup-contained.MuiButtonGroup-colorSecondary > .MuiButtonGroup-grouped');
`&.${buttonGroupClasses.horizontal} > .${buttonGroupClasses.grouped}`;
`&.${buttonGroupClasses.vertical} > .${buttonGroupClasses.grouped}`;
`&.${buttonGroupClasses.text} > .${buttonGroupClasses.grouped}`;
Expand Down

0 comments on commit 0a6182b

Please sign in to comment.