Skip to content

Commit 83b635c

Browse files
JoostKatscott
authored andcommitted
fix(ngcc): add reexports only once (#33658)
When ngcc is configured to generate reexports for a package using the `generateDeepReexports` configuration option, it could incorrectly render the reexports as often as the number of compiled classes in the declaration file. This would cause compilation errors due to duplicated declarations. PR Close #33658
1 parent 09cf0cd commit 83b635c

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

packages/compiler-cli/ngcc/src/rendering/dts_renderer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ export class DtsRenderer {
9696
const newStatement = ` static ${declaration.name}: ${typeStr};\n`;
9797
outputText.appendRight(endOfClass - 1, newStatement);
9898
});
99+
});
99100

100-
if (renderInfo.reexports.length > 0) {
101-
for (const e of renderInfo.reexports) {
102-
const newStatement = `\nexport {${e.symbolName} as ${e.asAlias}} from '${e.fromModule}';`;
103-
outputText.appendRight(endOfClass, newStatement);
104-
}
101+
if (renderInfo.reexports.length > 0) {
102+
for (const e of renderInfo.reexports) {
103+
const newStatement = `\nexport {${e.symbolName} as ${e.asAlias}} from '${e.fromModule}';`;
104+
outputText.append(newStatement);
105105
}
106-
});
106+
}
107107

108108
this.dtsFormatter.addModuleWithProvidersParams(
109109
outputText, renderInfo.moduleWithProviders, importManager);

packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,23 +918,35 @@ runInEachFileSystem(() => {
918918
var __decorate = null;
919919
var core_1 = require("@angular/core");
920920
var directive_1 = require("./directive");
921+
var LocalDir = /** @class */ (function () {
922+
function LocalDir() {
923+
}
924+
LocalDir = __decorate([
925+
core_1.Directive({
926+
selector: '[local]',
927+
})
928+
], LocalDir);
929+
return LocalDir;
930+
}());
921931
var FooModule = /** @class */ (function () {
922932
function FooModule() {
923933
}
924934
FooModule = __decorate([
925935
core_1.NgModule({
926-
declarations: [directive_1.Foo],
927-
exports: [directive_1.Foo],
936+
declarations: [directive_1.Foo, LocalDir],
937+
exports: [directive_1.Foo, LocalDir],
928938
})
929939
], FooModule);
930940
return FooModule;
931941
}());
942+
exports.LocalDir = LocalDir;
932943
exports.FooModule = FooModule;
933944
`,
934945
},
935946
{
936947
name: _('/node_modules/test-package/module.d.ts'),
937948
contents: `
949+
export declare class LocalDir {}
938950
export declare class FooModule {}
939951
`,
940952
},
@@ -1005,6 +1017,8 @@ runInEachFileSystem(() => {
10051017
expect(jsContents).toContain('exports.ɵngExportɵFooModuleɵFoo = ɵngcc1.Foo;');
10061018
expect(dtsContents)
10071019
.toContain(`export {Foo as ɵngExportɵFooModuleɵFoo} from './directive';`);
1020+
expect(dtsContents.match(/ɵngExportɵFooModuleɵFoo/g) !.length).toBe(1);
1021+
expect(dtsContents).not.toContain(`ɵngExportɵFooModuleɵLocalDir`);
10081022
});
10091023
});
10101024

0 commit comments

Comments
 (0)