Skip to content

Conversation

@sai6855
Copy link
Contributor

@sai6855 sai6855 commented Jan 30, 2024

How to test the fix

  1. go to https://github.com/mui/material-ui/blob/master/packages/mui-codemod/src/deprecations/accordion-props/accordion-props.js in master branch
  2. add console.log(elementPath.node.openingElement.name.name); below this line
    findComponentJSX(j, { root, componentName: 'Accordion' }, (elementPath) => {
    and run node packages/mui-codemod/codemod deprecations/accordion-props packages/mui-codemod/src/deprecations/accordion-props/test-cases/actual.js
  3. Notice it logs Accordion 2 times, everything is good until now
  4. Now change componentName: "Accordion" to componentName: "sank" (or any random value) on this line and run node packages/mui-codemod/codemod deprecations/accordion-props packages/mui-codemod/src/deprecations/accordion-props/test-cases/actual.js
  5. Notice it logs Accordion again 2 times, as per my understanding findComponentJSX function should filter out components which matches with componentName but i don't think that's the case now. This PR fixes it

Note: I'm really new to codemods and Regex, apologies in advance if my understanding or logic is wrong

@sai6855 sai6855 added the package: codemod Specific to codemod. label Jan 30, 2024
@sai6855 sai6855 marked this pull request as draft January 30, 2024 11:47
@mui-bot
Copy link

mui-bot commented Jan 30, 2024

Netlify deploy preview

https://deploy-preview-40855--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 8b714f8

@sai6855 sai6855 marked this pull request as ready for review January 30, 2024 11:59
@sai6855 sai6855 added the type: bug It doesn't behave as expected. label Jan 30, 2024
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this @sai6855

Comment on lines 20 to 23
.filter(
(path) =>
path.node.source.value.match(new RegExp(`^@mui/material/(${componentName})`)) ||
path.node.source.value === '@mui/material',
Copy link
Member

@DiegoAndai DiegoAndai Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make it simpler:

Suggested change
.filter(
(path) =>
path.node.source.value.match(new RegExp(`^@mui/material/(${componentName})`)) ||
path.node.source.value === '@mui/material',
.filter((path) =>
path.node.source.value.match(new RegExp(`^@mui/material(/${componentName})?$`)),

It's the same as your fix, as $ indicates to match the end of the line, so it's either

  • string start (^) -> @mui/material -> string end ($)
  • string start (^) -> @mui/material/componentName -> string end ($)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clear explaination. fixed in this commit 8b714f8

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Did you test if it's fixed on your side after the refactor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ran codemod script. Now util is filtering out data correctly

@DiegoAndai DiegoAndai merged commit 69b7a29 into mui:master Jan 31, 2024
@sai6855 sai6855 deleted the fix-codemod branch January 31, 2024 20:18
mostafa-rio pushed a commit to mostafa-rio/material-ui that referenced this pull request Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: codemod Specific to codemod. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants