summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/handlebars/compiler/compiler.js21
-rw-r--r--spec/qunit_spec.js12
2 files changed, 26 insertions, 7 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 04ad918..97e8c91 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -886,21 +886,28 @@ Handlebars.JavaScriptCompiler = function() {};
},
pushStack: function(item) {
- this.source.push(this.incrStack() + " = " + item + ";");
- this.compileStack.push("stack" + this.stackSlot);
- return "stack" + this.stackSlot;
+ var stack = this.incrStack();
+ this.source.push(stack + " = " + item + ";");
+ this.compileStack.push(stack);
+ return stack;
},
replaceStack: function(callback) {
- var item = callback.call(this, this.topStack());
+ var stack = this.topStack(),
+ item = callback.call(this, stack);
- this.source.push(this.topStack() + " = " + item + ";");
- return "stack" + this.stackSlot;
+ // Prevent modification of the context depth variable. Through replaceStack
+ if (this.compileStack.length <= 1) {
+ stack = this.nextStack();
+ }
+
+ this.source.push(stack + " = " + item + ";");
+ return stack;
},
nextStack: function(skipCompileStack) {
var name = this.incrStack();
- this.compileStack.push("stack" + this.stackSlot);
+ this.compileStack.push(name);
return name;
},
diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js
index 1e859e5..f16949e 100644
--- a/spec/qunit_spec.js
+++ b/spec/qunit_spec.js
@@ -1282,3 +1282,15 @@ test("Passing falsy values to Handlebars.compile throws an error", function() {
CompilerContext.compile(null);
}, "You must pass a string to Handlebars.compile. You passed null");
});
+
+test('GH-408: Multiple loops fail', function() {
+ var context = [
+ { name: "John Doe", location: { city: "Chicago" } },
+ { name: "Jane Doe", location: { city: "New York"} }
+ ];
+
+ var template = CompilerContext.compile('{{#.}}{{name}}{{/.}}{{#.}}{{name}}{{/.}}');
+
+ var result = template(context);
+ equals(result, "John DoeJane DoeJohn DoeJane Doe", 'It should output twice');
+});