From bbe0a94d6e5e909361d3f1195b1bc72dc31e233f Mon Sep 17 00:00:00 2001 From: Lon Ingram Date: Tue, 16 Aug 2016 15:47:33 -0500 Subject: Walk up data frames for nested @partial-block The root cause of #1218 is that `invokePartial` creates a stack of data frames for nested partial blocks, but `resolvePartial` always uses the value at top of the stack without "popping" it. The result is an infinite recursive loop, as references to `@partial-block` in the partial at the top of the stack resolve to itself. So, walk up the stack of data frames when evaluating. This is accomplished by 1) setting the `partial-block` property to `noop` after use and 2) using `_parent['partial-block']` if `partial-block` is `noop` Fix #1218 --- lib/handlebars/runtime.js | 7 ++++++- spec/partials.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index 55eb1c1..7426f1f 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -197,7 +197,12 @@ export function wrapProgram(container, i, fn, data, declaredBlockParams, blockPa export function resolvePartial(partial, context, options) { if (!partial) { if (options.name === '@partial-block') { - partial = options.data['partial-block']; + let data = options.data; + while (data['partial-block'] === noop) { + data = data._parent; + } + partial = data['partial-block']; + data['partial-block'] = noop; } else { partial = options.partials[options.name]; } diff --git a/spec/partials.js b/spec/partials.js index d3ead74..07d1c0d 100644 --- a/spec/partials.js +++ b/spec/partials.js @@ -270,6 +270,20 @@ describe('partials', function() { true, 'success'); }); + it('should render nested partial blocks', function() { + shouldCompileToWithPartials( + '.template-start.{{#> outer}}{{value}}{{/outer}}.template-end.', + [ + {value: 'success'}, + {}, + { + outer: '.outer-start.{{#> nested}}.outer-partial-block-start.{{> @partial-block}}.outer-partial-block-end.{{/nested}}.outer-end.', + nested: '.nested-start.{{> @partial-block}}.nested-end.' + } + ], + true, + '.template-start..outer-start..nested-start..outer-partial-block-start.success.outer-partial-block-end..nested-end..outer-end..template-end.'); + }); }); describe('inline partials', function() { -- cgit v1.1 From 601ce8a69f2d2de77400fe207713bd81a133d8e3 Mon Sep 17 00:00:00 2001 From: Lon Ingram Date: Wed, 17 Aug 2016 13:32:50 -0500 Subject: Add test reproducing #1185 --- spec/partials.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/partials.js b/spec/partials.js index 07d1c0d..fcfc780 100644 --- a/spec/partials.js +++ b/spec/partials.js @@ -323,6 +323,15 @@ describe('partials', function() { true, 'success'); }); + it('should render nested inline partials', function() { + shouldCompileToWithPartials( + '{{#*inline "outer"}}{{#>inner}}{{>@partial-block}}{{/inner}}{{/inline}}' + + '{{#*inline "inner"}}{{>@partial-block}}{{/inline}}' + + '{{#>outer}}{{value}}{{/outer}}', + [{value: 'success'}, {}, {}], + true, + 'success'); + }); }); it('should pass compiler flags', function() { -- cgit v1.1 From 21696005cd9e5a3ea2150431df44fd13da2c405c Mon Sep 17 00:00:00 2001 From: Lon Ingram Date: Wed, 17 Aug 2016 13:36:16 -0500 Subject: Use XML-like tags in test instead of bizarre dot delimiters --- spec/partials.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/partials.js b/spec/partials.js index fcfc780..d6baba5 100644 --- a/spec/partials.js +++ b/spec/partials.js @@ -272,17 +272,17 @@ describe('partials', function() { }); it('should render nested partial blocks', function() { shouldCompileToWithPartials( - '.template-start.{{#> outer}}{{value}}{{/outer}}.template-end.', + '', [ {value: 'success'}, {}, { - outer: '.outer-start.{{#> nested}}.outer-partial-block-start.{{> @partial-block}}.outer-partial-block-end.{{/nested}}.outer-end.', - nested: '.nested-start.{{> @partial-block}}.nested-end.' + outer: '{{#> nested}}{{> @partial-block}}{{/nested}}', + nested: '{{> @partial-block}}' } ], true, - '.template-start..outer-start..nested-start..outer-partial-block-start.success.outer-partial-block-end..nested-end..outer-end..template-end.'); + ''); }); }); -- cgit v1.1