1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | module.exports = (a, b) => {
|
17 | if (typeof a === "string") {
|
18 | if (typeof b === "string") {
|
19 | if (a < b) return -1;
|
20 | if (a > b) return 1;
|
21 | return 0;
|
22 | } else if (typeof b === "object") {
|
23 | return 1;
|
24 | } else {
|
25 | return 0;
|
26 | }
|
27 | } else if (typeof a === "object") {
|
28 | if (typeof b === "string") {
|
29 | return -1;
|
30 | } else if (typeof b === "object") {
|
31 | if ("start" in a && "start" in b) {
|
32 | const ap = a.start;
|
33 | const bp = b.start;
|
34 | if (ap.line < bp.line) return -1;
|
35 | if (ap.line > bp.line) return 1;
|
36 | if (ap.column < bp.column) return -1;
|
37 | if (ap.column > bp.column) return 1;
|
38 | }
|
39 | if ("name" in a && "name" in b) {
|
40 | if (a.name < b.name) return -1;
|
41 | if (a.name > b.name) return 1;
|
42 | }
|
43 | if ("index" in a && "index" in b) {
|
44 | if (a.index < b.index) return -1;
|
45 | if (a.index > b.index) return 1;
|
46 | }
|
47 | return 0;
|
48 | } else {
|
49 | return 0;
|
50 | }
|
51 | }
|
52 | };
|