@@ -707,7 +707,7 @@ namespace ts {
707707 return findPrecedingToken ( position , file ) ;
708708 }
709709
710- export function findNextToken ( previousToken : Node , parent : Node ) : Node {
710+ export function findNextToken ( previousToken : Node , parent : Node , sourceFile : SourceFile ) : Node {
711711 return find ( parent ) ;
712712
713713 function find ( n : Node ) : Node {
@@ -724,7 +724,7 @@ namespace ts {
724724 // previous token ends exactly at the beginning of child
725725 ( child . pos === previousToken . end ) ;
726726
727- if ( shouldDiveInChildNode && nodeHasTokens ( child ) ) {
727+ if ( shouldDiveInChildNode && nodeHasTokens ( child , sourceFile ) ) {
728728 return find ( child ) ;
729729 }
730730 }
@@ -759,12 +759,12 @@ namespace ts {
759759 const start = child . getStart ( sourceFile , includeJsDoc ) ;
760760 const lookInPreviousChild =
761761 ( start >= position ) || // cursor in the leading trivia
762- ! nodeHasTokens ( child ) ||
762+ ! nodeHasTokens ( child , sourceFile ) ||
763763 isWhiteSpaceOnlyJsxText ( child ) ;
764764
765765 if ( lookInPreviousChild ) {
766766 // 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 ) ;
768768 return candidate && findRightmostToken ( candidate , sourceFile ) ;
769769 }
770770 else {
@@ -781,7 +781,7 @@ namespace ts {
781781 // Try to find the rightmost token in the file without filtering.
782782 // Namely we are skipping the check: 'position < node.end'
783783 if ( children . length ) {
784- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length ) ;
784+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
785785 return candidate && findRightmostToken ( candidate , sourceFile ) ;
786786 }
787787 }
@@ -797,21 +797,21 @@ namespace ts {
797797 }
798798
799799 const children = n . getChildren ( sourceFile ) ;
800- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length ) ;
800+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
801801 return candidate && findRightmostToken ( candidate , sourceFile ) ;
802802 }
803803
804804 /**
805805 * Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
806806 */
807- function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number ) : Node | undefined {
807+ function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number , sourceFile : SourceFile ) : Node | undefined {
808808 for ( let i = exclusiveStartPosition - 1 ; i >= 0 ; i -- ) {
809809 const child = children [ i ] ;
810810
811811 if ( isWhiteSpaceOnlyJsxText ( child ) ) {
812812 Debug . assert ( i > 0 , "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`" ) ;
813813 }
814- else if ( nodeHasTokens ( children [ i ] ) ) {
814+ else if ( nodeHasTokens ( children [ i ] , sourceFile ) ) {
815815 return children [ i ] ;
816816 }
817817 }
@@ -1022,10 +1022,10 @@ namespace ts {
10221022 }
10231023 }
10241024
1025- function nodeHasTokens ( n : Node ) : boolean {
1025+ function nodeHasTokens ( n : Node , sourceFile : SourceFileLike ) : boolean {
10261026 // If we have a token or node that has a non-zero width, it must have tokens.
10271027 // Note: getWidth() does not take trivia into account.
1028- return n . getWidth ( ) !== 0 ;
1028+ return n . getWidth ( sourceFile ) !== 0 ;
10291029 }
10301030
10311031 export function getNodeModifiers ( node : Node ) : string {
0 commit comments