From 43c3f45fd0410ae62a2130d536acf79f39ff6c9a Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Tue, 18 Jan 2022 18:55:09 -0800
Subject: [PATCH 1/3] Modify debug assertion to avoid crashing on SyntaxList
---
src/services/utilities.ts | 15 ++++++++-------
tests/cases/fourslash/quickInfoOnClosingJsx.ts | 8 ++++++++
2 files changed, 16 insertions(+), 7 deletions(-)
create mode 100644 tests/cases/fourslash/quickInfoOnClosingJsx.ts
diff --git a/src/services/utilities.ts b/src/services/utilities.ts
index 146e3fb0260e8..a9d37325328d8 100644
--- a/src/services/utilities.ts
+++ b/src/services/utilities.ts
@@ -1297,7 +1297,7 @@ namespace ts {
if (lookInPreviousChild) {
// actual start of the node is past the position - previous token should be at the end of previous child
- const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile);
+ const candidate = findRightmostChildNodeWithTokens(n, /*exclusiveStartPosition*/ i, sourceFile);
return candidate && findRightmostToken(candidate, sourceFile);
}
else {
@@ -1313,7 +1313,7 @@ namespace ts {
// the only known case is when position is at the end of the file.
// Try to find the rightmost token in the file without filtering.
// Namely we are skipping the check: 'position < node.end'
- const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
+ const candidate = findRightmostChildNodeWithTokens(n, /*exclusiveStartPosition*/ children.length, sourceFile);
return candidate && findRightmostToken(candidate, sourceFile);
}
}
@@ -1332,19 +1332,20 @@ namespace ts {
return n;
}
- const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
+ const candidate = findRightmostChildNodeWithTokens(n, /*exclusiveStartPosition*/ children.length, sourceFile);
return candidate && findRightmostToken(candidate, sourceFile);
}
/**
- * Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
+ * Finds the rightmost child to the left of `n.children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
*/
- function findRightmostChildNodeWithTokens(children: Node[], exclusiveStartPosition: number, sourceFile: SourceFile): Node | undefined {
+ function findRightmostChildNodeWithTokens(n: Node, exclusiveStartPosition: number, sourceFile: SourceFile): Node | undefined {
+ const children = n.getChildren(sourceFile);
for (let i = exclusiveStartPosition - 1; i >= 0; i--) {
const child = children[i];
- if (isWhiteSpaceOnlyJsxText(child)) {
- Debug.assert(i > 0, "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
+ if (i === 0 && isWhiteSpaceOnlyJsxText(child)) {
+ Debug.assert(!(isJsxElement(n) || isJsxSelfClosingElement(n)), "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
}
else if (nodeHasTokens(children[i], sourceFile)) {
return children[i];
diff --git a/tests/cases/fourslash/quickInfoOnClosingJsx.ts b/tests/cases/fourslash/quickInfoOnClosingJsx.ts
new file mode 100644
index 0000000000000..bdee39457c91f
--- /dev/null
+++ b/tests/cases/fourslash/quickInfoOnClosingJsx.ts
@@ -0,0 +1,8 @@
+///