summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-12-12 15:27:56 -0600
committerkpdecker <kpdecker@gmail.com>2015-12-12 15:27:56 -0600
commit25458fdc2a3ad179d1eb4c8ae401c7b9bfdfb0d2 (patch)
treeb960c722e7c666887ac4b4d1919de480fa55b467
parent63a08890cce3620f3af328163f4313754df76581 (diff)
downloadhandlebars.js-25458fdc2a3ad179d1eb4c8ae401c7b9bfdfb0d2.zip
handlebars.js-25458fdc2a3ad179d1eb4c8ae401c7b9bfdfb0d2.tar.gz
handlebars.js-25458fdc2a3ad179d1eb4c8ae401c7b9bfdfb0d2.tar.bz2
Relax depth check for context push
Fixes #1135
-rw-r--r--lib/handlebars/runtime.js4
-rw-r--r--spec/regressions.js23
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index 5c479a8..55eb1c1 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -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];
}
@@ -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);
}
diff --git a/spec/regressions.js b/spec/regressions.js
index 83765a2..9bd00d9 100644
--- a/spec/regressions.js
+++ b/spec/regressions.js
@@ -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==
+ `);
+ });
});