mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 11:24:49 -05:00
Merge pull request #35742 from uniqueiniquity/addPositionAssert
Add asserts to narrow down position issue
This commit is contained in:
@@ -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() {
|
||||
@@ -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"}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user