@@ -1304,7 +1304,7 @@ namespace ts {
13041304
13051305 if ( lookInPreviousChild ) {
13061306 // 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 ) ;
13081308 return candidate && findRightmostToken ( candidate , sourceFile ) ;
13091309 }
13101310 else {
@@ -1320,7 +1320,7 @@ namespace ts {
13201320 // the only known case is when position is at the end of the file.
13211321 // Try to find the rightmost token in the file without filtering.
13221322 // 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 ) ;
13241324 return candidate && findRightmostToken ( candidate , sourceFile ) ;
13251325 }
13261326 }
@@ -1339,19 +1339,21 @@ namespace ts {
13391339 return n ;
13401340 }
13411341
1342- const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile ) ;
1342+ const candidate = findRightmostChildNodeWithTokens ( children , /*exclusiveStartPosition*/ children . length , sourceFile , n . kind ) ;
13431343 return candidate && findRightmostToken ( candidate , sourceFile ) ;
13441344 }
13451345
13461346 /**
13471347 * Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
13481348 */
1349- function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number , sourceFile : SourceFile ) : Node | undefined {
1349+ function findRightmostChildNodeWithTokens ( children : Node [ ] , exclusiveStartPosition : number , sourceFile : SourceFile , parentKind : SyntaxKind ) : Node | undefined {
13501350 for ( let i = exclusiveStartPosition - 1 ; i >= 0 ; i -- ) {
13511351 const child = children [ i ] ;
13521352
13531353 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+ }
13551357 }
13561358 else if ( nodeHasTokens ( children [ i ] , sourceFile ) ) {
13571359 return children [ i ] ;
0 commit comments