Skip to content

Commit

Permalink
Relax depth check for context push
Browse files Browse the repository at this point in the history
Fixes #1135
  • Loading branch information
kpdecker committed Dec 12, 2015
1 parent 63a0889 commit 25458fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function template(templateSpec, env) {
blockParams = templateSpec.useBlockParams ? [] : undefined;
if (templateSpec.useDepths) {
if (options.depths) {
depths = context !== options.depths[0] ? [context].concat(options.depths) : options.depths;
depths = context != options.depths[0] ? [context].concat(options.depths) : options.depths;
} else {
depths = [context];
}
Expand Down Expand Up @@ -174,7 +174,7 @@ export function template(templateSpec, env) {
export function wrapProgram(container, i, fn, data, declaredBlockParams, blockParams, depths) {
function prog(context, options = {}) {
let currentDepths = depths;
if (depths && context !== depths[0]) {
if (depths && context != depths[0]) {
currentDepths = [context].concat(depths);
}

Expand Down
23 changes: 23 additions & 0 deletions spec/regressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,27 @@ describe('Regressions', function() {
};
shouldCompileToWithPartials(string, [{}, {}, partials], true, 'Outer');
});

it('GH-1135 : Context handling within each iteration', function() {
var obj = {array: [1], name: 'John'};
var helpers = {
myif: function(conditional, options) {
if (conditional) {
return options.fn(this);
} else {
return options.inverse(this);
}
}
};

shouldCompileTo(`
{{#each array}}
1. IF: {{#if true}}{{../name}}-{{../../name}}-{{../../../name}}{{/if}}
2. MYIF: {{#myif true}}{{../name}}={{../../name}}={{../../../name}}{{/myif}}
{{/each}}
`, [obj, helpers], `
1. IF: John--
2. MYIF: John==
`);
});
});

0 comments on commit 25458fd

Please sign in to comment.