diff --git a/lib/handlebars.js b/lib/handlebars.js
index e310eded..d88ad248 100644
--- a/lib/handlebars.js
+++ b/lib/handlebars.js
@@ -84,7 +84,7 @@ var Handlebars = {
buildContext: function(context, stack) {
var ContextWrapper = function(stack) {
- this.__stack__ = stack;
+ this.__stack__ = stack.slice(0);
this.__get__ = function(path) {
var context = this;
var parsedPath = Handlebars.parsePath(path);
@@ -367,7 +367,7 @@ Handlebars.Compiler.prototype = {
addBlock: function(mustache, param, parts) {
// set up the stack before the new compiler starts
- this.fn += "stack.push(context);";
+ //this.fn += "stack.push(context);";
var compiler = this.compileToEndOfBlock(mustache);
var result = compiler.fn;
@@ -375,6 +375,7 @@ Handlebars.Compiler.prototype = {
// don't need to be globally unique, just per compiler
var fnId = "fn" + this.pointer.toString();
this.fn += "var wrappedContext = Handlebars.buildContext(context, stack);";
+ this.fn += "stack.push(context);";
this.fn += "var " + fnId + " = function(context) {" + result + "}; ";
this.fn += "lookup = " + this.lookupFor(mustache) + "; ";
diff --git a/test/handlebars.js b/test/handlebars.js
index 3a521813..89ba9774 100644
--- a/test/handlebars.js
+++ b/test/handlebars.js
@@ -195,7 +195,7 @@ test("helper with complex lookup and nested template", function() {
var string = "{{#goodbyes}}{{#link}}{{text}}{{/link}}{{/goodbyes}}";
var hash = {prefix: '/root', goodbyes: [{text: "Goodbye", url: "goodbye"}]};
var fallback = {link: function (context, fn) {
- return "" + fn(context) + "";
+ return "" + fn(context) + "";
}};
shouldCompileTo(string, [hash, fallback], "Goodbye")
});