@@ -224,6 +224,7 @@ const defaultMethods = {
224
224
// Why "executeInLoop"? Because if it needs to execute to get an array, I do not want to execute the arguments,
225
225
// Both for performance and safety reasons.
226
226
or : {
227
+ [ Sync ] : ( data , buildState ) => isSyncDeep ( data , buildState . engine , buildState ) ,
227
228
method : ( arr , _1 , _2 , engine ) => {
228
229
// See "executeInLoop" above
229
230
const executeInLoop = Array . isArray ( arr )
@@ -262,6 +263,7 @@ const defaultMethods = {
262
263
traverse : false
263
264
} ,
264
265
and : {
266
+ [ Sync ] : ( data , buildState ) => isSyncDeep ( data , buildState . engine , buildState ) ,
265
267
method : ( arr , _1 , _2 , engine ) => {
266
268
// See "executeInLoop" above
267
269
const executeInLoop = Array . isArray ( arr )
@@ -310,6 +312,7 @@ const defaultMethods = {
310
312
return 0
311
313
} ,
312
314
get : {
315
+ [ Sync ] : true ,
313
316
method : ( [ data , key , defaultValue ] , context , above , engine ) => {
314
317
const notFound = defaultValue === undefined ? null : defaultValue
315
318
@@ -391,6 +394,7 @@ const defaultMethods = {
391
394
some : createArrayIterativeMethod ( 'some' , true ) ,
392
395
all : createArrayIterativeMethod ( 'every' , true ) ,
393
396
none : {
397
+ [ Sync ] : ( data , buildState ) => isSyncDeep ( data , buildState . engine , buildState ) ,
394
398
traverse : false ,
395
399
// todo: add async build & build
396
400
method : ( val , context , above , engine ) => {
@@ -411,7 +415,7 @@ const defaultMethods = {
411
415
} ,
412
416
merge : ( arrays ) => ( Array . isArray ( arrays ) ? [ ] . concat ( ...arrays ) : [ arrays ] ) ,
413
417
every : createArrayIterativeMethod ( 'every' ) ,
414
- filter : createArrayIterativeMethod ( 'filter' ) ,
418
+ filter : createArrayIterativeMethod ( 'filter' , true ) ,
415
419
reduce : {
416
420
deterministic : ( data , buildState ) => {
417
421
return (
@@ -521,6 +525,7 @@ const defaultMethods = {
521
525
'!' : ( value , _1 , _2 , engine ) => Array . isArray ( value ) ? ! engine . truthy ( value [ 0 ] ) : ! engine . truthy ( value ) ,
522
526
'!!' : ( value , _1 , _2 , engine ) => Boolean ( Array . isArray ( value ) ? engine . truthy ( value [ 0 ] ) : engine . truthy ( value ) ) ,
523
527
cat : {
528
+ [ Sync ] : true ,
524
529
method : ( arr ) => {
525
530
if ( typeof arr === 'string' ) return arr
526
531
if ( ! Array . isArray ( arr ) ) return arr . toString ( )
@@ -659,8 +664,8 @@ function createArrayIterativeMethod (name, useTruthy = false) {
659
664
( await engine . run ( selector , context , {
660
665
above
661
666
} ) ) || [ ]
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 , {
664
669
above : [ { iterator : selector , index } , context , above ]
665
670
} )
666
671
return useTruthy ? engine . truthy ( result ) : result
@@ -680,15 +685,16 @@ function createArrayIterativeMethod (name, useTruthy = false) {
680
685
681
686
const method = build ( mapper , mapState )
682
687
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 ``
683
689
684
690
if ( async ) {
685
691
if ( ! isSyncDeep ( mapper , buildState . engine , buildState ) ) {
686
692
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 } ) ))`
688
694
}
689
695
}
690
696
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 } ) ))`
692
698
} ,
693
699
traverse : false
694
700
}
0 commit comments