@@ -1304,7 +1304,7 @@ namespace ts {
1304
1304
1305
1305
if ( lookInPreviousChild ) {
1306
1306
// actual start of the node is past the position - previous token should be at the end of previous child
1307
- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ i , sourceFile ) ;
1307
+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ i , sourceFile , n . kind ) ;
1308
1308
return candidate && findRightmostToken ( candidate , sourceFile ) ;
1309
1309
}
1310
1310
else {
@@ -1320,7 +1320,7 @@ namespace ts {
1320
1320
// the only known case is when position is at the end of the file.
1321
1321
// Try to find the rightmost token in the file without filtering.
1322
1322
// Namely we are skipping the check: 'position < node.end'
1323
- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
1323
+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile , n . kind ) ;
1324
1324
return candidate && findRightmostToken ( candidate , sourceFile ) ;
1325
1325
}
1326
1326
}
@@ -1339,19 +1339,21 @@ namespace ts {
1339
1339
return n ;
1340
1340
}
1341
1341
1342
- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
1342
+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile , n . kind ) ;
1343
1343
return candidate && findRightmostToken ( candidate , sourceFile ) ;
1344
1344
}
1345
1345
1346
1346
/**
1347
1347
* Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
1348
1348
*/
1349
- function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number , sourceFile : SourceFile ) : Node | undefined {
1349
+ function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number , sourceFile : SourceFile , parentKind : SyntaxKind ) : Node | undefined {
1350
1350
for ( let i = exclusiveStartPosition - 1 ; i >= 0 ; i -- ) {
1351
1351
const child = children [ i ] ;
1352
1352
1353
1353
if ( isWhiteSpaceOnlyJsxText ( child ) ) {
1354
- Debug . assert ( i > 0 , "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`" ) ;
1354
+ if ( i === 0 && ( parentKind === SyntaxKind . JsxText || parentKind === SyntaxKind . JsxSelfClosingElement ) ) {
1355
+ Debug . fail ( "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`" ) ;
1356
+ }
1355
1357
}
1356
1358
else if ( nodeHasTokens ( children [ i ] , sourceFile ) ) {
1357
1359
return children [ i ] ;
0 commit comments