1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.SourceLocation = exports.Position = undefined;
|
7 |
|
8 | var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
|
9 |
|
10 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
11 |
|
12 | exports.getLineInfo = getLineInfo;
|
13 |
|
14 | var _whitespace = require("./whitespace");
|
15 |
|
16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var Position = exports.Position = function Position(line, col) {
|
22 | (0, _classCallCheck3.default)(this, Position);
|
23 |
|
24 | this.line = line;
|
25 | this.column = col;
|
26 | };
|
27 |
|
28 | var SourceLocation = exports.SourceLocation = function SourceLocation(start, end) {
|
29 | (0, _classCallCheck3.default)(this, SourceLocation);
|
30 |
|
31 | this.start = start;
|
32 | this.end = end;
|
33 | };
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function getLineInfo(input, offset) {
|
42 | for (var line = 1, cur = 0;;) {
|
43 | _whitespace.lineBreakG.lastIndex = cur;
|
44 | var match = _whitespace.lineBreakG.exec(input);
|
45 | if (match && match.index < offset) {
|
46 | ++line;
|
47 | cur = match.index + match[0].length;
|
48 | } else {
|
49 | return new Position(line, offset - cur);
|
50 | }
|
51 | }
|
52 | } |
\ | No newline at end of file |