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:
577577 ' @typescript-eslint/prefer-readonly ' : error
578578 ' @typescript-eslint/prefer-readonly-parameter-types ' : off # TODO consider
579579 ' @typescript-eslint/prefer-reduce-type-parameter ' : error
580- ' @typescript-eslint/prefer-regexp-exec ' : error
580+ ' @typescript-eslint/prefer-regexp-exec ' : off
581581 ' @typescript-eslint/prefer-ts-expect-error ' : error
582582 ' @typescript-eslint/prefer-string-starts-ends-with ' : off # TODO switch to error after IE11 drop
583583 ' @typescript-eslint/promise-function-async ' : off
Original file line number Diff line number Diff line change 11import type { Source } from './source' ;
22
3+ const LineRegExp = / \r \n | [ \n \r ] / g;
4+
35/**
46 * Represents a location in a Source.
57 */
@@ -13,13 +15,16 @@ export type SourceLocation = {
1315 * line and column as a SourceLocation.
1416 */
1517export function getLocation ( source : Source , position : number ) : SourceLocation {
16- const lineRegexp = / \r \n | [ \n \r ] / g ;
18+ let lastLineStart = 0 ;
1719 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 ;
2126 line += 1 ;
22- column = position + 1 - ( match . index + match [ 0 ] . length ) ;
2327 }
24- return { line, column } ;
28+
29+ return { line, column : position + 1 - lastLineStart } ;
2530}
You can’t perform that action at this time.
0 commit comments