diff --git a/lib/dust.js b/lib/dust.js index 2cc5a440..6387b422 100644 --- a/lib/dust.js +++ b/lib/dust.js @@ -438,24 +438,12 @@ Chunk.prototype.section = function(elem, context, bodies, params) { // for anonymous functions that did not returns a chunk, truthiness is evaluated based on the return value // else if (elem || elem === 0) { - if (body) { - if(context.stack.head && typeof elem === 'object') { - context.stack.head['$idx'] = 0; - context.stack.head['$len'] = 1; - } - chunk = body(this, context.push(elem)); - if(context.stack.head && typeof elem === 'object') { - context.stack.head['$idx'] = undefined; - context.stack.head['$len'] = undefined; - } - return chunk; - } - } - // nonexistent, scalar false value, scalar empty string, null, + if (body) return body(this, context.push(elem)); + // nonexistent, scalar false value, scalar empty string, null, // undefined are all falsy - else if (skip) { + } else if (skip) { return skip(this, context); - } + } return this; }; diff --git a/test/jasmine-test/spec/coreTests.js b/test/jasmine-test/spec/coreTests.js index 36148263..379fc634 100644 --- a/test/jasmine-test/spec/coreTests.js +++ b/test/jasmine-test/spec/coreTests.js @@ -573,6 +573,13 @@ var coreTests = [ expected: "0Moe 1Larry 2Curly ", message: "test array reference $idx/$len {#.} section case" }, + { + name: "array reference $idx/$len not changed in nested object", + source: "{#results}{#info}{$idx}{name}-{$len} {/info}{/results}", + context: { results: [ {info: {name: "Steven"}  },  {info: {name: "Richard"} } ]  }, + expected: "0Steven-2 1Richard-2 ", + message: "test array reference $idx/$len not changed in nested object" + }, { name: "array reference $idx/$len nested loops", source: "{#A}A loop:{$idx}-{$len},{#B}B loop:{$idx}-{$len}C[0]={.C[0]} {/B}A loop trailing: {$idx}-{$len}{/A}",