Skip to content

Commit 4453c4b

Browse files
committed
Treat all ambient modules as external just as we did before.
1 parent 35c595e commit 4453c4b

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

apps/api-extractor/src/analyzer/ExportAnalyzer.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,17 @@ export class ExportAnalyzer {
259259
importOrExportDeclaration: ts.ImportDeclaration | ts.ExportDeclaration | ts.ImportTypeNode,
260260
moduleSpecifier: string
261261
): boolean {
262-
const resolvedModule: ts.ResolvedModuleFull = this._getResolvedModule(
263-
importOrExportDeclaration,
262+
const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(
263+
importOrExportDeclaration.getSourceFile(),
264264
moduleSpecifier
265265
);
266266

267+
// This is known to happen for ambient modules. For now, just treat all ambient modules as
268+
// external. This is tracked by https://github.com/microsoft/rushstack/issues/3335.
269+
if (resolvedModule === undefined) {
270+
return true;
271+
}
272+
267273
// Either something like `jquery` or `@microsoft/api-extractor`.
268274
const packageName: string | undefined = resolvedModule.packageId?.name;
269275
if (packageName !== undefined && this._bundledPackageNames.has(packageName)) {
@@ -856,11 +862,22 @@ export class ExportAnalyzer {
856862
exportSymbol: ts.Symbol
857863
): AstModule {
858864
const moduleSpecifier: string = this._getModuleSpecifier(importOrExportDeclaration);
859-
const resolvedModule: ts.ResolvedModuleFull = this._getResolvedModule(
860-
importOrExportDeclaration,
865+
const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(
866+
importOrExportDeclaration.getSourceFile(),
861867
moduleSpecifier
862868
);
863869

870+
if (resolvedModule === undefined) {
871+
// This should not happen, since getResolvedModule() specifically looks up names that the compiler
872+
// found in export declarations for this source file
873+
//
874+
// Encountered in https://github.com/microsoft/rushstack/issues/1914
875+
throw new InternalError(
876+
`getResolvedModule() could not resolve module name ${JSON.stringify(moduleSpecifier)}\n` +
877+
SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration)
878+
);
879+
}
880+
864881
// Map the filename back to the corresponding SourceFile. This circuitous approach is needed because
865882
// we have no way to access the compiler's internal resolveExternalModuleName() function
866883
const moduleSourceFile: ts.SourceFile | undefined = this._program.getSourceFile(
@@ -919,29 +936,6 @@ export class ExportAnalyzer {
919936
return astImport;
920937
}
921938

922-
private _getResolvedModule(
923-
importOrExportDeclaration: ts.ImportDeclaration | ts.ExportDeclaration | ts.ImportTypeNode,
924-
moduleSpecifier: string
925-
): ts.ResolvedModuleFull {
926-
const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(
927-
importOrExportDeclaration.getSourceFile(),
928-
moduleSpecifier
929-
);
930-
931-
if (resolvedModule === undefined) {
932-
// This should not happen, since getResolvedModule() specifically looks up names that the compiler
933-
// found in export declarations for this source file
934-
//
935-
// Encountered in https://github.com/microsoft/rushstack/issues/1914
936-
throw new InternalError(
937-
`getResolvedModule() could not resolve module name ${JSON.stringify(moduleSpecifier)}\n` +
938-
SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration)
939-
);
940-
}
941-
942-
return resolvedModule;
943-
}
944-
945939
private _getModuleSpecifier(
946940
importOrExportDeclaration: ts.ImportDeclaration | ts.ExportDeclaration | ts.ImportTypeNode
947941
): string {

0 commit comments

Comments
 (0)