Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support parsing files with macros in codemod #7114

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

reidbarber
Copy link
Member

@reidbarber reidbarber commented Sep 27, 2024

By updating the parser, we can now run codemods on files with the style macro already imported.
Also fixes an issue where existing s2 imports were being removed.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link

rspbot commented Sep 27, 2024

@@ -225,6 +225,12 @@ import { style } from "@react-spectrum/s2/style" with { type: "macro" };
})}>Test</RSPButton>"
`;

exports[`Should leave existing style macros unaffected 1`] = `
"import { style } from "@react-spectrum/s2/style" with { type: "macro" };
Copy link
Member

Choose a reason for hiding this comment

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

where'd the import of TextField go?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Looks like that was an unrelated issue that came up when we renamed the package, but we didn't have any tests to catch it. Just needed to update:

- if (path.node.source.value === '@adobe/react-spectrum' || path.node.source.value.startsWith('@react-spectrum/')) {
+ if (path.node.source.value === '@adobe/react-spectrum' || (path.node.source.value.startsWith('@react-spectrum/') && path.node.source.value !== '@react-spectrum/s2')) {

@rspbot
Copy link

rspbot commented Sep 30, 2024

@rspbot
Copy link

rspbot commented Sep 30, 2024

@reidbarber reidbarber added this pull request to the merge queue Sep 30, 2024
Merged via the queue into main with commit daed8ca Sep 30, 2024
29 checks passed
@reidbarber reidbarber deleted the fix-codemod-macro-parsing branch September 30, 2024 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants