Skip to content

Commit 43c3f45

Browse files
committed
Modify debug assertion to avoid crashing on SyntaxList
1 parent 97017ee commit 43c3f45

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Diff for: src/services/utilities.ts

+8-7
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(children, /*exclusiveStartPosition*/ i, sourceFile);
1300+
const candidate = findRightmostChildNodeWithTokens(n, /*exclusiveStartPosition*/ i, sourceFile);
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(n, /*exclusiveStartPosition*/ children.length, sourceFile);
13171317
return candidate && findRightmostToken(candidate, sourceFile);
13181318
}
13191319
}
@@ -1332,19 +1332,20 @@ namespace ts {
13321332
return n;
13331333
}
13341334

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

13391339
/**
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.
13411341
*/
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);
13431344
for (let i = exclusiveStartPosition - 1; i >= 0; i--) {
13441345
const child = children[i];
13451346

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`");
13481349
}
13491350
else if (nodeHasTokens(children[i], sourceFile)) {
13501351
return children[i];

Diff for: tests/cases/fourslash/quickInfoOnClosingJsx.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: foo.tsx
4+
////let x = <div>
5+
//// /*$*/</div >
6+
7+
goTo.marker("$");
8+
verify.not.quickInfoExists();

0 commit comments

Comments
 (0)