@@ -11,7 +11,7 @@ namespace ts.FindAllReferences {
1111 | { readonly type : DefinitionKind . Label ; readonly node : Identifier }
1212 | { readonly type : DefinitionKind . Keyword ; readonly node : Node }
1313 | { readonly type : DefinitionKind . This ; readonly node : Node }
14- | { readonly type : DefinitionKind . String ; readonly node : StringLiteral } ;
14+ | { readonly type : DefinitionKind . String ; readonly node : StringLiteralLike } ;
1515
1616 export const enum EntryKind { Span , Node , StringLiteral , SearchedLocalFoundProperty , SearchedPropertyFoundLocal }
1717 export type NodeEntryKind = EntryKind . Node | EntryKind . StringLiteral | EntryKind . SearchedLocalFoundProperty | EntryKind . SearchedPropertyFoundLocal ;
@@ -621,7 +621,7 @@ namespace ts.FindAllReferences {
621621 // Could not find a symbol e.g. unknown identifier
622622 if ( ! symbol ) {
623623 // String literal might be a property (and thus have a symbol), so do this here rather than in getReferencedSymbolsSpecial.
624- return ! options . implementations && isStringLiteral ( node ) ? getReferencesForStringLiteral ( node , sourceFiles , cancellationToken ) : undefined ;
624+ return ! options . implementations && isStringLiteralLike ( node ) ? getReferencesForStringLiteral ( node , sourceFiles , checker , cancellationToken ) : undefined ;
625625 }
626626
627627 if ( symbol . escapedName === InternalSymbolName . ExportEquals ) {
@@ -1889,11 +1889,23 @@ namespace ts.FindAllReferences {
18891889 } ] ;
18901890 }
18911891
1892- function getReferencesForStringLiteral ( node : StringLiteral , sourceFiles : readonly SourceFile [ ] , cancellationToken : CancellationToken ) : SymbolAndEntries [ ] {
1892+ function getReferencesForStringLiteral ( node : StringLiteralLike , sourceFiles : readonly SourceFile [ ] , checker : TypeChecker , cancellationToken : CancellationToken ) : SymbolAndEntries [ ] {
1893+ const type = getContextualTypeOrAncestorTypeNodeType ( node , checker ) ;
18931894 const references = flatMap ( sourceFiles , sourceFile => {
18941895 cancellationToken . throwIfCancellationRequested ( ) ;
1895- return mapDefined ( getPossibleSymbolReferenceNodes ( sourceFile , node . text ) , ref =>
1896- isStringLiteral ( ref ) && ref . text === node . text ? nodeEntry ( ref , EntryKind . StringLiteral ) : undefined ) ;
1896+ return mapDefined ( getPossibleSymbolReferenceNodes ( sourceFile , node . text ) , ref => {
1897+ if ( isStringLiteralLike ( ref ) && ref . text === node . text ) {
1898+ if ( type ) {
1899+ const refType = getContextualTypeOrAncestorTypeNodeType ( ref , checker ) ;
1900+ if ( type !== checker . getStringType ( ) && type === refType ) {
1901+ return nodeEntry ( ref , EntryKind . StringLiteral ) ;
1902+ }
1903+ }
1904+ else {
1905+ return nodeEntry ( ref , EntryKind . StringLiteral ) ;
1906+ }
1907+ }
1908+ } ) ;
18971909 } ) ;
18981910
18991911 return [ {
0 commit comments