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
Thoroughly improve import resolution #2584
Conversation
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.
Great work!
@@ -9,7 +9,7 @@ define(['exports'], function (exports) { 'use strict'; | |||
}); | |||
|
|||
exports.a = a; | |||
exports.b = b; |
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.
Wow, did you implement the import pruning!? Very cool. That closes #2231 if so.
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.
Yes I did :) and not by adding a final check but by not adding the unused imports in the first place.
Wondering as well if this has affected #2556 at all? |
One thing to ensure here is that execution ordering is carefully maintained. Previously I remember looking into doing these "direct" imports but found that was causing chunk ordering to be changed in some cases (say chunkA imports X from chunkB which is just reexported from chunkC, it might short-circuit chunkB, and lose the fact that chunkB was supposed to execute). I don't know if the above applies, but it is worth checking. |
Thanks for the great reviews! I will check into everything soon. Special thanks for the hint about the execution order. The logic was already there to sort-of maintain execution order by making sure all direct dependencies are added event though nothing was imported from those files but it was broken because the dependency sorting was happening too early. Already added a commit that fixes this. |
cda48e7
to
57f62b7
Compare
c2551f1
to
ae2d424
Compare
to simplify tracing
…orts when creating a namespace object
variables into modules that actually use them. Get rid of variable tracing logic on chunks.
Also, do not inline the execution list when preserving modules
and sorting only once all dependencies have been added
57f62b7
to
dc58d88
Compare
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
resolves #2576
resolves #2231
and quite possible a few more
Description
This is a huge follow-up to #2575. The original intention was to fix handling for dynamic namespaces when preserving modules which lead me down a deep rabbit whole and had me refactoring many core parts of the logic. This is what has been fixed and improved:
import * as lib from ...
for esm,const lib = require(...)
for cjs and so on). Note that namespace freezing will not be performed when preserving modules!a.js
andb.js
both import a variablex
fromc.js
that is only used in one of them, the other will no longer render the import! The effect becomes more pronounced when handling namespace imports. And the new logic is in fact a little simpler than the old one!