@@ -290,7 +290,7 @@ const defaultMethods = {
290290 lazy : true
291291 } ,
292292 '??' : defineCoalesce ( ) ,
293- try : defineCoalesce ( downgrade ) ,
293+ try : defineCoalesce ( downgrade , true ) ,
294294 and : {
295295 [ Sync ] : ( data , buildState ) => isSyncDeep ( data , buildState . engine , buildState ) ,
296296 method : ( arr , _1 , _2 , engine ) => {
@@ -715,7 +715,7 @@ const defaultMethods = {
715715/**
716716 * Defines separate coalesce methods
717717 */
718- function defineCoalesce ( func ) {
718+ function defineCoalesce ( func , panic ) {
719719 let downgrade
720720 if ( func ) downgrade = func
721721 else downgrade = ( a ) => a
@@ -734,6 +734,7 @@ function defineCoalesce (func) {
734734 }
735735
736736 if ( item === undefined ) return null
737+ if ( panic ) throw item
737738 return item
738739 } ,
739740 asyncMethod : async ( arr , _1 , _2 , engine ) => {
@@ -748,6 +749,7 @@ function defineCoalesce (func) {
748749 }
749750
750751 if ( item === undefined ) return null
752+ if ( panic ) throw item
751753 return item
752754 } ,
753755 deterministic : ( data , buildState ) => isDeterministic ( data , buildState . engine , buildState ) ,
@@ -756,8 +758,10 @@ function defineCoalesce (func) {
756758 const funcCall = func ? 'downgrade' : ''
757759 if ( Array . isArray ( data ) && data . length ) {
758760 return `(${ data . map ( ( i , x ) => {
759- if ( Array . isArray ( i ) || ! i || typeof i !== 'object' || x === data . length - 1 ) return buildString ( i , buildState )
760- return `${ funcCall } (` + buildString ( i , buildState ) + ')'
761+ const built = buildString ( i , buildState )
762+ if ( panic && x === data . length - 1 ) return `(typeof ((prev = ${ built } ) || 0).error !== 'undefined' || Number.isNaN(prev) ? (() => { throw prev.error })() : prev)`
763+ if ( Array . isArray ( i ) || ! i || typeof i !== 'object' || x === data . length - 1 ) return built
764+ return `${ funcCall } (` + built + ')'
761765 } ) . join ( ' ?? ' ) } )`
762766 }
763767 return `(${ buildString ( data , buildState ) } ).reduce((a,b) => ${ funcCall } (a) ?? b, null)`
0 commit comments