1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.getLocation = getLocation;
|
7 |
|
8 | /**
|
9 | * Represents a location in a Source.
|
10 | */
|
11 |
|
12 | /**
|
13 | * Takes a Source and a UTF-8 character offset, and returns the corresponding
|
14 | * line and column as a SourceLocation.
|
15 | */
|
16 | function getLocation(source, position) {
|
17 | var lineRegexp = /\r\n|[\n\r]/g;
|
18 | var line = 1;
|
19 | var column = position + 1;
|
20 | var match;
|
21 |
|
22 | while ((match = lineRegexp.exec(source.body)) && match.index < position) {
|
23 | line += 1;
|
24 | column = position + 1 - (match.index + match[0].length);
|
25 | }
|
26 |
|
27 | return {
|
28 | line: line,
|
29 | column: column
|
30 | };
|
31 | }
|