File tree Expand file tree Collapse file tree
tests/baselines/reference/api Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4374,6 +4374,11 @@ namespace ts {
43744374 return position >= span . start && position < textSpanEnd ( span ) ;
43754375 }
43764376
4377+ /* @internal */
4378+ export function textRangeContainsPositionInclusive ( span : TextRange , position : number ) : boolean {
4379+ return position >= span . pos && position <= span . end ;
4380+ }
4381+
43774382 // Returns true if 'span' contains 'other'.
43784383 export function textSpanContainsTextSpan ( span : TextSpan , other : TextSpan ) {
43794384 return other . start >= span . start && textSpanEnd ( other ) <= textSpanEnd ( span ) ;
Original file line number Diff line number Diff line change @@ -271,7 +271,7 @@ namespace ts.GoToDefinition {
271271 }
272272
273273 export function findReferenceInPosition ( refs : ReadonlyArray < FileReference > , pos : number ) : FileReference | undefined {
274- return find ( refs , ref => ref . pos <= pos && pos <= ref . end ) ;
274+ return find ( refs , ref => textRangeContainsPositionInclusive ( ref , pos ) ) ;
275275 }
276276
277277 function getDefinitionInfoForFileReference ( name : string , targetFileName : string ) : DefinitionInfo {
Original file line number Diff line number Diff line change @@ -729,21 +729,14 @@ namespace ts {
729729 // this is token that starts at the end of previous token - return it
730730 return n ;
731731 }
732-
733- const children = n . getChildren ( ) ;
734- for ( const child of children ) {
732+ return firstDefined ( n . getChildren ( ) , child => {
735733 const shouldDiveInChildNode =
736734 // previous token is enclosed somewhere in the child
737735 ( child . pos <= previousToken . pos && child . end > previousToken . end ) ||
738736 // previous token ends exactly at the beginning of child
739737 ( child . pos === previousToken . end ) ;
740-
741- if ( shouldDiveInChildNode && nodeHasTokens ( child , sourceFile ) ) {
742- return find ( child ) ;
743- }
744- }
745-
746- return undefined ;
738+ return shouldDiveInChildNode && nodeHasTokens ( child , sourceFile ) ? find ( child ) : undefined ;
739+ } ) ;
747740 }
748741 }
749742
Original file line number Diff line number Diff line change @@ -6627,6 +6627,7 @@ declare namespace ts {
66276627 function textSpanEnd(span: TextSpan): number;
66286628 function textSpanIsEmpty(span: TextSpan): boolean;
66296629 function textSpanContainsPosition(span: TextSpan, position: number): boolean;
6630+ function textRangeContainsPositionInclusive(span: TextRange, position: number): boolean;
66306631 function textSpanContainsTextSpan(span: TextSpan, other: TextSpan): boolean;
66316632 function textSpanOverlapsWith(span: TextSpan, other: TextSpan): boolean;
66326633 function textSpanOverlap(span1: TextSpan, span2: TextSpan): TextSpan | undefined;
You can’t perform that action at this time.
0 commit comments