-
-
Notifications
You must be signed in to change notification settings - Fork 27
feat(utils/import-statement): add support to dynamic import with promise #189
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
Conversation
JakobJingleheimer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks!
Will this handle bizarre things like
const dep = import('node:util');
const { default: util } = await dep;function isNodeModule(specifier) { /* … */ }
await isNodeModule('node:util');P.S. Let's avoid large formatting changes mixed into unrelated PRs 🙏 It bloats the diff making it more difficult to figure out what changes actually matter.
Noted, sorry about it
No, this scenario will not be handled with this implementation. To start covering it, we would need to update the function interface, because in this case we need to return more than one SgNode for a single import case. The current return type does not support this, so it would introduce a breaking change. So I would like to await a little bit, before does this refactoring, for two reasons.
Sorry but I didn't get what is happening here, and what is the expected output, could please you give more details? |
That sounds reasonable to me. Perhaps if we land it now, mark the version number as some kind of pre-v1 then to signify that we know it's incomplete (and maybe add that known missing edge-case to the README)? I could maybe be convinced for 1.0.0 with a subsequent patch, but I currently think the pre v1 is the way to go.
This is a case where an unrelated function is called with an argument needle we're searching for. If the search criteria is "a function called with |
Sorry for delay, All done =) |
JakobJingleheimer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT. If it could set the version to the pre-release thing, and note somewhere that it does not handle the bizarre non-awaited dynamic import, g2g.
Actually, our package |
|
Ah, it's the consumers that would need to be pre-release (and then they could all be bumped once this edge-case is covered). |
Closes #187
Add support to
getNodeImportCallsreturns the entire block when found a dynamic import with promise.like the block below
This utility function can now return two different types of nodes:
kind: variable_declaratorIndicates that a variable was created in the file scope.
kind: expression_statementIndicates that it is a dynamic import, and the imported module likely exists only within the scope of the then function.
Support handling imports that use variables as well.