Skip to content

Commit 42dc415

Browse files
author
Ben Lichtman
committed
Refactor to make failure messages more consistent
1 parent 925582d commit 42dc415

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/server/scriptInfo.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,7 @@ namespace ts.server {
623623

624624
positionToLineOffset(position: number): protocol.Location {
625625
const location = this.textStorage.positionToLineOffset(position);
626-
Debug.assert(typeof location.line === "number" && location.line > 0, `Expected line ${location.line} to be greater than 0.`);
627-
Debug.assert(typeof location.offset === "number" && location.offset > 0, `Expected offset ${location.offset} to be greater than 0.`);
626+
failIfInvalidLocation(location);
628627
return location;
629628
}
630629

@@ -645,4 +644,13 @@ namespace ts.server {
645644
}
646645
}
647646
}
647+
648+
/*@internal*/
649+
function failIfInvalidLocation(location: protocol.Location) {
650+
Debug.assert(typeof location.line === "number", `Expected line ${location.line} to be a number.`);
651+
Debug.assert(typeof location.offset === "number", `Expected offset ${location.offset} to be a number.`);
652+
653+
Debug.assert(location.line > 0, `Expected line to be non-${location.line === 0 ? "zero" : "negative"}`);
654+
Debug.assert(location.offset > 0, `Expected offset to be non-${location.offset === 0 ? "zero" : "negative"}`);
655+
}
648656
}

0 commit comments

Comments
 (0)