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() {