Skip to content

Commit

Permalink
Fix removedExports to correctly track the exported item (#2835)
Browse files Browse the repository at this point in the history
closes #2834
  • Loading branch information
Swatinem authored and lukastaegert committed May 4, 2019
1 parent 61a7947 commit 6238077
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 8 deletions.
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'
);
});
});
});

0 comments on commit 6238077

Please sign in to comment.