From 42dc4155ce13d80f31875d2525f64e31e4180927 Mon Sep 17 00:00:00 2001 From: Ben Lichtman Date: Tue, 17 Dec 2019 17:41:38 -0800 Subject: [PATCH] Refactor to make failure messages more consistent --- src/server/scriptInfo.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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"}`); + } }