Skip to content

Commit 9570a59

Browse files
committed
PR changes
1 parent 43c3f45 commit 9570a59

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Diff for: src/services/utilities.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -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(n, /*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(n, /*exclusiveStartPosition*/ children.length, sourceFile);
1316+
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
13171317
return candidate && findRightmostToken(candidate, sourceFile);
13181318
}
13191319
}
@@ -1332,20 +1332,21 @@ namespace ts {
13321332
return n;
13331333
}
13341334

1335-
const candidate = findRightmostChildNodeWithTokens(n, /*exclusiveStartPosition*/ children.length, sourceFile);
1335+
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
13361336
return candidate && findRightmostToken(candidate, sourceFile);
13371337
}
13381338

13391339
/**
1340-
* Finds the rightmost child to the left of `n.children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
1340+
* 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(n: Node, exclusiveStartPosition: number, sourceFile: SourceFile): Node | undefined {
1343-
const children = n.getChildren(sourceFile);
1342+
function findRightmostChildNodeWithTokens(children: Node[], exclusiveStartPosition: number, sourceFile: SourceFile, parentKind: SyntaxKind): Node | undefined {
13441343
for (let i = exclusiveStartPosition - 1; i >= 0; i--) {
13451344
const child = children[i];
13461345

1347-
if (i === 0 && isWhiteSpaceOnlyJsxText(child)) {
1348-
Debug.assert(!(isJsxElement(n) || isJsxSelfClosingElement(n)), "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
1346+
if (isWhiteSpaceOnlyJsxText(child)) {
1347+
if (parentKind === SyntaxKind.JsxText || parentKind === SyntaxKind.JsxSelfClosingElement) {
1348+
Debug.assert(i > 0, "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
1349+
}
13491350
}
13501351
else if (nodeHasTokens(children[i], sourceFile)) {
13511352
return children[i];

0 commit comments

Comments
 (0)