From 2981de43a23853baa3b13377e627809c71fbbbee Mon Sep 17 00:00:00 2001 From: Lasse Fister Date: Tue, 5 May 2020 04:40:34 +0200 Subject: [PATCH] Add explicit goDeeper option to wraped program;Fixes #1686 According to the commit message of 279e038: " [...] Helper authors now need to take care to return the same context value whenever it is conceptually the same and to avoid behaviors that may execute children under the current context in some situations and under different contexts under other situations." I belive that metric is too implicit, as the issue demonstrates. This is because in this case the context value is not conceptually the same, but it is de facto the same value. Instead this suggests to use an explicit option flag "goDeeper" to mark when a helper definitely should go deeper. This also should be backwards safe, as it doesn't change the behavior of existing helpers, builtin or custom, except the builtin "each", --- lib/handlebars/helpers/each.js | 3 ++- lib/handlebars/runtime.js | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/handlebars/helpers/each.js b/lib/handlebars/helpers/each.js index c1fa20f39..3487e4d78 100644 --- a/lib/handlebars/helpers/each.js +++ b/lib/handlebars/helpers/each.js @@ -52,7 +52,8 @@ export default function(instance) { blockParams: blockParams( [context[field], field], [contextPath + field, null] - ) + ), + goDeeper: true }); } diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index 67a500d79..7fa10bd8e 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -323,9 +323,10 @@ export function wrapProgram( function prog(context, options = {}) { let currentDepths = depths; if ( - depths && - context != depths[0] && - !(context === container.nullContext && depths[0] === null) + (depths && + context != depths[0] && + !(context === container.nullContext && depths[0] === null)) || + options.goDeeper ) { currentDepths = [context].concat(depths); }