2
2
'use strict'
3
3
4
4
import asyncIterators from './async_iterators.js'
5
- import { Sync , isSync , Unfound , OriginalImpl } from './constants.js'
5
+ import { Sync , isSync , Unfound , OriginalImpl , Compiled } from './constants.js'
6
6
import declareSync from './utilities/declareSync.js'
7
7
import { build , buildString } from './compiler.js'
8
8
import chainingSupported from './utilities/chainingSupported.js'
@@ -844,22 +844,6 @@ Object.keys(defaultMethods).forEach((item) => {
844
844
: defaultMethods [ item ] . deterministic
845
845
} )
846
846
847
- // @ts -ignore Allow custom attribute
848
- defaultMethods [ '<' ] . compile = function ( data , buildState ) {
849
- if ( ! Array . isArray ( data ) ) return false
850
- if ( data . length < 2 ) return false
851
- let res = buildState . compile `(${ data [ 0 ] } < (prev = ${ data [ 1 ] } ))`
852
- for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev < ${ data [ i ] } )`
853
- return res
854
- }
855
- // @ts -ignore Allow custom attribute
856
- defaultMethods [ '<=' ] . compile = function ( data , buildState ) {
857
- if ( ! Array . isArray ( data ) ) return false
858
- if ( data . length < 2 ) return false
859
- let res = buildState . compile `(${ data [ 0 ] } <= (prev = ${ data [ 1 ] } ))`
860
- for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev <= ${ data [ i ] } )`
861
- return res
862
- }
863
847
// @ts -ignore Allow custom attribute
864
848
defaultMethods . min . compile = function ( data , buildState ) {
865
849
if ( ! Array . isArray ( data ) ) return false
@@ -874,38 +858,19 @@ defaultMethods.max.compile = function (data, buildState) {
874
858
. map ( ( i ) => buildString ( i , buildState ) )
875
859
. join ( ', ' ) } )`
876
860
}
877
- // @ts -ignore Allow custom attribute
878
- defaultMethods [ '>' ] . compile = function ( data , buildState ) {
879
- if ( ! Array . isArray ( data ) ) return false
880
- if ( data . length < 2 ) return false
881
- let res = buildState . compile `(${ data [ 0 ] } > (prev = ${ data [ 1 ] } ))`
882
- for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev > ${ data [ i ] } )`
883
- return res
884
- }
885
- // @ts -ignore Allow custom attribute
886
- defaultMethods [ '>=' ] . compile = function ( data , buildState ) {
887
- if ( ! Array . isArray ( data ) ) return false
888
- if ( data . length < 2 ) return false
889
- let res = buildState . compile `(${ data [ 0 ] } >= (prev = ${ data [ 1 ] } ))`
890
- for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev >= ${ data [ i ] } )`
891
- return res
892
- }
893
- // @ts -ignore Allow custom attribute
894
- defaultMethods [ '==' ] . compile = function ( data , buildState ) {
895
- if ( ! Array . isArray ( data ) ) return false
896
- if ( data . length < 2 ) return false
897
- let res = buildState . compile `(${ data [ 0 ] } == (prev = ${ data [ 1 ] } ))`
898
- for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev == ${ data [ i ] } )`
899
- return res
900
- }
901
- // @ts -ignore Allow custom attribute
902
- defaultMethods [ '!=' ] . compile = function ( data , buildState ) {
903
- if ( ! Array . isArray ( data ) ) return false
904
- if ( data . length < 2 ) return false
905
- let res = buildState . compile `(${ data [ 0 ] } != (prev = ${ data [ 1 ] } ))`
906
- for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev != ${ data [ i ] } )`
907
- return res
861
+
862
+ for ( const op of [ '>' , '<' , '>=' , '<=' , '==' , '!=' , '!==' , '===' ] ) {
863
+ const opStr = { [ Compiled ] : op }
864
+ // @ts -ignore Allow custom attribute
865
+ defaultMethods [ op ] . compile = function ( data , buildState ) {
866
+ if ( ! Array . isArray ( data ) ) return false
867
+ if ( data . length < 2 ) return false
868
+ let res = buildState . compile `(${ data [ 0 ] } ${ opStr } (prev = ${ data [ 1 ] } ))`
869
+ for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev ${ opStr } ${ data [ i ] } )`
870
+ return res
871
+ }
908
872
}
873
+
909
874
// @ts -ignore Allow custom attribute
910
875
defaultMethods . if . compile = function ( data , buildState ) {
911
876
if ( ! Array . isArray ( data ) ) return false
@@ -924,14 +889,6 @@ defaultMethods.if.compile = function (data, buildState) {
924
889
925
890
return buildState . compile `(${ res } ${ onFalse } )`
926
891
}
927
- // @ts -ignore Allow custom attribute
928
- defaultMethods [ '===' ] . compile = function ( data , buildState ) {
929
- if ( ! Array . isArray ( data ) ) return false
930
- if ( data . length < 2 ) return false
931
- let res = buildState . compile `(${ data [ 0 ] } === ${ data [ 1 ] } )`
932
- for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && ${ data [ i - 1 ] } === ${ data [ i ] } )`
933
- return res
934
- }
935
892
936
893
/**
937
894
* Transforms the operands of the arithmetic operation to numbers.
0 commit comments