@@ -259,11 +259,17 @@ export class ExportAnalyzer {
259
259
importOrExportDeclaration : ts . ImportDeclaration | ts . ExportDeclaration | ts . ImportTypeNode ,
260
260
moduleSpecifier : string
261
261
) : boolean {
262
- const resolvedModule : ts . ResolvedModuleFull = this . _getResolvedModule (
263
- importOrExportDeclaration ,
262
+ const resolvedModule : ts . ResolvedModuleFull | undefined = TypeScriptInternals . getResolvedModule (
263
+ importOrExportDeclaration . getSourceFile ( ) ,
264
264
moduleSpecifier
265
265
) ;
266
266
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
+
267
273
// Either something like `jquery` or `@microsoft/api-extractor`.
268
274
const packageName : string | undefined = resolvedModule . packageId ?. name ;
269
275
if ( packageName !== undefined && this . _bundledPackageNames . has ( packageName ) ) {
@@ -856,11 +862,22 @@ export class ExportAnalyzer {
856
862
exportSymbol : ts . Symbol
857
863
) : AstModule {
858
864
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 ( ) ,
861
867
moduleSpecifier
862
868
) ;
863
869
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
+
864
881
// Map the filename back to the corresponding SourceFile. This circuitous approach is needed because
865
882
// we have no way to access the compiler's internal resolveExternalModuleName() function
866
883
const moduleSourceFile : ts . SourceFile | undefined = this . _program . getSourceFile (
@@ -919,29 +936,6 @@ export class ExportAnalyzer {
919
936
return astImport ;
920
937
}
921
938
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
-
945
939
private _getModuleSpecifier (
946
940
importOrExportDeclaration : ts . ImportDeclaration | ts . ExportDeclaration | ts . ImportTypeNode
947
941
) : string {
0 commit comments