22'use strict'
33
44import asyncIterators from './async_iterators.js'
5- import { Sync , isSync , Unfound , OriginalImpl } from './constants.js'
5+ import { Sync , isSync , Unfound , OriginalImpl , Compiled } from './constants.js'
66import declareSync from './utilities/declareSync.js'
77import { build , buildString } from './compiler.js'
88import chainingSupported from './utilities/chainingSupported.js'
@@ -844,22 +844,6 @@ Object.keys(defaultMethods).forEach((item) => {
844844 : defaultMethods [ item ] . deterministic
845845} )
846846
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- }
863847// @ts -ignore Allow custom attribute
864848defaultMethods . min . compile = function ( data , buildState ) {
865849 if ( ! Array . isArray ( data ) ) return false
@@ -874,38 +858,19 @@ defaultMethods.max.compile = function (data, buildState) {
874858 . map ( ( i ) => buildString ( i , buildState ) )
875859 . join ( ', ' ) } )`
876860}
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+ }
908872}
873+
909874// @ts -ignore Allow custom attribute
910875defaultMethods . if . compile = function ( data , buildState ) {
911876 if ( ! Array . isArray ( data ) ) return false
@@ -924,14 +889,6 @@ defaultMethods.if.compile = function (data, buildState) {
924889
925890 return buildState . compile `(${ res } ${ onFalse } )`
926891}
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- }
935892
936893/**
937894 * Transforms the operands of the arithmetic operation to numbers.
0 commit comments