location.js
811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getLineInfo = getLineInfo;
exports.SourceLocation = exports.Position = void 0;
var _whitespace = require("./whitespace");
class Position {
constructor(line, col) {
this.line = line;
this.column = col;
}
}
exports.Position = Position;
class SourceLocation {
constructor(start, end) {
this.start = start;
this.end = end;
}
}
exports.SourceLocation = SourceLocation;
function getLineInfo(input, offset) {
let line = 1;
let lineStart = 0;
let match;
_whitespace.lineBreakG.lastIndex = 0;
while ((match = _whitespace.lineBreakG.exec(input)) && match.index < offset) {
line++;
lineStart = _whitespace.lineBreakG.lastIndex;
}
return new Position(line, offset - lineStart);
}