-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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] named
/ExportMap
: handle named imports from CJS modules that use dynamic import
#2341
Conversation
… use dynamic import Fix import-js#2294 Mark ambiguous (i.e. not unambiguously ESM) modules that contain dynamic import() so that they can be ignored like other ambiguous modules when analysing named imports. In this way, the named rule accepts named imports from CJS modules that contain dynamic imports. Also fix the case where the importing module uses a require() call.
7301624
to
0dba1cf
Compare
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.
Tests look good!
Codecov Report
@@ Coverage Diff @@
## main #2341 +/- ##
==========================================
+ Coverage 94.64% 94.72% +0.07%
==========================================
Files 65 65
Lines 2691 2690 -1
Branches 891 893 +2
==========================================
+ Hits 2547 2548 +1
+ Misses 144 142 -2
Continue to review full report at Codecov.
|
I've applied your suggestion of turning |
I'm mainly hoping that we can get these kinds of helpers in a place where it becomes trivial to support CJS files as well as ESM files. What are your thoughts about having an "empty" ExportsMap instead of |
I need to take a longer look at the code. My instinct would be that it increases the risk of breaking something else as we'll miss one spot that's relying on the ExportsMap being |
Fair enough, let's do that in a follow-up PR then. |
56b6838
to
e3ca68e
Compare
named
/ExportMap
: handle named imports from CJS modules that use dynamic import
I feel like I am missing some context to make a follow-up. I've looked at the implementation for the rules some more and I've also looked at the issues. I cannot find case where returning empty ExportMap from a CJS file would make a difference:
On an unrelated note, have you thought about using issue templates to require a link to a reproduction? I've got the impression that a lot of open issues are unactionable because they lack a reproduction. |
@ludofischer i'm mainly thinking that it'd make it clearer for rules to use ExportsMap - since CJS Scripts have a dep graph too, and this plugin should support them. As for an issue template, I'd be happy to look at a PR that added one :-) |
Fix #2294
ExportMap
to track whether the module is unambiguously ES6import
asrequire()
Proposed solution
Mark ambiguous (i.e. not unambiguously ESM) modules that contain dynamic import()
so that they can be ignored like other ambiguous modules when analysing named imports.
Previous to 7c382f0 this was not necessary because a
null
ExportMap was returned for all ambiguous modules.Alternatives
Parse the CommonJS exports instead of ignoring the CommonJS modules. Rejected because analysingg CommonJS exports seems out of scope of this plugin.