summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js45
1 files changed, 33 insertions, 12 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index c36f7e1..6eda2ea 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -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);
+
+ this.pushStack("foundHelper ? foundHelper.call(" +
+ helper.callParams + ") " + ": helperMissing.call(" +
+ helper.helperMissingParams + ")");
+ },
+
+ invokeKnownHelper: function(paramSize, name) {
+ var helper = this.setupHelper(paramSize, name);
+ this.pushStack(helper.name + ".call(" + helper.callParams + ")");
+ },
- var main = ["depth0"].concat(params).join(", ");
- var helperMissing = ["depth0", this.quotedString(name)].concat(params).join(", ");
- this.pushStack("foundHelper ? foundHelper.call(" + main + ") " +
- ": helperMissing.call(" + helperMissing + ")");
+ setupHelper: function(paramSize, name) {
+ var params = [];
+ this.setupParams(paramSize, params);
+ var foundHelper = this.nameLookup('helpers', name, 'helper');
- //this.replaceStack(function(current) {
- //});
+ 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