-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Scope Hoisting: Don't insert unused requires that aren't registered anywhere #7764
Conversation
|
Benchmark ResultsKitchen Sink 🚨
Timings
Cold BundlesNo bundles found, this is probably a failed build... Cached BundlesNo bundles found, this is probably a failed build... React HackerNews ✅
Timings
Cold BundlesNo bundle changes detected. Cached BundlesNo bundle changes detected. AtlasKit Editor 🚨
Timings
Cold BundlesNo bundles found, this is probably a failed build... Cached BundlesNo bundles found, this is probably a failed build... Three.js ✅
Timings
Cold BundlesNo bundle changes detected. Cached BundlesNo bundle changes detected. |
0bf1f7b
to
e969630
Compare
The test looks great, but I'll defer to @devongovett or @mischnic to have a look at the scope hoisting logic. |
…l into gkong/unused-module
071052d
to
74a7da4
Compare
What's the state of this PR? |
|
This very long condition made me suspicious and indeed the following version passes all test (you probably want to test this in your app though). if (
isWrapped &&
dep &&
!dep?.meta.shouldWrap &&
symbol !== false &&
// Only do this if the asset is part of a different bundle (so it was definitely
// parcelRequire.register'ed there), or if it is indeed registered in this bundle.
(!this.bundle.hasAsset(resolvedAsset) ||
!this.shouldSkipAsset(resolvedAsset))
) {
let hoisted = this.hoistedRequires.get(dep.id);
if (!hoisted) {
hoisted = new Map();
this.hoistedRequires.set(dep.id, hoisted);
}
hoisted.set(
resolvedAsset.id,
`var $${publicId} = parcelRequire(${JSON.stringify(publicId)});`,
);
} |
…l into gkong/unused-module
@devongovett updated with @mischnic's suggestion and tested on a large app -- everything looks good 👍 |
↪️ Pull Request
In
getSymbolResolution
, unused modules can end up in an asset's hoisted requires. A parcelRequire is then inserted for the unused module, and results in aCannot find module
runtime error (see example below).Proposed fix is to check that an asset's exportSymbols are actually used before inserting a parcelRequire for it.
Tested on a large app.
💻 Examples
✔️ PR Todo