Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/server/scriptInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,10 @@ namespace ts.server {
}

positionToLineOffset(position: number): protocol.Location {
return this.textStorage.positionToLineOffset(position);
failIfInvalidPosition(position);
const location = this.textStorage.positionToLineOffset(position);
failIfInvalidLocation(location);
return location;
}

public isJavaScript() {
Expand All @@ -642,4 +645,17 @@ namespace ts.server {
}
}
}

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.`);

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"}`);
}
}