@@ -637,7 +637,9 @@ namespace ts.FindAllReferences.Core {
637
637
return parent ? scope . getSourceFile ( ) : scope ;
638
638
}
639
639
640
- function getPossibleSymbolReferencePositions ( sourceFile : SourceFile , symbolName : string , start : number , end : number ) : number [ ] {
640
+ function getPossibleSymbolReferencePositions ( sourceFile : SourceFile , symbolName : string , container : Node = sourceFile , fullStart = false ) : number [ ] {
641
+ const start = fullStart ? container . getFullStart ( ) : container . getStart ( sourceFile ) ;
642
+ const end = container . getEnd ( ) ;
641
643
const positions : number [ ] = [ ] ;
642
644
643
645
/// TODO: Cache symbol existence for files to save text search
@@ -676,16 +678,11 @@ namespace ts.FindAllReferences.Core {
676
678
const references : Entry [ ] = [ ] ;
677
679
const sourceFile = container . getSourceFile ( ) ;
678
680
const labelName = targetLabel . text ;
679
- const possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , labelName , container . getStart ( ) , container . getEnd ( ) ) ;
681
+ const possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , labelName , container ) ;
680
682
for ( const position of possiblePositions ) {
681
683
const node = getTouchingWord ( sourceFile , position ) ;
682
- if ( ! node || node . getWidth ( ) !== labelName . length ) {
683
- continue ;
684
- }
685
-
686
684
// Only pick labels that are either the target label, or have a target that is the target label
687
- if ( node === targetLabel ||
688
- ( isJumpStatementTarget ( node ) && getTargetLabel ( node , labelName ) === targetLabel ) ) {
685
+ if ( node && ( node === targetLabel || ( isJumpStatementTarget ( node ) && getTargetLabel ( node , labelName ) === targetLabel ) ) ) {
689
686
references . push ( nodeEntry ( node ) ) ;
690
687
}
691
688
}
@@ -697,15 +694,14 @@ namespace ts.FindAllReferences.Core {
697
694
// Compare the length so we filter out strict superstrings of the symbol we are looking for
698
695
switch ( node && node . kind ) {
699
696
case SyntaxKind . Identifier :
700
- return node . getWidth ( ) === searchSymbolName . length ;
697
+ return unescapeIdentifier ( ( node as Identifier ) . text ) . length === searchSymbolName . length ;
701
698
702
699
case SyntaxKind . StringLiteral :
703
700
return ( isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) || isNameOfExternalModuleImportOrDeclaration ( node ) ) &&
704
- // For string literals we have two additional chars for the quotes
705
- node . getWidth ( ) === searchSymbolName . length + 2 ;
701
+ ( node as StringLiteral ) . text . length === searchSymbolName . length ;
706
702
707
703
case SyntaxKind . NumericLiteral :
708
- return isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) && node . getWidth ( ) === searchSymbolName . length ;
704
+ return isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) && ( node as NumericLiteral ) . text . length === searchSymbolName . length ;
709
705
710
706
default :
711
707
return false ;
@@ -722,7 +718,7 @@ namespace ts.FindAllReferences.Core {
722
718
}
723
719
724
720
function addReferencesForKeywordInFile ( sourceFile : SourceFile , kind : SyntaxKind , searchText : string , references : Push < NodeEntry > ) : void {
725
- const possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , searchText , sourceFile . getStart ( ) , sourceFile . getEnd ( ) ) ;
721
+ const possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , searchText ) ;
726
722
for ( const position of possiblePositions ) {
727
723
const referenceLocation = getTouchingPropertyName ( sourceFile , position ) ;
728
724
if ( referenceLocation . kind === kind ) {
@@ -746,9 +742,7 @@ namespace ts.FindAllReferences.Core {
746
742
return ;
747
743
}
748
744
749
- const start = state . findInComments ? container . getFullStart ( ) : container . getStart ( ) ;
750
- const possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , search . text , start , container . getEnd ( ) ) ;
751
- for ( const position of possiblePositions ) {
745
+ for ( const position of getPossibleSymbolReferencePositions ( sourceFile , search . text , container , /*fullStart*/ state . findInComments ) ) {
752
746
getReferencesAtLocation ( sourceFile , position , search , state ) ;
753
747
}
754
748
}
@@ -1192,7 +1186,7 @@ namespace ts.FindAllReferences.Core {
1192
1186
const references : Entry [ ] = [ ] ;
1193
1187
1194
1188
const sourceFile = searchSpaceNode . getSourceFile ( ) ;
1195
- const possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "super" , searchSpaceNode . getStart ( ) , searchSpaceNode . getEnd ( ) ) ;
1189
+ const possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "super" , searchSpaceNode ) ;
1196
1190
for ( const position of possiblePositions ) {
1197
1191
const node = getTouchingWord ( sourceFile , position ) ;
1198
1192
@@ -1254,13 +1248,13 @@ namespace ts.FindAllReferences.Core {
1254
1248
if ( searchSpaceNode . kind === SyntaxKind . SourceFile ) {
1255
1249
forEach ( sourceFiles , sourceFile => {
1256
1250
cancellationToken . throwIfCancellationRequested ( ) ;
1257
- possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "this" , sourceFile . getStart ( ) , sourceFile . getEnd ( ) ) ;
1251
+ possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "this" ) ;
1258
1252
getThisReferencesInFile ( sourceFile , sourceFile , possiblePositions , references ) ;
1259
1253
} ) ;
1260
1254
}
1261
1255
else {
1262
1256
const sourceFile = searchSpaceNode . getSourceFile ( ) ;
1263
- possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "this" , searchSpaceNode . getStart ( ) , searchSpaceNode . getEnd ( ) ) ;
1257
+ possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , "this" , searchSpaceNode ) ;
1264
1258
getThisReferencesInFile ( sourceFile , searchSpaceNode , possiblePositions , references ) ;
1265
1259
}
1266
1260
@@ -1314,7 +1308,7 @@ namespace ts.FindAllReferences.Core {
1314
1308
1315
1309
for ( const sourceFile of sourceFiles ) {
1316
1310
cancellationToken . throwIfCancellationRequested ( ) ;
1317
- const possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , node . text , sourceFile . getStart ( ) , sourceFile . getEnd ( ) ) ;
1311
+ const possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , node . text ) ;
1318
1312
getReferencesForStringLiteralInFile ( sourceFile , node . text , possiblePositions , references ) ;
1319
1313
}
1320
1314
0 commit comments