1 |
|
2 |
|
3 |
|
4 |
|
5 | 'use strict';
|
6 | module.exports = function compareLocations(a, b) {
|
7 | if (typeof a === 'string') {
|
8 | if (typeof b === 'string') {
|
9 | if (a < b) return -1;
|
10 | if (a > b) return 1;
|
11 | return 0;
|
12 | } else if (typeof b === 'object') {
|
13 | return 1;
|
14 | } else {
|
15 | return 0;
|
16 | }
|
17 | } else if (typeof a === 'object') {
|
18 | if (typeof b === 'string') {
|
19 | return -1;
|
20 | } else if (typeof b === 'object') {
|
21 | if (a.start && b.start) {
|
22 | const ap = a.start;
|
23 | const bp = b.start;
|
24 | if (ap.line < bp.line) return -1;
|
25 | if (ap.line > bp.line) return 1;
|
26 | if (ap.column < bp.column) return -1;
|
27 | if (ap.column > bp.column) return 1;
|
28 | }
|
29 | if (a.index < b.index) return -1;
|
30 | if (a.index > b.index) return 1;
|
31 | return 0;
|
32 | } else {
|
33 | return 0;
|
34 | }
|
35 | }
|
36 | };
|