Skip to content
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

Merged
merged 3 commits into from Jul 9, 2018

Conversation

fathyb
Copy link
Contributor

@fathyb fathyb commented Jul 8, 2018

Fixes #1553

@@ -78,6 +78,25 @@ class JSConcatPackager extends Packager {
return this.size;
}

findExportAsset(asset, name) {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@fathyb fathyb force-pushed the fix/tree-shake-side-effects branch from 6cb093d to 925b236 Compare July 8, 2018 09:52
if (name === '*') {
this.markUsedExports(dep);
}

this.markUsed(dep, name);
Copy link
Member

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

Copy link
Contributor Author

@fathyb fathyb Jul 9, 2018

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 be dep here, if we remove markUsed it'll get trimmed because it doesn't have any exports/import in the cacheData (just 2 elements in wildcards)
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

let {id} = this.findExportModule(mod.id, name);
mod = this.assets.get(id) || mod;

let exp = mod.cacheData.exports[name];
if (Array.isArray(exp)) {
Copy link
Member

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?

Copy link
Contributor Author

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.

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);
Copy link
Member

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?

Copy link
Contributor Author

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

@devongovett devongovett merged commit 764f568 into master Jul 9, 2018
@devongovett devongovett deleted the fix/tree-shake-side-effects branch July 9, 2018 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants