mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
refactor(assert): remove unnecessary getValFromKeyedCollection()
(#5921)
* refactor(assert): remove unnecessary getValFromKeyedCollection function * Use type assertion instead of narrowing w unreachable path
This commit is contained in:
parent
2fe19de48f
commit
23b4d2a034
@ -2,15 +2,10 @@
|
||||
// This module is browser compatible.
|
||||
|
||||
type KeyedCollection = Set<unknown> | Map<unknown, unknown>;
|
||||
|
||||
function isKeyedCollection(x: unknown): x is KeyedCollection {
|
||||
return x instanceof Set || x instanceof Map;
|
||||
}
|
||||
|
||||
function getValFromKeyedCollection(kc: KeyedCollection, key: unknown) {
|
||||
return kc instanceof Map ? kc.get(key) : key;
|
||||
}
|
||||
|
||||
function constructorsEqual(a: object, b: object) {
|
||||
return a.constructor === b.constructor ||
|
||||
a.constructor === Object && !b.constructor ||
|
||||
@ -106,10 +101,7 @@ export function equal(c: unknown, d: unknown): boolean {
|
||||
for (const key of aKeys) {
|
||||
if (
|
||||
!b.has(key) ||
|
||||
!compare(
|
||||
getValFromKeyedCollection(a, key),
|
||||
getValFromKeyedCollection(b, key),
|
||||
)
|
||||
!compare(a.get(key), (b as Map<unknown, unknown>).get(key))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user