Skip to content

Commit c5ce170

Browse files
TypeScript Botjakebailey
TypeScript Bot
andauthored
Cherry-pick PR #47500 into release-4.5 (#47514)
Component commits: 43c3f45 Modify debug assertion to avoid crashing on SyntaxList 9570a59 PR changes e9a2355 More PR feedback Co-authored-by: Jake Bailey <[email protected]>
1 parent 8450901 commit c5ce170

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Diff for: src/services/utilities.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -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];

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)