diff --git a/apps/api-extractor/src/analyzer/ExportAnalyzer.ts b/apps/api-extractor/src/analyzer/ExportAnalyzer.ts index 53f8c12994c..e31edd49d44 100644 --- a/apps/api-extractor/src/analyzer/ExportAnalyzer.ts +++ b/apps/api-extractor/src/analyzer/ExportAnalyzer.ts @@ -74,6 +74,7 @@ export class ExportAnalyzer { private readonly _importableAmbientSourceFiles: Set = new Set(); private readonly _astImportsByKey: Map = new Map(); + private readonly _astImportInternalsByAstModule: Map = new Map(); public constructor(program: ts.Program, typeChecker: ts.TypeChecker, bundledPackageNames: Set, astSymbolTable: IAstSymbolTable) { @@ -452,11 +453,16 @@ export class ExportAnalyzer { if (externalModulePath === undefined) { const astModule: AstModule = this._fetchSpecifierAstModule(importDeclaration, declarationSymbol); - return new AstImportInternal({ - importKind: AstImportInternalKind.StarImport, - exportName: declarationSymbol.name, - astModule: astModule - }); + let astImportInternal: AstImportInternal | undefined = this._astImportInternalsByAstModule.get(astModule); + if (!astImportInternal) { + astImportInternal = new AstImportInternal({ + importKind: AstImportInternalKind.StarImport, + exportName: declarationSymbol.name, + astModule: astModule + }); + this._astImportInternalsByAstModule.set(astModule, astImportInternal); + } + return astImportInternal; } // Here importSymbol=undefined because {@inheritDoc} and such are not going to work correctly for diff --git a/apps/api-extractor/src/generators/DtsRollupGenerator.ts b/apps/api-extractor/src/generators/DtsRollupGenerator.ts index eb9b4d9a60f..7682fdaf722 100644 --- a/apps/api-extractor/src/generators/DtsRollupGenerator.ts +++ b/apps/api-extractor/src/generators/DtsRollupGenerator.ts @@ -20,6 +20,7 @@ import { StringWriter } from './StringWriter'; import { DtsEmitHelpers } from './DtsEmitHelpers'; import { DeclarationMetadata } from '../collector/DeclarationMetadata'; import { AstImportInternal } from '../analyzer/AstImportInternal'; +import { AstModuleExportInfo } from '../analyzer/AstModule'; /** * Used with DtsRollupGenerator.writeTypingsFile() @@ -133,10 +134,7 @@ export class DtsRollupGenerator { } } } else if (entity.astEntity instanceof AstImportInternal) { - if (!entity.astEntity.astModule.astModuleExportInfo) { - // This should never happen - throw new InternalError('local imported module has not been parsed.'); - } + const astModuleExportInfo: AstModuleExportInfo = collector.astSymbolTable.fetchAstModuleExportInfo(entity.astEntity.astModule); if (!entity.nameForEmit) { // This should never happen throw new InternalError('referencedEntry.nameForEmit is undefined'); @@ -150,7 +148,7 @@ export class DtsRollupGenerator { // all local exports of local imported module are just references to top-level declarations stringWriter.writeLine(' export {'); - entity.astEntity.astModule.astModuleExportInfo.exportedLocalEntities.forEach((exportedEntity, exportedName) => { + astModuleExportInfo.exportedLocalEntities.forEach((exportedEntity, exportedName) => { const collectorEntity: CollectorEntity | undefined = collector.tryGetCollectorEntity(exportedEntity); if (!collectorEntity) { // This should never happen @@ -165,6 +163,10 @@ export class DtsRollupGenerator { }); stringWriter.writeLine(' }'); // end of "export { ... }" + if (astModuleExportInfo.starExportedExternalModules.size > 0) { + throw new Error(`Unsupported star export of external module inside namespace imported module: ${entity.nameForEmit}`); + } + stringWriter.writeLine('}'); // end of "declare namespace { ... }" }