Continue work on cleaning up helpers
This commit is contained in:
@@ -28,7 +28,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
lookupOnContext: 19,
|
||||
resolvePossibleLambda: 20,
|
||||
invokeHelper: 21,
|
||||
pushLiteral: 22
|
||||
pushLiteral: 22,
|
||||
invokeKnownHelper: 23
|
||||
};
|
||||
|
||||
Compiler.MULTI_PARAM_OPCODES = {
|
||||
@@ -50,7 +51,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
lookupOnContext: 1,
|
||||
resolvePossibleLambda: 0,
|
||||
invokeHelper: 2,
|
||||
pushLiteral: 1
|
||||
pushLiteral: 1,
|
||||
invokeKnownHelper: 2
|
||||
};
|
||||
|
||||
Compiler.DISASSEMBLE_MAP = {};
|
||||
@@ -278,7 +280,13 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
var params = this.setupMustacheParams(mustache),
|
||||
name = mustache.id.parts[0];
|
||||
|
||||
this.opcode('invokeHelper', params.length, name);
|
||||
if (this.options.knownHelpers[name]) {
|
||||
this.opcode('invokeKnownHelper', params.length, name);
|
||||
} else if (this.knownHelpersOnly) {
|
||||
throw new Error("You specified knownHelpersOnly, but used the unknown helper " + name);
|
||||
} else {
|
||||
this.opcode('invokeHelper', params.length, name);
|
||||
}
|
||||
},
|
||||
|
||||
ID: function(id) {
|
||||
@@ -677,17 +685,30 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
invokeHelper: function(paramSize, name) {
|
||||
this.context.aliases.helperMissing = 'helpers.helperMissing';
|
||||
|
||||
var params = [], contexts = [];
|
||||
this.setupParams(paramSize, params, contexts);
|
||||
this.register('foundHelper', this.nameLookup('helpers', name, 'helper'));
|
||||
var helper = this.setupHelper(paramSize, name);
|
||||
this.register('foundHelper', helper.name);
|
||||
|
||||
var main = ["depth0"].concat(params).join(", ");
|
||||
var helperMissing = ["depth0", this.quotedString(name)].concat(params).join(", ");
|
||||
this.pushStack("foundHelper ? foundHelper.call(" + main + ") " +
|
||||
": helperMissing.call(" + helperMissing + ")");
|
||||
this.pushStack("foundHelper ? foundHelper.call(" +
|
||||
helper.callParams + ") " + ": helperMissing.call(" +
|
||||
helper.helperMissingParams + ")");
|
||||
},
|
||||
|
||||
//this.replaceStack(function(current) {
|
||||
//});
|
||||
invokeKnownHelper: function(paramSize, name) {
|
||||
var helper = this.setupHelper(paramSize, name);
|
||||
this.pushStack(helper.name + ".call(" + helper.callParams + ")");
|
||||
},
|
||||
|
||||
setupHelper: function(paramSize, name) {
|
||||
var params = [];
|
||||
this.setupParams(paramSize, params);
|
||||
var foundHelper = this.nameLookup('helpers', name, 'helper');
|
||||
|
||||
return {
|
||||
params: params,
|
||||
name: foundHelper,
|
||||
callParams: ["depth0"].concat(params).join(", "),
|
||||
helperMissingParams: ["depth0", this.quotedString(name)].concat(params).join(", ")
|
||||
};
|
||||
},
|
||||
|
||||
// the params and contexts arguments are passed in arrays
|
||||
|
||||
Reference in New Issue
Block a user