@@ -5517,10 +5517,8 @@ namespace ts {
55175517 } ;
55185518 }
55195519
5520- function isImportOrExportSpecifierImportSymbol ( symbol : Symbol ) {
5521- return ( symbol . flags & SymbolFlags . Alias ) && forEach ( symbol . declarations , declaration => {
5522- return declaration . kind === SyntaxKind . ImportSpecifier || declaration . kind === SyntaxKind . ExportSpecifier ;
5523- } ) ;
5520+ function isImportSpecifierSymbol ( symbol : Symbol ) {
5521+ return ( symbol . flags & SymbolFlags . Alias ) && ! ! getDeclarationOfKind ( symbol , SyntaxKind . ImportSpecifier ) ;
55245522 }
55255523
55265524 function getInternedName ( symbol : Symbol , location : Node , declarations : Declaration [ ] ) : string {
@@ -5964,8 +5962,17 @@ namespace ts {
59645962 let result = [ symbol ] ;
59655963
59665964 // If the symbol is an alias, add what it alaises to the list
5967- if ( isImportOrExportSpecifierImportSymbol ( symbol ) ) {
5968- result . push ( typeChecker . getAliasedSymbol ( symbol ) ) ;
5965+ if ( isImportSpecifierSymbol ( symbol ) ) {
5966+ result . push ( typeChecker . getAliasedSymbol ( symbol ) ) ;
5967+ }
5968+
5969+ // For export specifiers, the exported name can be refering to a local symbol, e.g.:
5970+ // import {a} from "mod";
5971+ // export {a as somethingElse}
5972+ // We want the *local* declaration of 'a' as declared in the import,
5973+ // *not* as declared within "mod" (or farther)
5974+ if ( location . parent . kind === SyntaxKind . ExportSpecifier ) {
5975+ result . push ( typeChecker . getExportSpecifierLocalTargetSymbol ( < ExportSpecifier > location . parent ) ) ;
59695976 }
59705977
59715978 // If the location is in a context sensitive location (i.e. in an object literal) try
@@ -6055,13 +6062,24 @@ namespace ts {
60556062
60566063 // If the reference symbol is an alias, check if what it is aliasing is one of the search
60576064 // symbols.
6058- if ( isImportOrExportSpecifierImportSymbol ( referenceSymbol ) ) {
6065+ if ( isImportSpecifierSymbol ( referenceSymbol ) ) {
60596066 const aliasedSymbol = typeChecker . getAliasedSymbol ( referenceSymbol ) ;
60606067 if ( searchSymbols . indexOf ( aliasedSymbol ) >= 0 ) {
60616068 return aliasedSymbol ;
60626069 }
60636070 }
60646071
6072+ // For export specifiers, it can be a local symbol, e.g.
6073+ // import {a} from "mod";
6074+ // export {a as somethingElse}
6075+ // We want the local target of the export (i.e. the import symbol) and not the final target (i.e. "mod".a)
6076+ if ( referenceLocation . parent . kind === SyntaxKind . ExportSpecifier ) {
6077+ const aliasedSymbol = typeChecker . getExportSpecifierLocalTargetSymbol ( < ExportSpecifier > referenceLocation . parent ) ;
6078+ if ( searchSymbols . indexOf ( aliasedSymbol ) >= 0 ) {
6079+ return aliasedSymbol ;
6080+ }
6081+ }
6082+
60656083 // If the reference location is in an object literal, try to get the contextual type for the
60666084 // object literal, lookup the property symbol in the contextual type, and use this symbol to
60676085 // compare to our searchSymbol
0 commit comments