@@ -310,28 +310,30 @@ const defaultMethods = {
310310 avoidInlineAsync : true
311311 }
312312 mapper = build ( mapper , mapState )
313+ const aboveArray = mapper . aboveDetected ? '[null, context, above]' : 'null'
314+
313315 buildState . methods . push ( mapper )
314316 if ( async ) {
315317 if ( ! isSync ( mapper ) || selector . includes ( 'await' ) ) {
316318 buildState . detectAsync = true
317319 if ( typeof defaultValue !== 'undefined' ) {
318320 return `await asyncIterators.reduce(${ selector } || [], (a,b) => methods[${
319321 buildState . methods . length - 1
320- } ]({ accumulator: a, current: b }, [null, context, above] ), ${ defaultValue } )`
322+ } ]({ accumulator: a, current: b }, ${ aboveArray } ), ${ defaultValue } )`
321323 }
322324 return `await asyncIterators.reduce(${ selector } || [], (a,b) => methods[${
323325 buildState . methods . length - 1
324- } ]({ accumulator: a, current: b }, [null, context, above] ))`
326+ } ]({ accumulator: a, current: b }, ${ aboveArray } ))`
325327 }
326328 }
327329 if ( typeof defaultValue !== 'undefined' ) {
328330 return `(${ selector } || []).reduce((a,b) => methods[${
329331 buildState . methods . length - 1
330- } ]({ accumulator: a, current: b }, [null, context, above] ), ${ defaultValue } )`
332+ } ]({ accumulator: a, current: b }, ${ aboveArray } ), ${ defaultValue } )`
331333 }
332334 return `(${ selector } || []).reduce((a,b) => methods[${
333335 buildState . methods . length - 1
334- } ]({ accumulator: a, current: b }, [null, context, above] ))`
336+ } ]({ accumulator: a, current: b }, ${ aboveArray } ))`
335337 } ,
336338 method : ( input , context , above , engine ) => {
337339 if ( ! Array . isArray ( input ) ) throw new InvalidControlInput ( input )
@@ -536,14 +538,17 @@ function createArrayIterativeMethod (name, useTruthy = false) {
536538 extraArguments : 'index, above'
537539 }
538540
541+ const method = build ( mapper , mapState )
542+ const aboveArray = method . aboveDetected ? buildState . compile `[{ item: null }, context, above]` : buildState . compile `null`
543+
539544 if ( async ) {
540545 if ( ! isSyncDeep ( mapper , buildState . engine , buildState ) ) {
541546 buildState . detectAsync = true
542- return buildState . compile `await asyncIterators[${ name } ](${ selector } || [], async (i, x) => ${ build ( mapper , mapState ) } (i, x, [{ item: null }, context, above] ))`
547+ return buildState . compile `await asyncIterators[${ name } ](${ selector } || [], async (i, x) => ${ method } (i, x, ${ aboveArray } ))`
543548 }
544549 }
545550
546- return buildState . compile `(${ selector } || [])[${ name } ]((i, x) => ${ build ( mapper , mapState ) } (i, x, [{ item: null }, context, above] ))`
551+ return buildState . compile `(${ selector } || [])[${ name } ]((i, x) => ${ method } (i, x, ${ aboveArray } ))`
547552 } ,
548553 traverse : false
549554 }
0 commit comments