From 1d349f1c270d5e739f251fa17fd5647f57b44b03 Mon Sep 17 00:00:00 2001 From: Joel Gallant Date: Fri, 31 May 2019 17:44:21 -0600 Subject: [PATCH] Keeps @root intact in repeat block --- index.js | 3 ++- test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e7dd058..d16ba00 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,8 @@ function repeatBlock({ count, start, step }, thisArg, options) { start, step, first: index === start, - last: index >= max - step + last: index >= max - step, + root: options.data.root, }; var blockParams = [index, data]; str += options.fn(thisArg, { data, blockParams }); diff --git a/test.js b/test.js index f443350..18d0220 100644 --- a/test.js +++ b/test.js @@ -121,6 +121,21 @@ describe('handlebars', function() { var actual = handlebars.compile(template)(ctx); assert.equal(actual, expected); }); + + it('should keep @root intact', function() { + var ctx = {bar: [0],foo: 'bar'}; + var template = + '{{#each bar}}' + + '{{#repeat 1}}' + + '{{@root/foo}}' + + '{{/repeat}}' + + '{{/each}}' + + ''; + var expected = + 'bar'; + var actual = handlebars.compile(template)(ctx); + assert.equal(actual, expected); + }); }); describe('Templates', function() {