MessagesForMacintosh/JS/node_modules/@wry/equality/lib/equality.esm.js.map

1 line
7.0 KiB
Plaintext

{"version":3,"file":"equality.esm.js","sources":["../src/equality.ts"],"sourcesContent":["const { toString, hasOwnProperty } = Object.prototype;\nconst previousComparisons = new Map<object, Set<object>>();\n\n/**\n * Performs a deep equality check on two JavaScript values, tolerating cycles.\n */\nexport function equal(a: any, b: any): boolean {\n try {\n return check(a, b);\n } finally {\n previousComparisons.clear();\n }\n}\n\n// Allow default imports as well.\nexport default equal;\n\nfunction check(a: any, b: any): boolean {\n // If the two values are strictly equal, our job is easy.\n if (a === b) {\n return true;\n }\n\n // Object.prototype.toString returns a representation of the runtime type of\n // the given value that is considerably more precise than typeof.\n const aTag = toString.call(a);\n const bTag = toString.call(b);\n\n // If the runtime types of a and b are different, they could maybe be equal\n // under some interpretation of equality, but for simplicity and performance\n // we just return false instead.\n if (aTag !== bTag) {\n return false;\n }\n\n switch (aTag) {\n case '[object Array]':\n // Arrays are a lot like other objects, but we can cheaply compare their\n // lengths as a short-cut before comparing their elements.\n if (a.length !== b.length) return false;\n // Fall through to object case...\n case '[object Object]': {\n if (previouslyCompared(a, b)) return true;\n\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n\n // If `a` and `b` have a different number of enumerable keys, they\n // must be different.\n const keyCount = aKeys.length;\n if (keyCount !== bKeys.length) return false;\n\n // Now make sure they have the same keys.\n for (let k = 0; k < keyCount; ++k) {\n if (!hasOwnProperty.call(b, aKeys[k])) {\n return false;\n }\n }\n\n // Finally, check deep equality of all child properties.\n for (let k = 0; k < keyCount; ++k) {\n const key = aKeys[k];\n if (!check(a[key], b[key])) {\n return false;\n }\n }\n\n return true;\n }\n\n case '[object Error]':\n return a.name === b.name && a.message === b.message;\n\n case '[object Number]':\n // Handle NaN, which is !== itself.\n if (a !== a) return b !== b;\n // Fall through to shared +a === +b case...\n case '[object Boolean]':\n case '[object Date]':\n return +a === +b;\n\n case '[object RegExp]':\n case '[object String]':\n return a == `${b}`;\n\n case '[object Map]':\n case '[object Set]': {\n if (a.size !== b.size) return false;\n if (previouslyCompared(a, b)) return true;\n\n const aIterator = a.entries();\n const isMap = aTag === '[object Map]';\n\n while (true) {\n const info = aIterator.next();\n if (info.done) break;\n\n // If a instanceof Set, aValue === aKey.\n const [aKey, aValue] = info.value;\n\n // So this works the same way for both Set and Map.\n if (!b.has(aKey)) {\n return false;\n }\n\n // However, we care about deep equality of values only when dealing\n // with Map structures.\n if (isMap && !check(aValue, b.get(aKey))) {\n return false;\n }\n }\n\n return true;\n }\n }\n\n // Otherwise the values are not equal.\n return false;\n}\n\nfunction previouslyCompared(a: object, b: object): boolean {\n // Though cyclic references can make an object graph appear infinite from the\n // perspective of a depth-first traversal, the graph still contains a finite\n // number of distinct object references. We use the previousComparisons cache\n // to avoid comparing the same pair of object references more than once, which\n // guarantees termination (even if we end up comparing every object in one\n // graph to every object in the other graph, which is extremely unlikely),\n // while still allowing weird isomorphic structures (like rings with different\n // lengths) a chance to pass the equality test.\n let bSet = previousComparisons.get(a);\n if (bSet) {\n // Return true here because we can be sure false will be returned somewhere\n // else if the objects are not equivalent.\n if (bSet.has(b)) return true;\n } else {\n previousComparisons.set(a, bSet = new Set);\n }\n bSet.add(b);\n return false;\n}\n"],"names":[],"mappings":"AAAM,IAAA,qBAA+C,EAA7C,sBAAQ,EAAE,kCAAmC,CAAC;AACtD,IAAM,mBAAmB,GAAG,IAAI,GAAG,EAAuB,CAAC;AAE3D;;;SAGgB,KAAK,CAAC,CAAM,EAAE,CAAM;IAClC,IAAI;QACF,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KACpB;YAAS;QACR,mBAAmB,CAAC,KAAK,EAAE,CAAC;KAC7B;AACH,CAAC;AAKD,SAAS,KAAK,CAAC,CAAM,EAAE,CAAM;;IAE3B,IAAI,CAAC,KAAK,CAAC,EAAE;QACX,OAAO,IAAI,CAAC;KACb;;;IAID,IAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,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