mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Component commits:43c3f45fd0Modify debug assertion to avoid crashing on SyntaxList9570a59da4PR changese9a2355e80More PR feedback Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
co-authored by
Jake Bailey
parent
84509012f3
commit
c5ce1706f4
@@ -1304,7 +1304,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(children, /*exclusiveStartPosition*/ i, sourceFile, n.kind);
|
||||
return candidate && findRightmostToken(candidate, sourceFile);
|
||||
}
|
||||
else {
|
||||
@@ -1320,7 +1320,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(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
|
||||
return candidate && findRightmostToken(candidate, sourceFile);
|
||||
}
|
||||
}
|
||||
@@ -1339,19 +1339,21 @@ namespace ts {
|
||||
return n;
|
||||
}
|
||||
|
||||
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
|
||||
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
|
||||
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.
|
||||
*/
|
||||
function findRightmostChildNodeWithTokens(children: Node[], exclusiveStartPosition: number, sourceFile: SourceFile): Node | undefined {
|
||||
function findRightmostChildNodeWithTokens(children: Node[], exclusiveStartPosition: number, sourceFile: SourceFile, parentKind: SyntaxKind): Node | undefined {
|
||||
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 && (parentKind === SyntaxKind.JsxText || parentKind === SyntaxKind.JsxSelfClosingElement)) {
|
||||
Debug.fail("`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
|
||||
}
|
||||
}
|
||||
else if (nodeHasTokens(children[i], sourceFile)) {
|
||||
return children[i];
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @Filename: foo.tsx
|
||||
////let x = <div>
|
||||
//// /*$*/</div >
|
||||
|
||||
goTo.marker("$");
|
||||
verify.not.quickInfoExists();
|
||||
Reference in New Issue
Block a user