Skip to content

Commit

Permalink
Add explicit goDeeper option to wraped program;Fixes #1686
Browse files Browse the repository at this point in the history
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",
  • Loading branch information
graphicore committed May 5, 2020
1 parent 353e0f9 commit 2981de4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/handlebars/helpers/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default function(instance) {
blockParams: blockParams(
[context[field], field],
[contextPath + field, null]
)
),
goDeeper: true
});
}

Expand Down
7 changes: 4 additions & 3 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 2981de4

Please sign in to comment.