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(compiler-cli): incorrect metadata bundle for multiple unnamed re-exports #29360

Closed
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
8 changes: 7 additions & 1 deletion packages/compiler-cli/src/metadata/bundler.ts
Expand Up @@ -180,6 +180,7 @@ export class MetadataBundler {

// Export all the re-exports from this module
if (module && module.exports) {
let unnamedModuleExportsIdx = 0;
for (const exportDeclaration of module.exports) {
const exportFrom = resolveModule(exportDeclaration.from, moduleName);
// Record all the exports from the module even if we don't use it directly.
Expand All @@ -202,7 +203,12 @@ export class MetadataBundler {
// Re-export all the symbols from the module
const exportedSymbols = this.exportAll(exportFrom);
for (const exportedSymbol of exportedSymbols) {
const name = exportedSymbol.name;
// In case the exported symbol does not have a name, we need to give it an unique
// name for the current module. This is necessary because there can be multiple
// unnamed re-exports in a given module.
const name = exportedSymbol.name === '*' ?
`unnamed_reexport_${unnamedModuleExportsIdx++}` :
exportedSymbol.name;
exportSymbol(exportedSymbol, name);
}
}
Expand Down
15 changes: 15 additions & 0 deletions packages/compiler-cli/test/metadata/bundler_spec.ts
Expand Up @@ -422,6 +422,21 @@ describe('metadata bundler', () => {
expect(result.metadata.origins !['E']).toBeUndefined();
});

it('should be able to bundle a library with multiple unnamed re-exports', () => {
const host = new MockStringBundlerHost('/', {
'public-api.ts': `
export * from '@mypkg/secondary1';
export * from '@mypkg/secondary2';
`,
});

const bundler = new MetadataBundler('/public-api', undefined, host);
const result = bundler.getMetadataBundle();
expect(result.metadata.exports).toEqual([
{from: '@mypkg/secondary1'}, {from: '@mypkg/secondary2'}
]);
});

it('should be able to de-duplicate symbols of re-exported modules', () => {
const host = new MockStringBundlerHost('/', {
'public-api.ts': `
Expand Down