Strip unnecessary imports for packages with no modules.

Note that even an empty package needs to define Package[name] = {}, so
that other packages can tell at runtime whether it's installed.

Fixes #7927.
This commit is contained in:
Ben Newman
2016-11-14 10:25:47 -05:00
parent 911f25bbf4
commit 2437f72cd7

View File

@@ -1002,6 +1002,21 @@ export var fullLink = Profile("linker.fullLink", function (inputFiles, {
return [];
}
// If none of the prelinkedFiles contain any code, then the only
// possible purpose of this package is to re-export imported symbols, so
// we filter the set of imported symbols according to declaredExports.
// When there are no declaredExports, this effectively slims the package
// bundle down to just Package[name] = {}.
if (prelinkedFiles.every(file => ! file.source)) {
const newImports = {};
declaredExports.forEach(name => {
if (_.has(imports, name)) {
newImports[name] = imports[name]
}
});
imports = newImports;
}
// Otherwise we're making a package and we have to actually combine the files
// into a single scope.
var header = getHeader({