New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify debug assertion to avoid crashing on SyntaxList #47500
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why the index check moved into the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shoot, you're right! I was trying to be too clever and optimize the assert, but I completely tunnel visioned away the code below. Will revert. |
||
Debug.assert(!(isJsxElement(n) || isJsxSelfClosingElement(n)), "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`"); | ||
} | ||
else if (nodeHasTokens(children[i], sourceFile)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of scope, but should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this seems like an oops. I can fix this, if desired. Shouldn't change anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe as a follow-up. |
||
return children[i]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @Filename: foo.tsx | ||
////let x = <div> | ||
//// /*$*/</div > | ||
|
||
goTo.marker("$"); | ||
verify.not.quickInfoExists(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I should bother leaving
children
as a parameter to save a little bit of processing; seemed more clear to me to just pass down the parent node and get the children, rather than passing the parent with its children (all call sites technically have the list).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like
n
is only needed for its kind and that kind is only needed for an assert so, personally, I'd add a new parameter for the kind to make it clear that it's "extra".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched it to that.