Commit a1746d4 Andy
authored
1 parent ded4465 commit a1746d4 Copy full SHA for a1746d4
File tree 4 files changed +10
-11
lines changed
tests/baselines/reference/api
4 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -4374,6 +4374,11 @@ namespace ts {
4374
4374
return position >= span . start && position < textSpanEnd ( span ) ;
4375
4375
}
4376
4376
4377
+ /* @internal */
4378
+ export function textRangeContainsPositionInclusive ( span : TextRange , position : number ) : boolean {
4379
+ return position >= span . pos && position <= span . end ;
4380
+ }
4381
+
4377
4382
// Returns true if 'span' contains 'other'.
4378
4383
export function textSpanContainsTextSpan ( span : TextSpan , other : TextSpan ) {
4379
4384
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 {
271
271
}
272
272
273
273
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 ) ) ;
275
275
}
276
276
277
277
function getDefinitionInfoForFileReference ( name : string , targetFileName : string ) : DefinitionInfo {
Original file line number Diff line number Diff line change @@ -729,21 +729,14 @@ namespace ts {
729
729
// this is token that starts at the end of previous token - return it
730
730
return n ;
731
731
}
732
-
733
- const children = n . getChildren ( ) ;
734
- for ( const child of children ) {
732
+ return firstDefined ( n . getChildren ( ) , child => {
735
733
const shouldDiveInChildNode =
736
734
// previous token is enclosed somewhere in the child
737
735
( child . pos <= previousToken . pos && child . end > previousToken . end ) ||
738
736
// previous token ends exactly at the beginning of child
739
737
( 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
+ } ) ;
747
740
}
748
741
}
749
742
Original file line number Diff line number Diff line change @@ -6627,6 +6627,7 @@ declare namespace ts {
6627
6627
function textSpanEnd(span: TextSpan): number;
6628
6628
function textSpanIsEmpty(span: TextSpan): boolean;
6629
6629
function textSpanContainsPosition(span: TextSpan, position: number): boolean;
6630
+ function textRangeContainsPositionInclusive(span: TextRange, position: number): boolean;
6630
6631
function textSpanContainsTextSpan(span: TextSpan, other: TextSpan): boolean;
6631
6632
function textSpanOverlapsWith(span: TextSpan, other: TextSpan): boolean;
6632
6633
function textSpanOverlap(span1: TextSpan, span2: TextSpan): TextSpan | undefined;
You can’t perform that action at this time.
0 commit comments