@@ -1297,7 +1297,7 @@ namespace ts {
1297
1297
1298
1298
if ( lookInPreviousChild ) {
1299
1299
// actual start of the node is past the position - previous token should be at the end of previous child
1300
- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ i , sourceFile ) ;
1300
+ const candidate = findRightmostChildNodeWithTokens ( n , /*exclusiveStartPosition*/ i , sourceFile ) ;
1301
1301
return candidate && findRightmostToken ( candidate , sourceFile ) ;
1302
1302
}
1303
1303
else {
@@ -1313,7 +1313,7 @@ namespace ts {
1313
1313
// the only known case is when position is at the end of the file.
1314
1314
// Try to find the rightmost token in the file without filtering.
1315
1315
// Namely we are skipping the check: 'position < node.end'
1316
- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
1316
+ const candidate = findRightmostChildNodeWithTokens ( n , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
1317
1317
return candidate && findRightmostToken ( candidate , sourceFile ) ;
1318
1318
}
1319
1319
}
@@ -1332,19 +1332,20 @@ namespace ts {
1332
1332
return n ;
1333
1333
}
1334
1334
1335
- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
1335
+ const candidate = findRightmostChildNodeWithTokens ( n , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
1336
1336
return candidate && findRightmostToken ( candidate , sourceFile ) ;
1337
1337
}
1338
1338
1339
1339
/**
1340
- * Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
1340
+ * Finds the rightmost child to the left of `n. children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
1341
1341
*/
1342
- function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number , sourceFile : SourceFile ) : Node | undefined {
1342
+ function findRightmostChildNodeWithTokens ( n : Node , exclusiveStartPosition : number , sourceFile : SourceFile ) : Node | undefined {
1343
+ const children = n . getChildren ( sourceFile ) ;
1343
1344
for ( let i = exclusiveStartPosition - 1 ; i >= 0 ; i -- ) {
1344
1345
const child = children [ i ] ;
1345
1346
1346
- if ( isWhiteSpaceOnlyJsxText ( child ) ) {
1347
- Debug . assert ( i > 0 , "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`" ) ;
1347
+ if ( i === 0 && isWhiteSpaceOnlyJsxText ( child ) ) {
1348
+ Debug . assert ( ! ( isJsxElement ( n ) || isJsxSelfClosingElement ( n ) ) , "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`" ) ;
1348
1349
}
1349
1350
else if ( nodeHasTokens ( children [ i ] , sourceFile ) ) {
1350
1351
return children [ i ] ;
0 commit comments