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:
+21
-6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user