@@ -4265,7 +4265,7 @@ namespace ts {
42654265 isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) ||
42664266 isNameOfExternalModuleImportOrDeclaration ( node ) ) {
42674267
4268- let referencedSymbols = getReferencedSymbolsForNodes ( node , sourceFilesToSearch , /*findInStrings:*/ false , /*findInComments:*/ false ) ;
4268+ let referencedSymbols = getReferencedSymbolsForNode ( node , sourceFilesToSearch , /*findInStrings:*/ false , /*findInComments:*/ false ) ;
42694269 return convertReferencedSymbols ( referencedSymbols ) ;
42704270 }
42714271
@@ -4917,10 +4917,10 @@ namespace ts {
49174917 }
49184918
49194919 Debug . assert ( node . kind === SyntaxKind . Identifier || node . kind === SyntaxKind . NumericLiteral || node . kind === SyntaxKind . StringLiteral ) ;
4920- return getReferencedSymbolsForNodes ( node , program . getSourceFiles ( ) , findInStrings , findInComments ) ;
4920+ return getReferencedSymbolsForNode ( node , program . getSourceFiles ( ) , findInStrings , findInComments ) ;
49214921 }
49224922
4923- function getReferencedSymbolsForNodes ( node : Node , sourceFiles : SourceFile [ ] , findInStrings : boolean , findInComments : boolean ) : ReferencedSymbol [ ] {
4923+ function getReferencedSymbolsForNode ( node : Node , sourceFiles : SourceFile [ ] , findInStrings : boolean , findInComments : boolean ) : ReferencedSymbol [ ] {
49244924 let typeChecker = program . getTypeChecker ( ) ;
49254925
49264926 // Labels
@@ -4955,7 +4955,7 @@ namespace ts {
49554955
49564956 let declarations = symbol . declarations ;
49574957
4958- // The symbol was an internal symbol and does not have a declaration e.g.undefined symbol
4958+ // The symbol was an internal symbol and does not have a declaration e.g. undefined symbol
49594959 if ( ! declarations || ! declarations . length ) {
49604960 return undefined ;
49614961 }
@@ -4965,8 +4965,9 @@ namespace ts {
49654965 // Compute the meaning from the location and the symbol it references
49664966 let searchMeaning = getIntersectingMeaningFromDeclarations ( getMeaningFromLocation ( node ) , declarations ) ;
49674967
4968- // Get the text to search for, we need to normalize it as external module names will have quote
4969- let declaredName = getDeclaredName ( symbol , node ) ;
4968+ // Get the text to search for.
4969+ // Note: if this is an external module symbol, the name doesn't include quotes.
4970+ let declaredName = getDeclaredName ( typeChecker , symbol , node ) ;
49704971
49714972 // Try to get the smallest valid scope that we can limit our search to;
49724973 // otherwise we'll need to search globally (i.e. include each file).
@@ -5013,76 +5014,43 @@ namespace ts {
50135014 } ;
50145015 }
50155016
5016- function isImportOrExportSpecifierName ( location : Node ) : boolean {
5017- return location . parent &&
5018- ( location . parent . kind === SyntaxKind . ImportSpecifier || location . parent . kind === SyntaxKind . ExportSpecifier ) &&
5019- ( < ImportOrExportSpecifier > location . parent ) . propertyName === location ;
5020- }
5021-
50225017 function isImportOrExportSpecifierImportSymbol ( symbol : Symbol ) {
50235018 return ( symbol . flags & SymbolFlags . Alias ) && forEach ( symbol . declarations , declaration => {
50245019 return declaration . kind === SyntaxKind . ImportSpecifier || declaration . kind === SyntaxKind . ExportSpecifier ;
50255020 } ) ;
50265021 }
50275022
5028- function getDeclaredName ( symbol : Symbol , location : Node ) {
5029- // Special case for function expressions, whose names are solely local to their bodies.
5030- let functionExpression = forEach ( symbol . declarations , d => d . kind === SyntaxKind . FunctionExpression ? < FunctionExpression > d : undefined ) ;
5031-
5032- // When a name gets interned into a SourceFile's 'identifiers' Map,
5033- // its name is escaped and stored in the same way its symbol name/identifier
5034- // name should be stored. Function expressions, however, are a special case,
5035- // because despite sometimes having a name, the binder unconditionally binds them
5036- // to a symbol with the name "__function".
5037- let name : string ;
5038- if ( functionExpression && functionExpression . name ) {
5039- name = functionExpression . name . text ;
5040- }
5041-
5042- // If this is an export or import specifier it could have been renamed using the as syntax.
5043- // if so we want to search for whatever under the cursor, the symbol is pointing to the alias (name)
5044- // so check for the propertyName.
5045- if ( isImportOrExportSpecifierName ( location ) ) {
5046- return location . getText ( ) ;
5047- }
5048-
5049- name = typeChecker . symbolToString ( symbol ) ;
5050-
5051- return stripQuotes ( name ) ;
5052- }
5053-
50545023 function getInternedName ( symbol : Symbol , location : Node , declarations : Declaration [ ] ) : string {
5055- // If this is an export or import specifier it could have been renamed using the as syntax.
5056- // if so we want to search for whatever under the cursor, the symbol is pointing to the alias (name)
5057- // so check for the propertyName.
5024+ // If this is an export or import specifier it could have been renamed using the 'as' syntax.
5025+ // If so we want to search for whatever under the cursor.
50585026 if ( isImportOrExportSpecifierName ( location ) ) {
50595027 return location . getText ( ) ;
50605028 }
50615029
5062- // Special case for function expressions, whose names are solely local to their bodies.
5063- let functionExpression = forEach ( declarations , d => d . kind === SyntaxKind . FunctionExpression ? < FunctionExpression > d : undefined ) ;
5064-
5065- // When a name gets interned into a SourceFile's 'identifiers' Map,
5066- // its name is escaped and stored in the same way its symbol name/identifier
5067- // name should be stored. Function expressions, however, are a special case,
5068- // because despite sometimes having a name, the binder unconditionally binds them
5069- // to a symbol with the name "__function".
5070- let name = functionExpression && functionExpression . name
5071- ? functionExpression . name . text
5072- : symbol . name ;
5073-
5074- return stripQuotes ( name ) ;
5075- }
5030+ // Try to get the local symbol if we're dealing with an 'export default'
5031+ // since that symbol has the "true" name.
5032+ let localExportDefaultSymbol = getLocalSymbolForExportDefault ( symbol ) ;
5033+ symbol = localExportDefaultSymbol || symbol ;
50765034
5077- function stripQuotes ( name : string ) {
5078- let length = name . length ;
5079- if ( length >= 2 && name . charCodeAt ( 0 ) === CharacterCodes . doubleQuote && name . charCodeAt ( length - 1 ) === CharacterCodes . doubleQuote ) {
5080- return name . substring ( 1 , length - 1 ) ;
5081- } ;
5082- return name ;
5035+ return stripQuotes ( symbol . name ) ;
50835036 }
50845037
5038+ /**
5039+ * Determines the smallest scope in which a symbol may have named references.
5040+ * Note that not every construct has been accounted for. This function can
5041+ * probably be improved.
5042+ *
5043+ * @returns undefined if the scope cannot be determined, implying that
5044+ * a reference to a symbol can occur anywhere.
5045+ */
50855046 function getSymbolScope ( symbol : Symbol ) : Node {
5047+ // If this is the symbol of a function expression, then named references
5048+ // are limited to its own scope.
5049+ let valueDeclaration = symbol . valueDeclaration ;
5050+ if ( valueDeclaration && valueDeclaration . kind === SyntaxKind . FunctionExpression ) {
5051+ return valueDeclaration ;
5052+ }
5053+
50865054 // If this is private property or method, the scope is the containing class
50875055 if ( symbol . flags & ( SymbolFlags . Property | SymbolFlags . Method ) ) {
50885056 let privateDeclaration = forEach ( symbol . getDeclarations ( ) , d => ( d . flags & NodeFlags . Private ) ? d : undefined ) ;
@@ -6724,12 +6692,13 @@ namespace ts {
67246692 }
67256693 }
67266694
6695+ let displayName = getDeclaredName ( typeChecker , symbol , node ) ;
67276696 let kind = getSymbolKind ( symbol , node ) ;
67286697 if ( kind ) {
67296698 return {
67306699 canRename : true ,
67316700 localizedErrorMessage : undefined ,
6732- displayName : symbol . name ,
6701+ displayName,
67336702 fullDisplayName : typeChecker . getFullyQualifiedName ( symbol ) ,
67346703 kind : kind ,
67356704 kindModifiers : getSymbolModifiers ( symbol ) ,
0 commit comments