@@ -7,7 +7,7 @@ import declareSync from './utilities/declareSync.js'
77import { build , buildString } from './compiler.js'
88import chainingSupported from './utilities/chainingSupported.js'
99import legacyMethods from './legacy.js'
10- import { precoerceNumber , assertNotType } from './utilities/downgrade.js'
10+ import { precoerceNumber , assertAllowedDepth } from './utilities/downgrade.js'
1111
1212const INVALID_ARGUMENTS = { type : 'Invalid Arguments' }
1313
@@ -402,7 +402,7 @@ const defaultMethods = {
402402 }
403403
404404 res = buildState . compile `${ res } } })(context, above)`
405- if ( res [ Compiled ] . includes ( 'await' ) ) res [ Compiled ] = res [ Compiled ] . replace ( '((context' , '(async (context' )
405+ if ( res [ Compiled ] . includes ( 'await' ) ) res [ Compiled ] = res [ Compiled ] . replace ( '((context' , 'await (async (context' )
406406
407407 return res
408408 }
@@ -653,16 +653,16 @@ const defaultMethods = {
653653 }
654654 mapper = build ( mapper , mapState )
655655 const aboveArray = mapper . aboveDetected ? '[null, context, above]' : 'null'
656- const verifyAccumulator = buildState . engine . options . enableObjectAccumulators ? '' : 'assertNotType '
656+ const verifyAccumulator = buildState . engine . options . maxDepth === Infinity ? '' : 'assertAllowedDepth '
657657 buildState . methods . push ( mapper )
658658
659659 if ( async ) {
660660 if ( ! isSync ( mapper ) || selector . includes ( 'await' ) ) {
661661 buildState . asyncDetected = true
662662 if ( typeof defaultValue !== 'undefined' ) {
663- return `await asyncIterators.reduce(${ selector } || [], (a,b) => methods[${ buildState . methods . length - 1 } ]({ accumulator: a, current: b }, ${ aboveArray } ), ${ defaultValue } , ${ buildState . engine . options . enableObjectAccumulators } )`
663+ return `await asyncIterators.reduce(${ selector } || [], (a,b) => methods[${ buildState . methods . length - 1 } ]({ accumulator: a, current: b }, ${ aboveArray } ), ${ defaultValue } , ${ buildState . engine . options . maxDepth } )`
664664 }
665- return `await asyncIterators.reduce(${ selector } || [], (a,b) => methods[${ buildState . methods . length - 1 } ]({ accumulator: a, current: b }, ${ aboveArray } ), undefined, ${ buildState . engine . options . enableObjectAccumulators } )`
665+ return `await asyncIterators.reduce(${ selector } || [], (a,b) => methods[${ buildState . methods . length - 1 } ]({ accumulator: a, current: b }, ${ aboveArray } ), undefined, ${ buildState . engine . options . maxDepth } )`
666666 }
667667 }
668668
@@ -675,15 +675,13 @@ const defaultMethods = {
675675 if ( ! Array . isArray ( input ) ) throw INVALID_ARGUMENTS
676676 let [ selector , mapper , defaultValue ] = input
677677
678- const verifyAccumulator = engine . options . enableObjectAccumulators ? a => a : assertNotType
679-
680- defaultValue = verifyAccumulator ( runOptimizedOrFallback ( defaultValue , engine , context , above ) )
678+ defaultValue = assertAllowedDepth ( runOptimizedOrFallback ( defaultValue , engine , context , above ) , engine . options . maxDepth )
681679 selector = runOptimizedOrFallback ( selector , engine , context , above ) || [ ]
682- let func = ( accumulator , current ) => verifyAccumulator ( engine . run ( mapper , { accumulator, current } , { above : [ selector , context , above ] } ) , 'object' )
680+ let func = ( accumulator , current ) => assertAllowedDepth ( engine . run ( mapper , { accumulator, current } , { above : [ selector , context , above ] } ) , engine . options . maxDepth )
683681
684682 if ( engine . optimizedMap . has ( mapper ) && typeof engine . optimizedMap . get ( mapper ) === 'function' ) {
685683 const optimized = engine . optimizedMap . get ( mapper )
686- func = ( accumulator , current ) => verifyAccumulator ( optimized ( { accumulator, current } , [ selector , context , above ] ) )
684+ func = ( accumulator , current ) => assertAllowedDepth ( optimized ( { accumulator, current } , [ selector , context , above ] ) , engine . options . maxDepth )
687685 }
688686
689687 if ( typeof defaultValue === 'undefined' ) return selector . reduce ( func )
@@ -694,9 +692,8 @@ const defaultMethods = {
694692 asyncMethod : async ( input , context , above , engine ) => {
695693 if ( ! Array . isArray ( input ) ) throw INVALID_ARGUMENTS
696694 let [ selector , mapper , defaultValue ] = input
697- const verifyAccumulator = engine . options . enableObjectAccumulators ? a => a : assertNotType
698695
699- defaultValue = verifyAccumulator ( await engine . run ( defaultValue , context , { above } ) )
696+ defaultValue = assertAllowedDepth ( await engine . run ( defaultValue , context , { above } ) , engine . options . maxDepth )
700697 selector = ( await engine . run ( selector , context , { above } ) ) || [ ]
701698 return asyncIterators . reduce (
702699 selector ,
@@ -713,7 +710,7 @@ const defaultMethods = {
713710 )
714711 } ,
715712 defaultValue ,
716- engine . enableObjectAccumulators
713+ engine . options . maxDepth
717714 )
718715 } ,
719716 lazy : true
@@ -823,7 +820,7 @@ const defaultMethods = {
823820 return accumulator
824821 } ,
825822 { } ,
826- true
823+ Infinity
827824 )
828825 return result
829826 }
0 commit comments