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