@@ -224,6 +224,7 @@ const defaultMethods = {
224224 // Why "executeInLoop"? Because if it needs to execute to get an array, I do not want to execute the arguments,
225225 // Both for performance and safety reasons.
226226 or : {
227+ [ Sync ] : ( data , buildState ) => isSyncDeep ( data , buildState . engine , buildState ) ,
227228 method : ( arr , _1 , _2 , engine ) => {
228229 // See "executeInLoop" above
229230 const executeInLoop = Array . isArray ( arr )
@@ -262,6 +263,7 @@ const defaultMethods = {
262263 traverse : false
263264 } ,
264265 and : {
266+ [ Sync ] : ( data , buildState ) => isSyncDeep ( data , buildState . engine , buildState ) ,
265267 method : ( arr , _1 , _2 , engine ) => {
266268 // See "executeInLoop" above
267269 const executeInLoop = Array . isArray ( arr )
@@ -310,6 +312,7 @@ const defaultMethods = {
310312 return 0
311313 } ,
312314 get : {
315+ [ Sync ] : true ,
313316 method : ( [ data , key , defaultValue ] , context , above , engine ) => {
314317 const notFound = defaultValue === undefined ? null : defaultValue
315318
@@ -391,6 +394,7 @@ const defaultMethods = {
391394 some : createArrayIterativeMethod ( 'some' , true ) ,
392395 all : createArrayIterativeMethod ( 'every' , true ) ,
393396 none : {
397+ [ Sync ] : ( data , buildState ) => isSyncDeep ( data , buildState . engine , buildState ) ,
394398 traverse : false ,
395399 // todo: add async build & build
396400 method : ( val , context , above , engine ) => {
@@ -411,7 +415,7 @@ const defaultMethods = {
411415 } ,
412416 merge : ( arrays ) => ( Array . isArray ( arrays ) ? [ ] . concat ( ...arrays ) : [ arrays ] ) ,
413417 every : createArrayIterativeMethod ( 'every' ) ,
414- filter : createArrayIterativeMethod ( 'filter' ) ,
418+ filter : createArrayIterativeMethod ( 'filter' , true ) ,
415419 reduce : {
416420 deterministic : ( data , buildState ) => {
417421 return (
@@ -521,6 +525,7 @@ const defaultMethods = {
521525 '!' : ( value , _1 , _2 , engine ) => Array . isArray ( value ) ? ! engine . truthy ( value [ 0 ] ) : ! engine . truthy ( value ) ,
522526 '!!' : ( value , _1 , _2 , engine ) => Boolean ( Array . isArray ( value ) ? engine . truthy ( value [ 0 ] ) : engine . truthy ( value ) ) ,
523527 cat : {
528+ [ Sync ] : true ,
524529 method : ( arr ) => {
525530 if ( typeof arr === 'string' ) return arr
526531 if ( ! Array . isArray ( arr ) ) return arr . toString ( )
@@ -659,8 +664,8 @@ function createArrayIterativeMethod (name, useTruthy = false) {
659664 ( await engine . run ( selector , context , {
660665 above
661666 } ) ) || [ ]
662- return asyncIterators [ name ] ( selector , ( i , index ) => {
663- const result = engine . run ( mapper , i , {
667+ return asyncIterators [ name ] ( selector , async ( i , index ) => {
668+ const result = await engine . run ( mapper , i , {
664669 above : [ { iterator : selector , index } , context , above ]
665670 } )
666671 return useTruthy ? engine . truthy ( result ) : result
@@ -680,15 +685,16 @@ function createArrayIterativeMethod (name, useTruthy = false) {
680685
681686 const method = build ( mapper , mapState )
682687 const aboveArray = method . aboveDetected ? buildState . compile `[{ iterator: z, index: x }, context, above]` : buildState . compile `null`
688+ const useTruthyMethod = useTruthy ? buildState . compile `engine.truthy` : buildState . compile ``
683689
684690 if ( async ) {
685691 if ( ! isSyncDeep ( mapper , buildState . engine , buildState ) ) {
686692 buildState . detectAsync = true
687- return buildState . compile `await asyncIterators[${ name } ](${ selector } || [], async (i, x, z) => ${ method } (i, x, ${ aboveArray } ))`
693+ return buildState . compile `await asyncIterators[${ name } ](${ selector } || [], async (i, x, z) => ${ useTruthyMethod } ( ${ method } (i, x, ${ aboveArray } ) ))`
688694 }
689695 }
690696
691- return buildState . compile `(${ selector } || [])[${ name } ]((i, x, z) => ${ method } (i, x, ${ aboveArray } ))`
697+ return buildState . compile `(${ selector } || [])[${ name } ]((i, x, z) => ${ useTruthyMethod } ( ${ method } (i, x, ${ aboveArray } ) ))`
692698 } ,
693699 traverse : false
694700 }
0 commit comments