@@ -217,6 +217,12 @@ const defaultMethods = {
217
217
) {
218
218
context = above [ iter ++ ]
219
219
key = key . substring ( 3 )
220
+ // A performance optimization that allows you to pass the previous above array without spreading it as the last argument
221
+ if ( iter === above . length && Array . isArray ( context ) ) {
222
+ iter = 0
223
+ above = context
224
+ context = above [ iter ++ ]
225
+ }
220
226
}
221
227
222
228
const notFound = b === undefined ? null : b
@@ -311,21 +317,21 @@ const defaultMethods = {
311
317
if ( typeof defaultValue !== 'undefined' ) {
312
318
return `await asyncIterators.reduce(${ selector } || [], (a,b) => methods[${
313
319
buildState . methods . length - 1
314
- } ]({ accumulator: a, current: b }, [null, context, ... above]), ${ defaultValue } )`
320
+ } ]({ accumulator: a, current: b }, [null, context, above]), ${ defaultValue } )`
315
321
}
316
322
return `await asyncIterators.reduce(${ selector } || [], (a,b) => methods[${
317
323
buildState . methods . length - 1
318
- } ]({ accumulator: a, current: b }, [null, context, ... above]))`
324
+ } ]({ accumulator: a, current: b }, [null, context, above]))`
319
325
}
320
326
}
321
327
if ( typeof defaultValue !== 'undefined' ) {
322
328
return `(${ selector } || []).reduce((a,b) => methods[${
323
329
buildState . methods . length - 1
324
- } ]({ accumulator: a, current: b }, [null, context, ... above]), ${ defaultValue } )`
330
+ } ]({ accumulator: a, current: b }, [null, context, above]), ${ defaultValue } )`
325
331
}
326
332
return `(${ selector } || []).reduce((a,b) => methods[${
327
333
buildState . methods . length - 1
328
- } ]({ accumulator: a, current: b }, [null, context, ... above]))`
334
+ } ]({ accumulator: a, current: b }, [null, context, above]))`
329
335
} ,
330
336
method : ( input , context , above , engine ) => {
331
337
if ( ! Array . isArray ( input ) ) throw new InvalidControlInput ( input )
@@ -345,7 +351,7 @@ const defaultMethods = {
345
351
current
346
352
} ,
347
353
{
348
- above : [ selector , context , ... above ]
354
+ above : [ selector , context , above ]
349
355
}
350
356
)
351
357
}
@@ -375,7 +381,7 @@ const defaultMethods = {
375
381
current
376
382
} ,
377
383
{
378
- above : [ selector , context , ... above ]
384
+ above : [ selector , context , above ]
379
385
}
380
386
)
381
387
} ,
@@ -398,19 +404,19 @@ const defaultMethods = {
398
404
[ Sync ] : ( data , buildState ) => isSyncDeep ( data , buildState . engine , buildState ) ,
399
405
method : ( args , context , above , engine ) => {
400
406
if ( ! Array . isArray ( args ) ) throw new Error ( 'Data for pipe must be an array' )
401
- let answer = engine . run ( args [ 0 ] , context , { above : [ args , context , ... above ] } )
402
- for ( let i = 1 ; i < args . length ; i ++ ) answer = engine . run ( args [ i ] , answer , { above : [ args , context , ... above ] } )
407
+ let answer = engine . run ( args [ 0 ] , context , { above : [ args , context , above ] } )
408
+ for ( let i = 1 ; i < args . length ; i ++ ) answer = engine . run ( args [ i ] , answer , { above : [ args , context , above ] } )
403
409
return answer
404
410
} ,
405
411
asyncMethod : async ( args , context , above , engine ) => {
406
412
if ( ! Array . isArray ( args ) ) throw new Error ( 'Data for pipe must be an array' )
407
- let answer = await engine . run ( args [ 0 ] , context , { above : [ args , context , ... above ] } )
408
- for ( let i = 1 ; i < args . length ; i ++ ) answer = await engine . run ( args [ i ] , answer , { above : [ args , context , ... above ] } )
413
+ let answer = await engine . run ( args [ 0 ] , context , { above : [ args , context , above ] } )
414
+ for ( let i = 1 ; i < args . length ; i ++ ) answer = await engine . run ( args [ i ] , answer , { above : [ args , context , above ] } )
409
415
return answer
410
416
} ,
411
417
compile : ( args , buildState ) => {
412
418
let res = buildState . compile `${ args [ 0 ] } `
413
- for ( let i = 1 ; i < args . length ; i ++ ) res = buildState . compile `${ build ( args [ i ] , { ...buildState , extraArguments : 'above' } ) } (${ res } , [null, context, ... above])`
419
+ for ( let i = 1 ; i < args . length ; i ++ ) res = buildState . compile `${ build ( args [ i ] , { ...buildState , extraArguments : 'above' } ) } (${ res } , [null, context, above])`
414
420
return res
415
421
} ,
416
422
deterministic : ( data , buildState ) => {
@@ -499,7 +505,7 @@ function createArrayIterativeMethod (name, useTruthy = false) {
499
505
500
506
return selector [ name ] ( ( i , index ) => {
501
507
const result = engine . run ( mapper , i , {
502
- above : [ { item : selector , index } , context , ... above ]
508
+ above : [ { item : selector , index } , context , above ]
503
509
} )
504
510
return useTruthy ? engine . truthy ( result ) : result
505
511
} )
@@ -513,7 +519,7 @@ function createArrayIterativeMethod (name, useTruthy = false) {
513
519
} ) ) || [ ]
514
520
return asyncIterators [ name ] ( selector , ( i , index ) => {
515
521
const result = engine . run ( mapper , i , {
516
- above : [ { item : selector , index } , context , ... above ]
522
+ above : [ { item : selector , index } , context , above ]
517
523
} )
518
524
return useTruthy ? engine . truthy ( result ) : result
519
525
} )
@@ -533,11 +539,11 @@ function createArrayIterativeMethod (name, useTruthy = false) {
533
539
if ( async ) {
534
540
if ( ! isSyncDeep ( mapper , buildState . engine , buildState ) ) {
535
541
buildState . detectAsync = true
536
- return buildState . compile `await asyncIterators[${ name } ](${ selector } || [], async (i, x) => ${ build ( mapper , mapState ) } (i, x, [{ item: null }, context, ... above]))`
542
+ return buildState . compile `await asyncIterators[${ name } ](${ selector } || [], async (i, x) => ${ build ( mapper , mapState ) } (i, x, [{ item: null }, context, above]))`
537
543
}
538
544
}
539
545
540
- return buildState . compile `(${ selector } || [])[${ name } ]((i, x) => ${ build ( mapper , mapState ) } (i, x, [{ item: null }, context, ... above]))`
546
+ return buildState . compile `(${ selector } || [])[${ name } ]((i, x) => ${ build ( mapper , mapState ) } (i, x, [{ item: null }, context, above]))`
541
547
} ,
542
548
traverse : false
543
549
}
0 commit comments