Bundled up the block handling into a handleBlock function - means less code gen and more already jit-ed code, hopefully.

This commit is contained in:
Alan Johnson
2010-09-14 08:03:54 -04:00
parent c176892639
commit 384ebf6373
+21 -6
View File
@@ -164,6 +164,22 @@ var Handlebars = {
} else {
return value;
}
},
handleBlock: function(lookup, context, proxy, fn, notFn) {
var out = "";
if (Handlebars.isFunction(lookup)) {
out = out + lookup.call(context, proxy, fn);
}
else if (typeof lookup != 'undefined') {
out = out + Handlebars.helperMissing.call(proxy, lookup, fn);
}
if (notFn != null && Handlebars.isFunction(lookup.not)) {
out = out + lookup.not.call(context, proxy, notFn);
}
return out;
}
}
@@ -334,16 +350,15 @@ Handlebars.Compiler.prototype = {
this.fn += "var wrappedContext = Handlebars.buildContext(context);";
this.fn += "var " + fnId + " = function(context) {" + result + "}; ";
this.fn += "lookup = " + this.lookupFor(mustache) + "; ";
this.fn += "if(Handlebars.isFunction(lookup)) out = out + lookup.call(wrappedContext, proxy, " + fnId + "); ";
this.fn += "else if(typeof lookup !== 'undefined') { out = out + Handlebars.helperMissing.call(proxy, lookup, " + fnId + "); }";
if (compiler.continueInverted) {
var invertedCompiler = this.compileToEndOfBlock(mustache);
this.fn += "if (Handlebars.isFunction(lookup.not)) {";
this.fn += " var " + fnId + "Not = function(context) { " + invertedCompiler.fn + " };";
this.fn += " out = out + lookup.not.call(wrappedContext, proxy, " + fnId + "Not);";
this.fn += "}";
}
else {
this.fn += " var " + fnId + "Not = null;";
}
this.fn += "out = out + Handlebars.handleBlock(lookup, wrappedContext, proxy, " + fnId + ", " + fnId + "Not);"
this.fn += "stack.pop();";
this.openBlock = false;