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 removedExports to correctly track the exported item #2835

Merged
merged 1 commit into from May 4, 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
14 changes: 6 additions & 8 deletions src/Module.ts
Expand Up @@ -66,7 +66,6 @@ export interface ImportDescription {
export interface ExportDescription {
identifier?: string;
localName: string;
node?: Node;
}

export interface ReexportDescription {
Expand Down Expand Up @@ -334,8 +333,8 @@ export default class Module {
const renderedExports: string[] = [];
const removedExports: string[] = [];
for (const exportName in this.exports) {
const expt = this.exports[exportName];
(expt.node && expt.node.included ? renderedExports : removedExports).push(exportName);
const variable = this.getVariableForExportName(exportName);
(variable && variable.included ? renderedExports : removedExports).push(exportName);
}
return { renderedExports, removedExports };
}
Expand Down Expand Up @@ -666,8 +665,7 @@ export default class Module {

this.exports.default = {
identifier: node.variable.getOriginalVariableName(),
localName: 'default',
node
localName: 'default'
};
} else if ((<ExportNamedDeclaration>node).declaration) {
// export var { foo, bar } = ...
Expand All @@ -679,13 +677,13 @@ export default class Module {
if (declaration.type === NodeType.VariableDeclaration) {
for (const decl of declaration.declarations) {
for (const localName of extractAssignedNames(decl.id)) {
this.exports[localName] = { localName, node };
this.exports[localName] = { localName };
}
}
} else {
// export function foo () {}
const localName = declaration.id.name;
this.exports[localName] = { localName, node };
this.exports[localName] = { localName };
}
} else {
// export { foo, bar, baz }
Expand All @@ -703,7 +701,7 @@ export default class Module {
);
}

this.exports[exportedName] = { localName, node };
this.exports[exportedName] = { localName };
}
}
}
Expand Down
103 changes: 103 additions & 0 deletions test/misc/bundle-information.js
Expand Up @@ -416,4 +416,107 @@ console.log(other);Promise.all([import('./dynamic1'), import('./dynamic2')]).the
);
});
});

it('contains correct information about rendered/removedExports when directly exporting items', () => {
return rollup
.rollup({
input: ['input'],
plugins: [
loader({
input: 'export { renderedFn, renderedClass, renderedConst } from "code"',
code:
'export function renderedFn() {}\nexport function removedFn() {}\n' +
'export class renderedClass {}\nexport class removedClass {}\n' +
'export const renderedConst = 1;\nexport const removedConst = 1;'
})
]
})
.then(bundle =>
bundle.generate({
format: 'esm'
})
)
.then(({ output: [output] }) => {
assert.deepEqual(
output.code,
'function renderedFn() {}\nclass renderedClass {}\nconst renderedConst = 1;\n\nexport { renderedClass, renderedConst, renderedFn };\n',
'code'
);
assert.deepEqual(
output.exports,
['renderedClass', 'renderedConst', 'renderedFn'],
'exports'
);
assert.deepEqual(
output.modules,
{
code: {
originalLength: 184,
removedExports: ['removedFn', 'removedClass', 'removedConst'],
renderedExports: ['renderedFn', 'renderedClass', 'renderedConst'],
renderedLength: 72
},
input: {
originalLength: 63,
removedExports: [],
renderedExports: [],
renderedLength: 0
}
},
'modules'
);
});
});

it('contains correct information about rendered/removedExports when using export declaration', () => {
return rollup
.rollup({
input: ['input'],
plugins: [
loader({
input: 'export { renderedFn, renderedClass, renderedConst } from "code"',
code:
'function renderedFn() {}\nfunction removedFn() {}\n' +
'class renderedClass {}\nclass removedClass {}\n' +
'const renderedConst = 1;\nconst removedConst = 1;\n' +
'export { renderedFn, renderedClass, renderedConst, removedFn, removedClass, removedConst }'
})
]
})
.then(bundle =>
bundle.generate({
format: 'esm'
})
)
.then(({ output: [output] }) => {
assert.deepEqual(
output.code,
'function renderedFn() {}\nclass renderedClass {}\nconst renderedConst = 1;\n\nexport { renderedClass, renderedConst, renderedFn };\n',
'code'
);
assert.deepEqual(
output.exports,
['renderedClass', 'renderedConst', 'renderedFn'],
'exports'
);
assert.deepEqual(
output.modules,
{
code: {
originalLength: 233,
removedExports: ['removedFn', 'removedClass', 'removedConst'],
renderedExports: ['renderedFn', 'renderedClass', 'renderedConst'],
renderedLength: 72
},
input: {
originalLength: 63,
removedExports: [],
renderedExports: [],
renderedLength: 0
}
},
'modules'
);
});
});
});