(seenReferences: WeakMap<object, boolean> = new WeakMap())
| 617 | // there are circular references in the subset passed to it. |
| 618 | const subsetEqualityWithContext |
| 619 | = (seenReferences: WeakMap<object, boolean> = new WeakMap()) => |
| 620 | (object: any, subset: any): boolean | undefined => { |
| 621 | if (!isObjectWithKeys(subset)) { |
| 622 | return undefined |
| 623 | } |
| 624 | |
| 625 | return Object.keys(subset).every((key) => { |
| 626 | if (subset[key] != null && typeof subset[key] === 'object') { |
| 627 | if (seenReferences.has(subset[key])) { |
| 628 | return equals(object[key], subset[key], filteredCustomTesters) |
| 629 | } |
| 630 | |
| 631 | seenReferences.set(subset[key], true) |
| 632 | } |
| 633 | const result |
| 634 | = object != null |
| 635 | && hasPropertyInObject(object, key) |
| 636 | && equals(object[key], subset[key], [ |
| 637 | ...filteredCustomTesters, |
| 638 | subsetEqualityWithContext(seenReferences), |
| 639 | ]) |
| 640 | // The main goal of using seenReference is to avoid circular node on tree. |
| 641 | // It will only happen within a parent and its child, not a node and nodes next to it (same level) |
| 642 | // We should keep the reference for a parent and its child only |
| 643 | // Thus we should delete the reference immediately so that it doesn't interfere |
| 644 | // other nodes within the same level on tree. |
| 645 | seenReferences.delete(subset[key]) |
| 646 | return result |
| 647 | }) |
| 648 | } |
| 649 | |
| 650 | return subsetEqualityWithContext()(object, subset) |
| 651 | } |
no test coverage detected