1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | function correctSourceRange(sourceRange, locationOffset) {
|
17 | if (!locationOffset || !sourceRange) {
|
18 | return sourceRange;
|
19 | }
|
20 | return {
|
21 | file: locationOffset.filename || sourceRange.file,
|
22 | start: correctPosition(sourceRange.start, locationOffset),
|
23 | end: correctPosition(sourceRange.end, locationOffset)
|
24 | };
|
25 | }
|
26 | exports.correctSourceRange = correctSourceRange;
|
27 | function correctPosition(position, locationOffset) {
|
28 | return {
|
29 | line: position.line + locationOffset.line,
|
30 | column: position.column + (position.line === 0 ? locationOffset.col : 0)
|
31 | };
|
32 | }
|
33 | exports.correctPosition = correctPosition;
|
34 | function uncorrectSourceRange(sourceRange, locationOffset) {
|
35 | if (locationOffset == null || sourceRange == null) {
|
36 | return sourceRange;
|
37 | }
|
38 | return {
|
39 | file: locationOffset.filename || sourceRange.file,
|
40 | start: uncorrectPosition(sourceRange.start, locationOffset),
|
41 | end: uncorrectPosition(sourceRange.end, locationOffset),
|
42 | };
|
43 | }
|
44 | exports.uncorrectSourceRange = uncorrectSourceRange;
|
45 | function uncorrectPosition(position, locationOffset) {
|
46 | const line = position.line - locationOffset.line;
|
47 | return {
|
48 | line: line,
|
49 | column: position.column - (line === 0 ? locationOffset.col : 0)
|
50 | };
|
51 | }
|
52 | exports.uncorrectPosition = uncorrectPosition;
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | function comparePosition(a, b) {
|
58 | if (a.line !== b.line) {
|
59 | return a.line < b.line ? -1 : 1;
|
60 | }
|
61 | if (a.column !== b.column) {
|
62 | return a.column < b.column ? -1 : 1;
|
63 | }
|
64 | return 0;
|
65 | }
|
66 | exports.comparePosition = comparePosition;
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | function comparePositionAndRange(position, range, includeEdges) {
|
75 |
|
76 |
|
77 |
|
78 | if (includeEdges == null) {
|
79 | includeEdges = true;
|
80 | }
|
81 | if (includeEdges == null) {
|
82 | includeEdges = true;
|
83 | }
|
84 | if (position.line < range.start.line) {
|
85 | return -1;
|
86 | }
|
87 | if (position.line > range.end.line) {
|
88 | return 1;
|
89 | }
|
90 | if (position.line === range.start.line) {
|
91 | if (includeEdges) {
|
92 | if (position.column < range.start.column) {
|
93 | return -1;
|
94 | }
|
95 | }
|
96 | else {
|
97 | if (position.column <= range.start.column) {
|
98 | return -1;
|
99 | }
|
100 | }
|
101 | }
|
102 | if (position.line === range.end.line) {
|
103 | if (includeEdges) {
|
104 | if (position.column > range.end.column) {
|
105 | return 1;
|
106 | }
|
107 | }
|
108 | else {
|
109 | if (position.column >= range.end.column) {
|
110 | return 1;
|
111 | }
|
112 | }
|
113 | }
|
114 | return 0;
|
115 | }
|
116 | exports.comparePositionAndRange = comparePositionAndRange;
|
117 | function isPositionInsideRange(position, range, includeEdges) {
|
118 | if (!range) {
|
119 | return false;
|
120 | }
|
121 | return comparePositionAndRange(position, range, includeEdges) === 0;
|
122 | }
|
123 | exports.isPositionInsideRange = isPositionInsideRange;
|
124 |
|
\ | No newline at end of file |