@@ -36,7 +36,7 @@ namespace ts.FindAllReferences {
36
36
type ImporterOrCallExpression = Importer | CallExpression ;
37
37
38
38
/** 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 [ ] } {
40
40
const markSeenDirectImport = nodeSeenTracker < ImporterOrCallExpression > ( ) ;
41
41
const markSeenIndirectUser = nodeSeenTracker < SourceFileLike > ( ) ;
42
42
const directImports : Importer [ ] = [ ] ;
@@ -148,7 +148,7 @@ namespace ts.FindAllReferences {
148
148
}
149
149
150
150
function getDirectImports ( moduleSymbol : Symbol ) : ImporterOrCallExpression [ ] | undefined {
151
- return allDirectImports [ getSymbolId ( moduleSymbol ) ] ;
151
+ return allDirectImports . get ( getSymbolId ( moduleSymbol ) . toString ( ) ) ;
152
152
}
153
153
}
154
154
@@ -173,7 +173,7 @@ namespace ts.FindAllReferences {
173
173
174
174
function handleImport ( decl : Importer ) : void {
175
175
if ( decl . kind === SyntaxKind . ImportEqualsDeclaration ) {
176
- if ( isProperImportEquals ( decl ) ) {
176
+ if ( isExternalModuleImportEquals ( decl ) ) {
177
177
handleNamespaceImportLike ( decl . name ) ;
178
178
}
179
179
return ;
@@ -274,17 +274,17 @@ namespace ts.FindAllReferences {
274
274
}
275
275
276
276
/** 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 [ ] > ( ) ;
279
279
280
280
for ( const sourceFile of sourceFiles ) {
281
281
forEachImport ( sourceFile , ( importDecl , moduleSpecifier ) => {
282
282
const moduleSymbol = checker . getSymbolAtLocation ( moduleSpecifier ) ;
283
283
if ( moduleSymbol ) {
284
- const id = getSymbolId ( moduleSymbol ) ;
285
- let imports = map [ id ] ;
284
+ const id = getSymbolId ( moduleSymbol ) . toString ( ) ;
285
+ let imports = map . get ( id ) ;
286
286
if ( ! imports ) {
287
- imports = map [ id ] = [ ] ;
287
+ map . set ( id , imports = [ ] ) ;
288
288
}
289
289
imports . push ( importDecl ) ;
290
290
}
@@ -371,8 +371,7 @@ namespace ts.FindAllReferences {
371
371
* @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.
372
372
*/
373
373
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 ( ) ;
376
375
377
376
function getExport ( ) : ExportedSymbol | ImportedSymbol | undefined {
378
377
const { parent } = node ;
@@ -459,7 +458,9 @@ namespace ts.FindAllReferences {
459
458
const { parent } = node ;
460
459
switch ( parent . kind ) {
461
460
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 ;
463
464
case SyntaxKind . ImportSpecifier :
464
465
// For a rename import `{ foo as bar }`, don't search for the imported symbol. Just find local uses of `bar`.
465
466
return ( parent as ImportSpecifier ) . propertyName ? undefined : { isNamedImport : true } ;
@@ -522,7 +523,7 @@ namespace ts.FindAllReferences {
522
523
return node . kind === SyntaxKind . ModuleDeclaration && ( node as ModuleDeclaration ) . name . kind === SyntaxKind . StringLiteral ;
523
524
}
524
525
525
- function isProperImportEquals ( { moduleReference } : ImportEqualsDeclaration ) : boolean {
526
+ function isExternalModuleImportEquals ( { moduleReference } : ImportEqualsDeclaration ) : boolean {
526
527
return moduleReference . kind === SyntaxKind . ExternalModuleReference && moduleReference . expression . kind === SyntaxKind . StringLiteral
527
528
}
528
529
}
0 commit comments