@@ -5,12 +5,13 @@ namespace ts.FindAllReferences {
55 references : Entry [ ] ;
66 }
77
8+ export const enum DefinitionKind { Symbol , Label , Keyword , This , String }
89 export type Definition =
9- | { type : "symbol" ; symbol : Symbol }
10- | { type : "label" ; node : Identifier }
11- | { type : "keyword" ; node : Node }
12- | { type : "this" ; node : Node }
13- | { type : "string" ; node : StringLiteral } ;
10+ | { readonly type : DefinitionKind . Symbol ; readonly symbol : Symbol }
11+ | { readonly type : DefinitionKind . Label ; readonly node : Identifier }
12+ | { readonly type : DefinitionKind . Keyword ; readonly node : Node }
13+ | { readonly type : DefinitionKind . This ; readonly node : Node }
14+ | { readonly type : DefinitionKind . String ; readonly node : StringLiteral } ;
1415
1516 export type Entry = NodeEntry | SpanEntry ;
1617 export interface NodeEntry {
@@ -98,29 +99,29 @@ namespace ts.FindAllReferences {
9899 function definitionToReferencedSymbolDefinitionInfo ( def : Definition , checker : TypeChecker , originalNode : Node ) : ReferencedSymbolDefinitionInfo {
99100 const info = ( ( ) => {
100101 switch ( def . type ) {
101- case "symbol" : {
102+ case DefinitionKind . Symbol : {
102103 const { symbol } = def ;
103104 const { displayParts, kind } = getDefinitionKindAndDisplayParts ( symbol , checker , originalNode ) ;
104105 const name = displayParts . map ( p => p . text ) . join ( "" ) ;
105106 return { node : symbol . declarations ? getNameOfDeclaration ( first ( symbol . declarations ) ) || first ( symbol . declarations ) : originalNode , name, kind, displayParts } ;
106107 }
107- case "label" : {
108+ case DefinitionKind . Label : {
108109 const { node } = def ;
109110 return { node, name : node . text , kind : ScriptElementKind . label , displayParts : [ displayPart ( node . text , SymbolDisplayPartKind . text ) ] } ;
110111 }
111- case "keyword" : {
112+ case DefinitionKind . Keyword : {
112113 const { node } = def ;
113114 const name = tokenToString ( node . kind ) ! ;
114115 return { node, name, kind : ScriptElementKind . keyword , displayParts : [ { text : name , kind : ScriptElementKind . keyword } ] } ;
115116 }
116- case "this" : {
117+ case DefinitionKind . This : {
117118 const { node } = def ;
118119 const symbol = checker . getSymbolAtLocation ( node ) ;
119120 const displayParts = symbol && SymbolDisplay . getSymbolDisplayPartsDocumentationAndSymbolKind (
120121 checker , symbol , node . getSourceFile ( ) , getContainerNode ( node ) , node ) . displayParts || [ textPart ( "this" ) ] ;
121122 return { node, name : "this" , kind : ScriptElementKind . variableElement , displayParts } ;
122123 }
123- case "string" : {
124+ case DefinitionKind . String : {
124125 const { node } = def ;
125126 return { node, name : node . text , kind : ScriptElementKind . variableElement , displayParts : [ displayPart ( getTextOfNode ( node ) , SymbolDisplayPartKind . stringLiteral ) ] } ;
126127 }
@@ -374,7 +375,7 @@ namespace ts.FindAllReferences.Core {
374375 }
375376 }
376377
377- return references . length ? [ { definition : { type : "symbol" , symbol } , references } ] : emptyArray ;
378+ return references . length ? [ { definition : { type : DefinitionKind . Symbol , symbol } , references } ] : emptyArray ;
378379 }
379380
380381 /** getReferencedSymbols for special node kinds. */
@@ -585,7 +586,7 @@ namespace ts.FindAllReferences.Core {
585586 let references = this . symbolIdToReferences [ symbolId ] ;
586587 if ( ! references ) {
587588 references = this . symbolIdToReferences [ symbolId ] = [ ] ;
588- this . result . push ( { definition : { type : "symbol" , symbol : searchSymbol } , references } ) ;
589+ this . result . push ( { definition : { type : DefinitionKind . Symbol , symbol : searchSymbol } , references } ) ;
589590 }
590591 return node => references . push ( nodeEntry ( node ) ) ;
591592 }
@@ -879,7 +880,7 @@ namespace ts.FindAllReferences.Core {
879880 const references = mapDefined ( getPossibleSymbolReferenceNodes ( sourceFile , labelName , container ) , node =>
880881 // Only pick labels that are either the target label, or have a target that is the target label
881882 node === targetLabel || ( isJumpStatementTarget ( node ) && getTargetLabel ( node , labelName ) === targetLabel ) ? nodeEntry ( node ) : undefined ) ;
882- return [ { definition : { type : "label" , node : targetLabel } , references } ] ;
883+ return [ { definition : { type : DefinitionKind . Label , node : targetLabel } , references } ] ;
883884 }
884885
885886 function isValidReferencePosition ( node : Node , searchSymbolName : string ) : boolean {
@@ -911,7 +912,7 @@ namespace ts.FindAllReferences.Core {
911912 return mapDefined ( getPossibleSymbolReferenceNodes ( sourceFile , tokenToString ( keywordKind ) ! , sourceFile ) , referenceLocation =>
912913 referenceLocation . kind === keywordKind ? nodeEntry ( referenceLocation ) : undefined ) ;
913914 } ) ;
914- return references . length ? [ { definition : { type : "keyword" , node : references [ 0 ] . node } , references } ] : undefined ;
915+ return references . length ? [ { definition : { type : DefinitionKind . Keyword , node : references [ 0 ] . node } , references } ] : undefined ;
915916 }
916917
917918 function getReferencesInSourceFile ( sourceFile : SourceFile , search : Search , state : State , addReferencesHere = true ) : void {
@@ -1353,7 +1354,7 @@ namespace ts.FindAllReferences.Core {
13531354 return container && ( ModifierFlags . Static & getModifierFlags ( container ) ) === staticFlag && container . parent . symbol === searchSpaceNode . symbol ? nodeEntry ( node ) : undefined ;
13541355 } ) ;
13551356
1356- return [ { definition : { type : "symbol" , symbol : searchSpaceNode . symbol } , references } ] ;
1357+ return [ { definition : { type : DefinitionKind . Symbol , symbol : searchSpaceNode . symbol } , references } ] ;
13571358 }
13581359
13591360 function getReferencesForThisKeyword ( thisOrSuperKeyword : Node , sourceFiles : ReadonlyArray < SourceFile > , cancellationToken : CancellationToken ) : SymbolAndEntries [ ] | undefined {
@@ -1416,8 +1417,9 @@ namespace ts.FindAllReferences.Core {
14161417 } ) ;
14171418 } ) . map ( n => nodeEntry ( n ) ) ;
14181419
1420+ const thisParameter = firstDefined ( references , r => isParameter ( r . node . parent ) ? r . node : undefined ) ;
14191421 return [ {
1420- definition : { type : "this" , node : thisOrSuperKeyword } ,
1422+ definition : { type : DefinitionKind . This , node : thisParameter || thisOrSuperKeyword } ,
14211423 references
14221424 } ] ;
14231425 }
@@ -1430,7 +1432,7 @@ namespace ts.FindAllReferences.Core {
14301432 } ) ;
14311433
14321434 return [ {
1433- definition : { type : "string" , node } ,
1435+ definition : { type : DefinitionKind . String , node } ,
14341436 references
14351437 } ] ;
14361438 }
0 commit comments