@@ -36,7 +36,7 @@ namespace ts.FindAllReferences {
3636 type ImporterOrCallExpression = Importer | CallExpression ;
3737
3838 /** Returns import statements that directly reference the exporting module, and a list of files that may access the module through a namespace. */
39- function getImportersForExport ( sourceFiles : SourceFile [ ] , allDirectImports : ImporterOrCallExpression [ ] [ ] , { exportingModuleSymbol, exportKind } : ExportInfo , checker : TypeChecker ) : { directImports : Importer [ ] , indirectUsers : SourceFile [ ] } {
39+ function getImportersForExport ( sourceFiles : SourceFile [ ] , allDirectImports : Map < ImporterOrCallExpression [ ] > , { exportingModuleSymbol, exportKind } : ExportInfo , checker : TypeChecker ) : { directImports : Importer [ ] , indirectUsers : SourceFile [ ] } {
4040 const markSeenDirectImport = nodeSeenTracker < ImporterOrCallExpression > ( ) ;
4141 const markSeenIndirectUser = nodeSeenTracker < SourceFileLike > ( ) ;
4242 const directImports : Importer [ ] = [ ] ;
@@ -148,7 +148,7 @@ namespace ts.FindAllReferences {
148148 }
149149
150150 function getDirectImports ( moduleSymbol : Symbol ) : ImporterOrCallExpression [ ] | undefined {
151- return allDirectImports [ getSymbolId ( moduleSymbol ) ] ;
151+ return allDirectImports . get ( getSymbolId ( moduleSymbol ) . toString ( ) ) ;
152152 }
153153 }
154154
@@ -173,7 +173,7 @@ namespace ts.FindAllReferences {
173173
174174 function handleImport ( decl : Importer ) : void {
175175 if ( decl . kind === SyntaxKind . ImportEqualsDeclaration ) {
176- if ( isProperImportEquals ( decl ) ) {
176+ if ( isExternalModuleImportEquals ( decl ) ) {
177177 handleNamespaceImportLike ( decl . name ) ;
178178 }
179179 return ;
@@ -274,17 +274,17 @@ namespace ts.FindAllReferences {
274274 }
275275
276276 /** Returns a map from a module symbol Id to all import statements that directly reference the module. */
277- function getDirectImportsMap ( sourceFiles : SourceFile [ ] , checker : TypeChecker ) : ImporterOrCallExpression [ ] [ ] {
278- const map : ImporterOrCallExpression [ ] [ ] = [ ] ;
277+ function getDirectImportsMap ( sourceFiles : SourceFile [ ] , checker : TypeChecker ) : Map < ImporterOrCallExpression [ ] > {
278+ const map = createMap < ImporterOrCallExpression [ ] > ( ) ;
279279
280280 for ( const sourceFile of sourceFiles ) {
281281 forEachImport ( sourceFile , ( importDecl , moduleSpecifier ) => {
282282 const moduleSymbol = checker . getSymbolAtLocation ( moduleSpecifier ) ;
283283 if ( moduleSymbol ) {
284- const id = getSymbolId ( moduleSymbol ) ;
285- let imports = map [ id ] ;
284+ const id = getSymbolId ( moduleSymbol ) . toString ( ) ;
285+ let imports = map . get ( id ) ;
286286 if ( ! imports ) {
287- imports = map [ id ] = [ ] ;
287+ map . set ( id , imports = [ ] ) ;
288288 }
289289 imports . push ( importDecl ) ;
290290 }
@@ -371,8 +371,7 @@ namespace ts.FindAllReferences {
371371 * @param comingFromExport If we are doing a search for all exports, don't bother looking backwards for the imported symbol, since that's the reason we're here.
372372 */
373373 export function getImportOrExportSymbol ( node : Node , symbol : Symbol , checker : TypeChecker , comingFromExport : boolean ) : ImportedSymbol | ExportedSymbol | undefined {
374- const ex = getExport ( ) ;
375- return ex || comingFromExport ? ex : getImport ( ) ;
374+ return comingFromExport ? getExport ( ) : getExport ( ) || getImport ( ) ;
376375
377376 function getExport ( ) : ExportedSymbol | ImportedSymbol | undefined {
378377 const { parent } = node ;
@@ -459,7 +458,9 @@ namespace ts.FindAllReferences {
459458 const { parent } = node ;
460459 switch ( parent . kind ) {
461460 case SyntaxKind . ImportEqualsDeclaration :
462- return ( parent as ImportEqualsDeclaration ) . name === node ? { isNamedImport : false } : undefined ;
461+ return ( parent as ImportEqualsDeclaration ) . name === node && isExternalModuleImportEquals ( parent as ImportEqualsDeclaration )
462+ ? { isNamedImport : false }
463+ : undefined ;
463464 case SyntaxKind . ImportSpecifier :
464465 // For a rename import `{ foo as bar }`, don't search for the imported symbol. Just find local uses of `bar`.
465466 return ( parent as ImportSpecifier ) . propertyName ? undefined : { isNamedImport : true } ;
@@ -522,7 +523,7 @@ namespace ts.FindAllReferences {
522523 return node . kind === SyntaxKind . ModuleDeclaration && ( node as ModuleDeclaration ) . name . kind === SyntaxKind . StringLiteral ;
523524 }
524525
525- function isProperImportEquals ( { moduleReference } : ImportEqualsDeclaration ) : boolean {
526+ function isExternalModuleImportEquals ( { moduleReference } : ImportEqualsDeclaration ) : boolean {
526527 return moduleReference . kind === SyntaxKind . ExternalModuleReference && moduleReference . expression . kind === SyntaxKind . StringLiteral
527528 }
528529}
0 commit comments