@@ -707,7 +707,7 @@ namespace ts {
707
707
return findPrecedingToken ( position , file ) ;
708
708
}
709
709
710
- export function findNextToken ( previousToken : Node , parent : Node ) : Node {
710
+ export function findNextToken ( previousToken : Node , parent : Node , sourceFile : SourceFile ) : Node {
711
711
return find ( parent ) ;
712
712
713
713
function find ( n : Node ) : Node {
@@ -724,7 +724,7 @@ namespace ts {
724
724
// previous token ends exactly at the beginning of child
725
725
( child . pos === previousToken . end ) ;
726
726
727
- if ( shouldDiveInChildNode && nodeHasTokens ( child ) ) {
727
+ if ( shouldDiveInChildNode && nodeHasTokens ( child , sourceFile ) ) {
728
728
return find ( child ) ;
729
729
}
730
730
}
@@ -759,12 +759,12 @@ namespace ts {
759
759
const start = child . getStart ( sourceFile , includeJsDoc ) ;
760
760
const lookInPreviousChild =
761
761
( start >= position ) || // cursor in the leading trivia
762
- ! nodeHasTokens ( child ) ||
762
+ ! nodeHasTokens ( child , sourceFile ) ||
763
763
isWhiteSpaceOnlyJsxText ( child ) ;
764
764
765
765
if ( lookInPreviousChild ) {
766
766
// actual start of the node is past the position - previous token should be at the end of previous child
767
- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ i ) ;
767
+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ i , sourceFile ) ;
768
768
return candidate && findRightmostToken ( candidate , sourceFile ) ;
769
769
}
770
770
else {
@@ -781,7 +781,7 @@ namespace ts {
781
781
// Try to find the rightmost token in the file without filtering.
782
782
// Namely we are skipping the check: 'position < node.end'
783
783
if ( children . length ) {
784
- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length ) ;
784
+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
785
785
return candidate && findRightmostToken ( candidate , sourceFile ) ;
786
786
}
787
787
}
@@ -797,21 +797,21 @@ namespace ts {
797
797
}
798
798
799
799
const children = n . getChildren ( sourceFile ) ;
800
- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length ) ;
800
+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
801
801
return candidate && findRightmostToken ( candidate , sourceFile ) ;
802
802
}
803
803
804
804
/**
805
805
* Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
806
806
*/
807
- function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number ) : Node | undefined {
807
+ function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number , sourceFile : SourceFile ) : Node | undefined {
808
808
for ( let i = exclusiveStartPosition - 1 ; i >= 0 ; i -- ) {
809
809
const child = children [ i ] ;
810
810
811
811
if ( isWhiteSpaceOnlyJsxText ( child ) ) {
812
812
Debug . assert ( i > 0 , "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`" ) ;
813
813
}
814
- else if ( nodeHasTokens ( children [ i ] ) ) {
814
+ else if ( nodeHasTokens ( children [ i ] , sourceFile ) ) {
815
815
return children [ i ] ;
816
816
}
817
817
}
@@ -1022,10 +1022,10 @@ namespace ts {
1022
1022
}
1023
1023
}
1024
1024
1025
- function nodeHasTokens ( n : Node ) : boolean {
1025
+ function nodeHasTokens ( n : Node , sourceFile : SourceFileLike ) : boolean {
1026
1026
// If we have a token or node that has a non-zero width, it must have tokens.
1027
1027
// Note: getWidth() does not take trivia into account.
1028
- return n . getWidth ( ) !== 0 ;
1028
+ return n . getWidth ( sourceFile ) !== 0 ;
1029
1029
}
1030
1030
1031
1031
export function getNodeModifiers ( node : Node ) : string {
0 commit comments