From 9f1e389441bb5ec92338c216df45efbcd0a008de Mon Sep 17 00:00:00 2001 From: Ben Lichtman Date: Wed, 18 Dec 2019 10:44:40 -0800 Subject: [PATCH] Remove unnecessary internal tags, handle bad input --- src/server/scriptInfo.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index e3f4bd2d195..53bbc6cba75 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -622,6 +622,7 @@ namespace ts.server { } positionToLineOffset(position: number): protocol.Location { + failIfInvalidPosition(position); const location = this.textStorage.positionToLineOffset(position); failIfInvalidLocation(location); return location; @@ -645,7 +646,11 @@ namespace ts.server { } } - /*@internal*/ + function failIfInvalidPosition(position: number) { + Debug.assert(typeof position === "number", `Expected position ${position} to be a number.`); + Debug.assert(position >= 0, `Expected position to be non-negative.`); + } + 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.`);