Skip to content

Commit

Permalink
Track depths on deduped children
Browse files Browse the repository at this point in the history
Fixes a very specific error case where deduped children won’t receive the depths object due to it being omitted by the caller when optimizing.

Fixes #926
  • Loading branch information
kpdecker committed Dec 16, 2014
1 parent 69b1bdd commit 59e80c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@ JavaScriptCompiler.prototype = {
} else {
child.index = index;
child.name = 'program' + index;

this.useDepths = this.useDepths || child.depths.list.length;
}
}
},
Expand Down
19 changes: 18 additions & 1 deletion spec/regressions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global CompilerContext, Handlebars, shouldCompileTo, shouldThrow */
/*global CompilerContext, shouldCompileTo, shouldThrow */
describe('Regressions', function() {
it("GH-94: Cannot read property of undefined", function() {
var data = {"books":[{"title":"The origin of species","author":{"name":"Charles Darwin"}},{"title":"Lazarillo de Tormes"}]};
Expand Down Expand Up @@ -145,4 +145,21 @@ describe('Regressions', function() {

shouldCompileTo('{{str bar.baz}}', [{}, helpers], 'undefined');
});

it('GH-926: Depths and de-dupe', function() {
var context = {
name: 'foo',
data: [
1
],
notData: [
1
]
};

var template = CompilerContext.compile('{{#if dater}}{{#each data}}{{../name}}{{/each}}{{else}}{{#each notData}}{{../name}}{{/each}}{{/if}}');

var result = template(context);
equals(result, 'foo');
});
});

0 comments on commit 59e80c5

Please sign in to comment.