File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
lib/languages/js/source-code
tests/lib/languages/js/source-code Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -816,6 +816,12 @@ class SourceCode extends TokenStore {
816
816
) ;
817
817
}
818
818
819
+ if ( loc . column < 0 ) {
820
+ throw new RangeError (
821
+ `Invalid column number (column ${ loc . column } requested).` ,
822
+ ) ;
823
+ }
824
+
819
825
const lineStartIndex = this . lineStartIndices [ loc . line - 1 ] ;
820
826
const lineEndIndex =
821
827
loc . line === this . lineStartIndices . length
Original file line number Diff line number Diff line change @@ -2339,6 +2339,21 @@ describe("SourceCode", () => {
2339
2339
} ) ;
2340
2340
2341
2341
it ( "should throw a useful error if `column` is out of range" , ( ) => {
2342
+ assert . throws (
2343
+ ( ) => sourceCode . getIndexFromLoc ( { line : 1 , column : - 1 } ) ,
2344
+ "Invalid column number (column -1 requested)." ,
2345
+ ) ;
2346
+
2347
+ assert . throws (
2348
+ ( ) => sourceCode . getIndexFromLoc ( { line : 1 , column : - 5 } ) ,
2349
+ "Invalid column number (column -5 requested)." ,
2350
+ ) ;
2351
+
2352
+ assert . throws (
2353
+ ( ) => sourceCode . getIndexFromLoc ( { line : 3 , column : - 1 } ) ,
2354
+ "Invalid column number (column -1 requested)." ,
2355
+ ) ;
2356
+
2342
2357
assert . throws (
2343
2358
( ) => sourceCode . getIndexFromLoc ( { line : 3 , column : 4 } ) ,
2344
2359
/ C o l u m n n u m b e r o u t o f r a n g e \( c o l u m n 4 r e q u e s t e d , b u t t h e l e n g t h o f l i n e 3 i s 4 \) \. / u,
You can’t perform that action at this time.
0 commit comments