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

1 line
8.5 KiB
Plaintext
Raw Normal View History

{"version":3,"file":"equality.js","sources":["equality.esm.js"],"sourcesContent":["var _a = Object.prototype, toString = _a.toString, hasOwnProperty = _a.hasOwnProperty;\r\nvar previousComparisons = new Map();\r\n/**\r\n * Performs a deep equality check on two JavaScript values, tolerating cycles.\r\n */\r\nfunction equal(a, b) {\r\n try {\r\n return check(a, b);\r\n }\r\n finally {\r\n previousComparisons.clear();\r\n }\r\n}\r\nfunction check(a, b) {\r\n // If the two values are strictly equal, our job is easy.\r\n if (a === b) {\r\n return true;\r\n }\r\n // Object.prototype.toString returns a representation of the runtime type of\r\n // the given value that is considerably more precise than typeof.\r\n var aTag = toString.call(a);\r\n var bTag = toString.call(b);\r\n // If the runtime types of a and b are different, they could maybe be equal\r\n // under some interpretation of equality, but for simplicity and performance\r\n // we just return false instead.\r\n if (aTag !== bTag) {\r\n return false;\r\n }\r\n switch (aTag) {\r\n case '[object Array]':\r\n // Arrays are a lot like other objects, but we can cheaply compare their\r\n // lengths as a short-cut before comparing their elements.\r\n if (a.length !== b.length)\r\n return false;\r\n // Fall through to object case...\r\n case '[object Object]': {\r\n if (previouslyCompared(a, b))\r\n return true;\r\n var aKeys = Object.keys(a);\r\n var bKeys = Object.keys(b);\r\n // If `a` and `b` have a different number of enumerable keys, they\r\n // must be different.\r\n var keyCount = aKeys.length;\r\n if (keyCount !== bKeys.length)\r\n return false;\r\n // Now make sure they have the same keys.\r\n for (var k = 0; k < keyCount; ++k) {\r\n if (!hasOwnProperty.call(b, aKeys[k])) {\r\n return false;\r\n }\r\n }\r\n // Finally, check deep equality of all child properties.\r\n for (var k = 0; k < keyCount; ++k) {\r\n var key = aKeys[k];\r\n if (!check(a[key], b[key])) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n case '[object Error]':\r\n return a.name === b.name && a.message === b.message;\r\n case '[object Number]':\r\n // Handle NaN, which is !== itself.\r\n if (a !== a)\r\n return b !== b;\r\n // Fall through to shared +a === +b case...\r\n case '[object Boolean]':\r\n case '[object Date]':\r\n return +a === +b;\r\n case '[object RegExp]':\r\n case '[object String]':\r\n return a == \"\" + b;\r\n case '[object Map]':\r\n case '[object Set]': {\r\n if (a.size !== b.size)\r\n return false;\r\n if (previouslyCompared(a, b))\r\n return true;\r\n var aIterator = a.entries();\r\n var isMap = aTag === '[object Map]';\r\n while (true) {\r\n var info = aIterator.next();\r\n if (info.done)\r\n break;\r\n // If a instanceof Set, aValue === aKey.\r\n var _a = info.value, aKey = _a[0], aValue = _a[1];\r\n // So this works the same way for both Set and Map.\r\n if (!b.has(aKey)) {\r\n return false;\r\n }\r\n // However, we care about deep equality of values only when dealing\r\n // with Map structures.\r\n if (isMap && !check(aValue, b.get(aKey))) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n }\r\n // Otherwise the values are not equal.\r\n return