diff --git a/compare/deep/deep.test.tsx b/compare/deep/deep.test.tsx index a4b89bd1302..10c2555bf64 100644 --- a/compare/deep/deep.test.tsx +++ b/compare/deep/deep.test.tsx @@ -35,10 +35,16 @@ namespace $ { } , 'Array'() { + $mol_assert_ok( $mol_compare_deep( [] , [] ) ) $mol_assert_ok( $mol_compare_deep( [ 1 , [2] ] , [ 1 , [2] ] ) ) + $mol_assert_not( $mol_compare_deep( [ 1 , 2 ] , [ 1 , 3 ] ) ) $mol_assert_not( $mol_compare_deep( [ 1 , 2 , ] , [ 1 , 3 , undefined ] ) ) + + $mol_assert_not( $mol_compare_deep( $mol_range2().slice(0,0), new Array() ) ) + $mol_assert_not( $mol_compare_deep( $mol_range2(), $mol_range2() ) ) + } , 'Non POJO are different'() { diff --git a/compare/deep/deep.ts b/compare/deep/deep.ts index 91830cd72cd..86ced8bf81b 100644 --- a/compare/deep/deep.ts +++ b/compare/deep/deep.ts @@ -47,12 +47,12 @@ namespace $ { if( !left_proto ) result = compare_pojo( left, right as any ) else if( !Reflect.getPrototypeOf( left_proto ) ) result = compare_pojo( left, right as any ) + else if( Symbol.toPrimitive in left ) result = compare_primitive( left, right ) else if( Array.isArray( left ) ) result = compare_array( left, right as any ) else if( left instanceof Set ) result = compare_set( left, right as any ) else if( left instanceof Map ) result = compare_map( left, right as any ) else if( ArrayBuffer.isView( left ) ) result = compare_buffer( left, right as any ) else if( Symbol.iterator in left ) result = compare_iterator( ( left as any )[ Symbol.iterator ](), ( right as any )[ Symbol.iterator ]() ) - else if( Symbol.toPrimitive in left ) result = compare_primitive( left, right ) else result = false } finally { diff --git a/range2/range2.ts b/range2/range2.ts index a5ee5cfbf1b..9688436b605 100644 --- a/range2/range2.ts +++ b/range2/range2.ts @@ -166,6 +166,10 @@ namespace $ { sort() { return $mol_fail( new TypeError( `Mutable sort is forbidden. Use toSorted instead.` ) ) } + + [Symbol.toPrimitive]() { + return $mol_guid() + } }