@@ -1297,7 +1297,7 @@ namespace ts {
12971297
12981298 if ( lookInPreviousChild ) {
12991299 // 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 ( children , /*exclusiveStartPosition*/ i , sourceFile , n . kind ) ;
13011301 return candidate && findRightmostToken ( candidate , sourceFile ) ;
13021302 }
13031303 else {
@@ -1313,7 +1313,7 @@ namespace ts {
13131313 // the only known case is when position is at the end of the file.
13141314 // Try to find the rightmost token in the file without filtering.
13151315 // Namely we are skipping the check: 'position < node.end'
1316- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
1316+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile , n . kind ) ;
13171317 return candidate && findRightmostToken ( candidate , sourceFile ) ;
13181318 }
13191319 }
@@ -1332,19 +1332,21 @@ namespace ts {
13321332 return n ;
13331333 }
13341334
1335- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
1335+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile , n . kind ) ;
13361336 return candidate && findRightmostToken ( candidate , sourceFile ) ;
13371337 }
13381338
13391339 /**
13401340 * Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
13411341 */
1342- function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number , sourceFile : SourceFile ) : Node | undefined {
1342+ function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number , sourceFile : SourceFile , parentKind : SyntaxKind ) : Node | undefined {
13431343 for ( let i = exclusiveStartPosition - 1 ; i >= 0 ; i -- ) {
13441344 const child = children [ i ] ;
13451345
13461346 if ( isWhiteSpaceOnlyJsxText ( child ) ) {
1347- Debug . assert ( i > 0 , "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`" ) ;
1347+ if ( i === 0 && ( parentKind === SyntaxKind . JsxText || parentKind === SyntaxKind . JsxSelfClosingElement ) ) {
1348+ Debug . fail ( "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`" ) ;
1349+ }
13481350 }
13491351 else if ( nodeHasTokens ( children [ i ] , sourceFile ) ) {
13501352 return children [ i ] ;
0 commit comments