Skip to content

Commit 2fd3cd9

Browse files
committed
Fix bad line number assertion due to undefined leaf in LineNode
This is the line number side of ecddf84 (from #21924). I've stared at this code way too much, since I think that there is something more fundamentally wrong here. E.g., `EditWalker` only `push`es to `startPath` but never pops even a `children`-less node that is left after deleting the whole contents. But I can't figure out the overall structure, which is also why I couldn't come up with a good way to test it (and this is also similar to #21924). Fixes #44518.
1 parent 906cbd2 commit 2fd3cd9

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/server/scriptVersionCache.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ namespace ts.server {
6767
}
6868
const lm = LineIndex.linesFromText(insertedText);
6969
const lines = lm.lines;
70-
if (lines.length > 1) {
71-
if (lines[lines.length - 1] === "") {
72-
lines.pop();
73-
}
70+
if (lines.length > 1 && lines[lines.length - 1] === "") {
71+
lines.pop();
7472
}
7573
let branchParent: LineNode | undefined;
7674
let lastZeroCount: LineCollection | undefined;
@@ -684,7 +682,8 @@ namespace ts.server {
684682

685683
// Skipped all children
686684
const { leaf } = this.lineNumberToInfo(this.lineCount(), 0);
687-
return { oneBasedLine: this.lineCount(), zeroBasedColumn: leaf ? leaf.charCount() : 0, lineText: undefined };
685+
if (!leaf) return { oneBasedLine: 1, zeroBasedColumn: 0, lineText: undefined };
686+
else return { oneBasedLine: this.lineCount(), zeroBasedColumn: leaf.charCount(), lineText: undefined };
688687
}
689688

690689
/**

0 commit comments

Comments
 (0)