@@ -790,13 +790,14 @@ const defaultMethods = {
790
790
791
791
function createComparator ( name , func ) {
792
792
const opStr = { [ Compiled ] : name }
793
+ const strict = name . length === 3
793
794
return {
794
795
method : ( args , context , above , engine ) => {
795
796
if ( ! Array . isArray ( args ) || args . length <= 1 ) throw INVALID_ARGUMENTS
796
797
if ( args . length === 2 ) {
797
798
const a = runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
798
799
const b = runOptimizedOrFallback ( args [ 1 ] , engine , context , above )
799
- if ( typeof a !== typeof b ) {
800
+ if ( ! strict && typeof a !== typeof b ) {
800
801
if ( typeof a === 'string' && Number . isNaN ( + a ) ) throw NaN
801
802
if ( typeof b === 'string' && Number . isNaN ( + b ) ) throw NaN
802
803
}
@@ -805,7 +806,7 @@ function createComparator (name, func) {
805
806
let prev = runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
806
807
for ( let i = 1 ; i < args . length ; i ++ ) {
807
808
const current = runOptimizedOrFallback ( args [ i ] , engine , context , above )
808
- if ( typeof current !== typeof prev ) {
809
+ if ( ! strict && typeof current !== typeof prev ) {
809
810
if ( typeof current === 'string' && Number . isNaN ( + current ) ) throw NaN
810
811
if ( i === 1 && typeof prev === 'string' && Number . isNaN ( + prev ) ) throw NaN
811
812
}
@@ -819,7 +820,7 @@ function createComparator (name, func) {
819
820
if ( args . length === 2 ) {
820
821
const a = await runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
821
822
const b = await runOptimizedOrFallback ( args [ 1 ] , engine , context , above )
822
- if ( typeof a !== typeof b ) {
823
+ if ( ! strict && typeof a !== typeof b ) {
823
824
if ( typeof a === 'string' && Number . isNaN ( + a ) ) throw NaN
824
825
if ( typeof b === 'string' && Number . isNaN ( + b ) ) throw NaN
825
826
}
@@ -828,7 +829,7 @@ function createComparator (name, func) {
828
829
let prev = await runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
829
830
for ( let i = 1 ; i < args . length ; i ++ ) {
830
831
const current = await runOptimizedOrFallback ( args [ i ] , engine , context , above )
831
- if ( typeof current !== typeof prev ) {
832
+ if ( ! strict && typeof current !== typeof prev ) {
832
833
if ( typeof current === 'string' && Number . isNaN ( + current ) ) throw NaN
833
834
if ( i === 1 && typeof prev === 'string' && Number . isNaN ( + prev ) ) throw NaN
834
835
}
@@ -840,9 +841,9 @@ function createComparator (name, func) {
840
841
compile : ( data , buildState ) => {
841
842
if ( ! Array . isArray ( data ) ) return false
842
843
if ( data . length < 2 ) return false
843
- if ( data . length === 2 ) return buildState . compile `((prev = ${ data [ 0 ] } ) ${ opStr } compareCheck(${ data [ 1 ] } , prev))`
844
- let res = buildState . compile `((prev = ${ data [ 0 ] } ) ${ opStr } (prev = compareCheck(${ data [ 1 ] } , prev)))`
845
- for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev ${ opStr } (prev = compareCheck(${ data [ i ] } , prev)))`
844
+ if ( data . length === 2 ) return buildState . compile `((prev = ${ data [ 0 ] } ) ${ opStr } compareCheck(${ data [ 1 ] } , prev, ${ strict } ))`
845
+ let res = buildState . compile `((prev = ${ data [ 0 ] } ) ${ opStr } (prev = compareCheck(${ data [ 1 ] } , prev, ${ strict } )))`
846
+ for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev ${ opStr } (prev = compareCheck(${ data [ i ] } , prev, ${ strict } )))`
846
847
return res
847
848
} ,
848
849
[ OriginalImpl ] : true ,
0 commit comments