-
Notifications
You must be signed in to change notification settings - Fork 483
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
WIP: Addition of custom collection functions for importDeclarations/Specifiers #611
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This is really useful! I've written code like this so many times. Nice work. Can this handle Flow/TypeScript type imports too? |
Thanks @Daniel15! I've also written code like this a lot 😂 and I find it's normally the first util people make, but given the way jscodeshift's API is designed (via dependency injection, rather than typical imports) it can be quite cumbersome to import and use utils unless you have access to the I have a util library here, which I've based most of this work on, and as you can probably guess the API is less than ideal because it's forcing me to pass the core API and AST into every method: I'll add some test cases for flow/typescript, but it should work because these utils operate on the |
I'm going to merge this as-is. We can add tests for type imports as a followup. Flow uses a slightly different format for type imports, which we should test too:
|
Thanks @Daniel15 I'll come back to this asap. I have more ready to push up :) |
@mohab-sameh would be good to have these documented on the new site if you have time for it! |
@danieldelcore sure thing! thanks for notifying me. |
I'll push a new version of jscodeshift this week, depending on when you're planning on submitting more PRs this week. |
@danieldelcore Can you please look at the test failure? Not sure why it didn't appear on this diff. Did I merge this too early? We should ensure that PRs that aren't ready to merge are labelled as set as "drafts" Edit: Sorry I messed this up a bit :) Please submit a new PR in draft status.
|
Oh, no worries; yeah, it was a bit early, but I'm happy to reopen :). |
Adds utility methods for import specifiers (similar to the ones provided for
JSXElements
).Why?
Import manipulation is probably the most common operation you will do in a codemod, but there are quite a few edge cases to consider when doing so.
For example,
GLOBALS
insertImportDeclaration
insertImportSpecifiers
findImportDeclarations
findImportSpecifier
findDefaultSpecifier
hasImportSpecifier
hasDefaultImportSpecifier
FILTERS
TBD