diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index 4f471d6ab37..e3f4bd2d195 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -623,8 +623,7 @@ namespace ts.server { positionToLineOffset(position: number): protocol.Location { const location = this.textStorage.positionToLineOffset(position); - Debug.assert(typeof location.line === "number" && location.line > 0, `Expected line ${location.line} to be greater than 0.`); - Debug.assert(typeof location.offset === "number" && location.offset > 0, `Expected offset ${location.offset} to be greater than 0.`); + failIfInvalidLocation(location); return location; } @@ -645,4 +644,13 @@ namespace ts.server { } } } + + /*@internal*/ + function failIfInvalidLocation(location: protocol.Location) { + Debug.assert(typeof location.line === "number", `Expected line ${location.line} to be a number.`); + Debug.assert(typeof location.offset === "number", `Expected offset ${location.offset} to be a number.`); + + Debug.assert(location.line > 0, `Expected line to be non-${location.line === 0 ? "zero" : "negative"}`); + Debug.assert(location.offset > 0, `Expected offset to be non-${location.offset === 0 ? "zero" : "negative"}`); + } }