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

Make sure external re-exports are included for moduleSideEffects: false #2905

Merged
merged 2 commits into from Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Module.ts
Expand Up @@ -456,7 +456,6 @@ export default class Module {

for (const exportName of this.getExports()) {
const variable = this.getVariableForExportName(exportName);

variable.deoptimizePath(UNKNOWN_PATH);
if (!variable.included) {
variable.include();
Expand All @@ -466,14 +465,14 @@ export default class Module {

for (const name of this.getReexports()) {
const variable = this.getVariableForExportName(name);

if (variable instanceof ExternalVariable) {
variable.reexported = variable.module.reexported = true;
} else if (!variable.included) {
variable.deoptimizePath(UNKNOWN_PATH);
if (!variable.included) {
variable.include();
variable.deoptimizePath(UNKNOWN_PATH);
this.graph.needsTreeshakingPass = true;
}
if (variable instanceof ExternalVariable) {
variable.module.reexported = true;
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/ModuleLoader.ts
Expand Up @@ -398,7 +398,11 @@ export class ModuleLoader {
error(errUnresolvedImport(source, importer));
}
this.graph.warn(errUnresolvedImportTreatedAsExternal(source, importer));
return { id: source, external: true, moduleSideEffects: true };
return {
external: true,
id: source,
moduleSideEffects: this.hasModuleSideEffects(source, true)
};
}
return resolvedId;
}
Expand Down
1 change: 0 additions & 1 deletion src/ast/variables/Variable.ts
Expand Up @@ -18,7 +18,6 @@ export default class Variable implements ExpressionEntity {
isReassigned = false;
module?: Module | ExternalModule;
name: string;
reexported = false;
renderBaseName: string | null = null;
renderName: string | null = null;
safeExportName: string | null = null;
Expand Down
Expand Up @@ -25,6 +25,9 @@ module.exports = {
if (id === 'internal') {
return id;
}
if (id === 'implicit-external') {
return null;
}
const moduleSideEffects = JSON.parse(id.split('-')[1]);
if (moduleSideEffects) {
return { id, moduleSideEffects, external: true };
Expand All @@ -38,5 +41,15 @@ module.exports = {
}
}
}
}
},
warnings: [
{
code: 'UNRESOLVED_IMPORT',
importer: 'main.js',
message:
"'implicit-external' is imported by main.js, but could not be resolved – treating it as an external dependency",
source: 'implicit-external',
url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency'
}
]
};
@@ -1,3 +1,4 @@
import 'pluginsideeffects-false';
import 'pluginsideeffects-true';
import 'internal';
import 'implicit-external';
@@ -0,0 +1,24 @@
const assert = require('assert');

module.exports = {
description: 'handles reexporting external values when module side-effects are false',
context: {
require(id) {
return { value: id };
}
},
exports(exports) {
assert.deepStrictEqual(exports, {
external: 'external',
value: 'externalStar'
});
},
options: {
external() {
return true;
},
treeshake: {
moduleSideEffects: false
}
}
};
@@ -0,0 +1,2 @@
export { value as external } from 'external';
export * from 'externalStar';