File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -622,7 +622,10 @@ namespace ts.server {
622
622
}
623
623
624
624
positionToLineOffset ( position : number ) : protocol . Location {
625
- return this . textStorage . positionToLineOffset ( position ) ;
625
+ failIfInvalidPosition ( position ) ;
626
+ const location = this . textStorage . positionToLineOffset ( position ) ;
627
+ failIfInvalidLocation ( location ) ;
628
+ return location ;
626
629
}
627
630
628
631
public isJavaScript ( ) {
@@ -642,4 +645,17 @@ namespace ts.server {
642
645
}
643
646
}
644
647
}
648
+
649
+ function failIfInvalidPosition ( position : number ) {
650
+ Debug . assert ( typeof position === "number" , `Expected position ${ position } to be a number.` ) ;
651
+ Debug . assert ( position >= 0 , `Expected position to be non-negative.` ) ;
652
+ }
653
+
654
+ function failIfInvalidLocation ( location : protocol . Location ) {
655
+ Debug . assert ( typeof location . line === "number" , `Expected line ${ location . line } to be a number.` ) ;
656
+ Debug . assert ( typeof location . offset === "number" , `Expected offset ${ location . offset } to be a number.` ) ;
657
+
658
+ Debug . assert ( location . line > 0 , `Expected line to be non-${ location . line === 0 ? "zero" : "negative" } ` ) ;
659
+ Debug . assert ( location . offset > 0 , `Expected offset to be non-${ location . offset === 0 ? "zero" : "negative" } ` ) ;
660
+ }
645
661
}
You can’t perform that action at this time.
0 commit comments