source: trip-planner-front/node_modules/@babel/types/lib/validators/isNodesEquivalent.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = isNodesEquivalent;
7
8var _definitions = require("../definitions");
9
10function isNodesEquivalent(a, b) {
11 if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) {
12 return a === b;
13 }
14
15 if (a.type !== b.type) {
16 return false;
17 }
18
19 const fields = Object.keys(_definitions.NODE_FIELDS[a.type] || a.type);
20 const visitorKeys = _definitions.VISITOR_KEYS[a.type];
21
22 for (const field of fields) {
23 if (typeof a[field] !== typeof b[field]) {
24 return false;
25 }
26
27 if (a[field] == null && b[field] == null) {
28 continue;
29 } else if (a[field] == null || b[field] == null) {
30 return false;
31 }
32
33 if (Array.isArray(a[field])) {
34 if (!Array.isArray(b[field])) {
35 return false;
36 }
37
38 if (a[field].length !== b[field].length) {
39 return false;
40 }
41
42 for (let i = 0; i < a[field].length; i++) {
43 if (!isNodesEquivalent(a[field][i], b[field][i])) {
44 return false;
45 }
46 }
47
48 continue;
49 }
50
51 if (typeof a[field] === "object" && !(visitorKeys != null && visitorKeys.includes(field))) {
52 for (const key of Object.keys(a[field])) {
53 if (a[field][key] !== b[field][key]) {
54 return false;
55 }
56 }
57
58 continue;
59 }
60
61 if (!isNodesEquivalent(a[field], b[field])) {
62 return false;
63 }
64 }
65
66 return true;
67}
Note: See TracBrowser for help on using the repository browser.