parent
72ee1816a4
commit
edbffda091
@ -39,16 +39,14 @@ export class SourceLocation {
|
|||||||
// into.
|
// into.
|
||||||
|
|
||||||
export function getLineInfo(input: string, offset: number): Position {
|
export function getLineInfo(input: string, offset: number): Position {
|
||||||
for (let line = 1, cur = 0; ; ) {
|
let line = 1;
|
||||||
lineBreakG.lastIndex = cur;
|
let lineStart = 0;
|
||||||
const match = lineBreakG.exec(input);
|
let match;
|
||||||
if (match && match.index < offset) {
|
lineBreakG.lastIndex = 0;
|
||||||
++line;
|
while ((match = lineBreakG.exec(input)) && match.index < offset) {
|
||||||
cur = match.index + match[0].length;
|
line++;
|
||||||
} else {
|
lineStart = lineBreakG.lastIndex;
|
||||||
return new Position(line, offset - cur);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// istanbul ignore next
|
|
||||||
throw new Error("Unreachable");
|
return new Position(line, offset - lineStart);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user