d52b8a14f46c7e3ac5ccf9c6eab87e6f330bee9484fd8323fd7072b940838eef8d858c75e1cb9c1445e8c58fa1e64f553b7bc180dd8f667b25fff7bc7b1a83 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isNodesEquivalent;
  6. var _index = require("../definitions/index.js");
  7. function isNodesEquivalent(a, b) {
  8. if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) {
  9. return a === b;
  10. }
  11. if (a.type !== b.type) {
  12. return false;
  13. }
  14. const fields = Object.keys(_index.NODE_FIELDS[a.type] || a.type);
  15. const visitorKeys = _index.VISITOR_KEYS[a.type];
  16. for (const field of fields) {
  17. const val_a = a[field];
  18. const val_b = b[field];
  19. if (typeof val_a !== typeof val_b) {
  20. return false;
  21. }
  22. if (val_a == null && val_b == null) {
  23. continue;
  24. } else if (val_a == null || val_b == null) {
  25. return false;
  26. }
  27. if (Array.isArray(val_a)) {
  28. if (!Array.isArray(val_b)) {
  29. return false;
  30. }
  31. if (val_a.length !== val_b.length) {
  32. return false;
  33. }
  34. for (let i = 0; i < val_a.length; i++) {
  35. if (!isNodesEquivalent(val_a[i], val_b[i])) {
  36. return false;
  37. }
  38. }
  39. continue;
  40. }
  41. if (typeof val_a === "object" && !(visitorKeys != null && visitorKeys.includes(field))) {
  42. for (const key of Object.keys(val_a)) {
  43. if (val_a[key] !== val_b[key]) {
  44. return false;
  45. }
  46. }
  47. continue;
  48. }
  49. if (!isNodesEquivalent(val_a, val_b)) {
  50. return false;
  51. }
  52. }
  53. return true;
  54. }
  55. //# sourceMappingURL=isNodesEquivalent.js.map