File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -577,7 +577,7 @@ overrides:
577
577
' @typescript-eslint/prefer-readonly ' : error
578
578
' @typescript-eslint/prefer-readonly-parameter-types ' : off # TODO consider
579
579
' @typescript-eslint/prefer-reduce-type-parameter ' : error
580
- ' @typescript-eslint/prefer-regexp-exec ' : error
580
+ ' @typescript-eslint/prefer-regexp-exec ' : off
581
581
' @typescript-eslint/prefer-ts-expect-error ' : error
582
582
' @typescript-eslint/prefer-string-starts-ends-with ' : off # TODO switch to error after IE11 drop
583
583
' @typescript-eslint/promise-function-async ' : off
Original file line number Diff line number Diff line change 1
1
import type { Source } from './source' ;
2
2
3
+ const LineRegExp = / \r \n | [ \n \r ] / g;
4
+
3
5
/**
4
6
* Represents a location in a Source.
5
7
*/
@@ -13,13 +15,16 @@ export type SourceLocation = {
13
15
* line and column as a SourceLocation.
14
16
*/
15
17
export function getLocation ( source : Source , position : number ) : SourceLocation {
16
- const lineRegexp = / \r \n | [ \n \r ] / g ;
18
+ let lastLineStart = 0 ;
17
19
let line = 1 ;
18
- let column = position + 1 ;
19
- let match ;
20
- while ( ( match = lineRegexp . exec ( source . body ) ) && match . index < position ) {
20
+
21
+ for ( const match of source . body . matchAll ( LineRegExp ) ) {
22
+ if ( match . index >= position ) {
23
+ break ;
24
+ }
25
+ lastLineStart = match . index + match [ 0 ] . length ;
21
26
line += 1 ;
22
- column = position + 1 - ( match . index + match [ 0 ] . length ) ;
23
27
}
24
- return { line, column } ;
28
+
29
+ return { line, column : position + 1 - lastLineStart } ;
25
30
}
You can’t perform that action at this time.
0 commit comments