More stack fixes. The context stack was being corrupted by nested blocks and expressions.
This commit is contained in:
+3
-2
@@ -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) + "; ";
|
||||
|
||||
|
||||
+1
-1
@@ -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 "<a href='" + this.__get__("../../prefix") + "/" + context.url + "'>" + fn(context) + "</a>";
|
||||
return "<a href='" + this.__get__("../prefix") + "/" + context.url + "'>" + fn(context) + "</a>";
|
||||
}};
|
||||
shouldCompileTo(string, [hash, fallback], "<a href='/root/goodbye'>Goodbye</a>")
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user