-
-
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
Fix tree-shaking wildcards with sideEffects: false #1682
Conversation
33377d0
to
6cb093d
Compare
src/packagers/JSConcatPackager.js
Outdated
@@ -78,6 +78,25 @@ class JSConcatPackager extends Packager { | |||
return this.size; | |||
} | |||
|
|||
findExportAsset(asset, name) { |
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.
might be a good idea to share some of this function with the similar one in concat.js. probably should ensure that they work the same way.
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.
fixed
6cb093d
to
925b236
Compare
if (name === '*') { | ||
this.markUsedExports(dep); | ||
} | ||
|
||
this.markUsed(dep, name); |
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.
should this be in an else
? Otherwise we pass *
as the name to markUsed
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.
a.js
:
import * as b from './b'
console.log(b)
b.js
: <==b.js
should bedep
here, if we removemarkUsed
it'll get trimmed because it doesn't have any exports/import in thecacheData
(just 2 elements inwildcards
)
export * from './c'
export * from './d'
Using *
seemed like a nice fix to me for this, as it'll keep usedImports.size > 0
and never conflict with existing import. I'm just getting familiar with this part though, so not really sure
src/packagers/JSConcatPackager.js
Outdated
let {id} = this.findExportModule(mod.id, name); | ||
mod = this.assets.get(id) || mod; | ||
|
||
let exp = mod.cacheData.exports[name]; | ||
if (Array.isArray(exp)) { |
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.
this should always be false now right, since you already followed the exports through in findExportModule
?
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.
Not in a code-splitted packager, doesn't really make sense to fallback on mod
though. Replaced it with a return fallback.
src/packagers/JSConcatPackager.js
Outdated
for (let source of asset.cacheData.wildcards) { | ||
let dep = asset.depAssets.get(asset.dependencies.get(source)); | ||
for (let exportIdentifier in dep.cacheData.exports) { | ||
this.markUsed(dep, exportIdentifier); |
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.
Is this correct? Do we really want to mark every export in the wildcard as used? Shouldn't it only be the one matching name
? And will markUsed
already handle that for us since it is looking up wildcards via findExportModule
?
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.
Ah, it's a piece of code I added early but forgot to remove
Fixes #1553