@@ -790,13 +790,14 @@ const defaultMethods = {
790790
791791function createComparator ( name , func ) {
792792 const opStr = { [ Compiled ] : name }
793+ const strict = name . length === 3
793794 return {
794795 method : ( args , context , above , engine ) => {
795796 if ( ! Array . isArray ( args ) || args . length <= 1 ) throw INVALID_ARGUMENTS
796797 if ( args . length === 2 ) {
797798 const a = runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
798799 const b = runOptimizedOrFallback ( args [ 1 ] , engine , context , above )
799- if ( typeof a !== typeof b ) {
800+ if ( ! strict && typeof a !== typeof b ) {
800801 if ( typeof a === 'string' && Number . isNaN ( + a ) ) throw NaN
801802 if ( typeof b === 'string' && Number . isNaN ( + b ) ) throw NaN
802803 }
@@ -805,7 +806,7 @@ function createComparator (name, func) {
805806 let prev = runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
806807 for ( let i = 1 ; i < args . length ; i ++ ) {
807808 const current = runOptimizedOrFallback ( args [ i ] , engine , context , above )
808- if ( typeof current !== typeof prev ) {
809+ if ( ! strict && typeof current !== typeof prev ) {
809810 if ( typeof current === 'string' && Number . isNaN ( + current ) ) throw NaN
810811 if ( i === 1 && typeof prev === 'string' && Number . isNaN ( + prev ) ) throw NaN
811812 }
@@ -819,7 +820,7 @@ function createComparator (name, func) {
819820 if ( args . length === 2 ) {
820821 const a = await runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
821822 const b = await runOptimizedOrFallback ( args [ 1 ] , engine , context , above )
822- if ( typeof a !== typeof b ) {
823+ if ( ! strict && typeof a !== typeof b ) {
823824 if ( typeof a === 'string' && Number . isNaN ( + a ) ) throw NaN
824825 if ( typeof b === 'string' && Number . isNaN ( + b ) ) throw NaN
825826 }
@@ -828,7 +829,7 @@ function createComparator (name, func) {
828829 let prev = await runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
829830 for ( let i = 1 ; i < args . length ; i ++ ) {
830831 const current = await runOptimizedOrFallback ( args [ i ] , engine , context , above )
831- if ( typeof current !== typeof prev ) {
832+ if ( ! strict && typeof current !== typeof prev ) {
832833 if ( typeof current === 'string' && Number . isNaN ( + current ) ) throw NaN
833834 if ( i === 1 && typeof prev === 'string' && Number . isNaN ( + prev ) ) throw NaN
834835 }
@@ -840,9 +841,9 @@ function createComparator (name, func) {
840841 compile : ( data , buildState ) => {
841842 if ( ! Array . isArray ( data ) ) return false
842843 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 } )))`
846847 return res
847848 } ,
848849 [ OriginalImpl ] : true ,
0 commit comments