@@ -310,28 +310,30 @@ const defaultMethods = {
310
310
avoidInlineAsync : true
311
311
}
312
312
mapper = build ( mapper , mapState )
313
+ const aboveArray = mapper . aboveDetected ? '[null, context, above]' : 'null'
314
+
313
315
buildState . methods . push ( mapper )
314
316
if ( async ) {
315
317
if ( ! isSync ( mapper ) || selector . includes ( 'await' ) ) {
316
318
buildState . detectAsync = true
317
319
if ( typeof defaultValue !== 'undefined' ) {
318
320
return `await asyncIterators.reduce(${ selector } || [], (a,b) => methods[${
319
321
buildState . methods . length - 1
320
- } ]({ accumulator: a, current: b }, [null, context, above] ), ${ defaultValue } )`
322
+ } ]({ accumulator: a, current: b }, ${ aboveArray } ), ${ defaultValue } )`
321
323
}
322
324
return `await asyncIterators.reduce(${ selector } || [], (a,b) => methods[${
323
325
buildState . methods . length - 1
324
- } ]({ accumulator: a, current: b }, [null, context, above] ))`
326
+ } ]({ accumulator: a, current: b }, ${ aboveArray } ))`
325
327
}
326
328
}
327
329
if ( typeof defaultValue !== 'undefined' ) {
328
330
return `(${ selector } || []).reduce((a,b) => methods[${
329
331
buildState . methods . length - 1
330
- } ]({ accumulator: a, current: b }, [null, context, above] ), ${ defaultValue } )`
332
+ } ]({ accumulator: a, current: b }, ${ aboveArray } ), ${ defaultValue } )`
331
333
}
332
334
return `(${ selector } || []).reduce((a,b) => methods[${
333
335
buildState . methods . length - 1
334
- } ]({ accumulator: a, current: b }, [null, context, above] ))`
336
+ } ]({ accumulator: a, current: b }, ${ aboveArray } ))`
335
337
} ,
336
338
method : ( input , context , above , engine ) => {
337
339
if ( ! Array . isArray ( input ) ) throw new InvalidControlInput ( input )
@@ -536,14 +538,17 @@ function createArrayIterativeMethod (name, useTruthy = false) {
536
538
extraArguments : 'index, above'
537
539
}
538
540
541
+ const method = build ( mapper , mapState )
542
+ const aboveArray = method . aboveDetected ? buildState . compile `[{ item: null }, context, above]` : buildState . compile `null`
543
+
539
544
if ( async ) {
540
545
if ( ! isSyncDeep ( mapper , buildState . engine , buildState ) ) {
541
546
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 } ))`
543
548
}
544
549
}
545
550
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 } ))`
547
552
} ,
548
553
traverse : false
549
554
}
0 commit comments