@@ -30,30 +30,31 @@ class LogicEngine {
3030
3131 /**
3232 * An internal method used to parse through the JSON Logic at a lower level.
33- * @param {String } func The name of the function being executed
34- * @param {* } data The data to traverse / execute upon
33+ * @param {* } logic The logic being executed.
3534 * @param {* } context The context of the logic being run (input to the function.)
3635 * @param {* } above The context above (can be used for handlebars-style data traversal.)
37- * @returns {* }
36+ * @returns {{ result: *, func: string } }
3837 */
39- _parse ( func , data , context , above ) {
38+ _parse ( logic , context , above ) {
39+ const [ func ] = Object . keys ( logic )
40+ const data = logic [ func ]
4041 if ( this . methods [ func ] ) {
4142 if ( typeof this . methods [ func ] === 'function' ) {
4243 const input = this . run ( data , context , { above } )
43- if ( this . options . yieldSupported && checkYield ( input ) ) return input
44- return this . methods [ func ] ( input , context , above , this )
44+ if ( this . options . yieldSupported && checkYield ( input ) ) return { result : input , func }
45+ return { result : this . methods [ func ] ( input , context , above , this ) , func }
4546 }
4647 if ( typeof this . methods [ func ] === 'object' ) {
4748 const { method, traverse } = this . methods [ func ]
4849 const shouldTraverse = typeof traverse === 'undefined' ? true : traverse
4950 const parsedData = shouldTraverse
5051 ? this . run ( data , context , { above } )
5152 : data
52- if ( this . options . yieldSupported && checkYield ( parsedData ) ) return parsedData
53- return method ( parsedData , context , above , this )
53+ if ( this . options . yieldSupported && checkYield ( parsedData ) ) return { result : parsedData , func }
54+ return { result : method ( parsedData , context , above , this ) , func }
5455 }
5556 }
56- if ( this . options . permissive ) return { [ func ] : data }
57+ if ( this . options . permissive ) return { result : logic , func }
5758 throw new Error ( `Method '${ func } ' was not found in the Logic Engine.` )
5859 }
5960
@@ -111,8 +112,7 @@ class LogicEngine {
111112 return result
112113 }
113114 if ( logic && typeof logic === 'object' ) {
114- const [ func ] = Object . keys ( logic )
115- const result = this . _parse ( func , logic [ func ] , data , above )
115+ const { func, result } = this . _parse ( logic , data , above )
116116 if ( this . options . yieldSupported && checkYield ( result ) ) {
117117 if ( result instanceof YieldStructure ) {
118118 if ( result . _input ) {
0 commit comments