Helper to run comparison with proper visited tracking
( self: object, that: object, fn: () => boolean )
| 203 | |
| 204 | /** Helper to run comparison with proper visited tracking */ |
| 205 | function withVisitedTracking( |
| 206 | self: object, |
| 207 | that: object, |
| 208 | fn: () => boolean |
| 209 | ): boolean { |
| 210 | const hasLeft = visitedLeft.has(self) |
| 211 | const hasRight = visitedRight.has(that) |
| 212 | // Check for circular references before adding |
| 213 | if (hasLeft && hasRight) { |
| 214 | return true // Both are circular at the same level |
| 215 | } |
| 216 | if (hasLeft || hasRight) { |
| 217 | return false // Only one is circular |
| 218 | } |
| 219 | visitedLeft.add(self) |
| 220 | visitedRight.add(that) |
| 221 | const result = fn() |
| 222 | visitedLeft.delete(self) |
| 223 | visitedRight.delete(that) |
| 224 | return result |
| 225 | } |
| 226 | |
| 227 | const visitedLeft = new WeakSet<object>() |
| 228 | const visitedRight = new WeakSet<object>() |
no test coverage detected