Differentiate between lambdas in the context (which should have mustache semantics) and helpers (which have Handlebars helper semantics).
This commit is contained in:
@@ -408,6 +408,12 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
preamble: function() {
|
||||
var out = [];
|
||||
|
||||
// this register will disambiguate helper lookup from finding a function in
|
||||
// a context. This is necessary for mustache compatibility, which requires
|
||||
// that context functions in blocks are evaluated by blockHelperMissing, and
|
||||
// then proceed as if the resulting value was provided to blockHelperMissing.
|
||||
this.useRegister('foundHelper');
|
||||
|
||||
if (!this.isChild) {
|
||||
var namespace = this.namespace;
|
||||
var copies = "helpers = helpers || " + namespace + ".helpers;";
|
||||
@@ -520,10 +526,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
} else if (isScoped || this.options.knownHelpersOnly) {
|
||||
toPush = topStack + " = " + this.nameLookup('depth' + this.lastContext, name, 'context');
|
||||
} else {
|
||||
toPush = topStack + " = "
|
||||
+ this.nameLookup('helpers', name, 'helper')
|
||||
+ " || "
|
||||
+ this.nameLookup('depth' + this.lastContext, name, 'context');
|
||||
this.register('foundHelper', this.nameLookup('helpers', name, 'helper'));
|
||||
toPush = topStack + " = foundHelper || " + this.nameLookup('depth' + this.lastContext, name, 'context');
|
||||
}
|
||||
|
||||
toPush += ';';
|
||||
@@ -618,10 +622,10 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
params.push(stringOptions);
|
||||
|
||||
this.populateCall(params, id, helperId || id, fn);
|
||||
this.populateCall(params, id, helperId || id, fn, program !== '{}');
|
||||
},
|
||||
|
||||
populateCall: function(params, id, helperId, fn) {
|
||||
populateCall: function(params, id, helperId, fn, program) {
|
||||
var paramString = ["depth0"].concat(params).join(", ");
|
||||
var helperMissingString = ["depth0"].concat(helperId).concat(params).join(", ");
|
||||
|
||||
@@ -631,7 +635,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
this.source.push(nextStack + " = " + id + ".call(" + paramString + ");");
|
||||
} else {
|
||||
this.context.aliases.functionType = '"function"';
|
||||
this.source.push("if(typeof " + id + " === functionType) { " + nextStack + " = " + id + ".call(" + paramString + "); }");
|
||||
var condition = program ? "foundHelper && " : ""
|
||||
this.source.push("if(" + condition + "typeof " + id + " === functionType) { " + nextStack + " = " + id + ".call(" + paramString + "); }");
|
||||
}
|
||||
fn.call(this, nextStack, helperMissingString, id);
|
||||
this.usingKnownHelper = false;
|
||||
|
||||
Reference in New Issue
Block a user