diff options
author | Kevin Decker <kpdecker@gmail.com> | 2014-01-15 08:42:32 -0800 |
---|---|---|
committer | Kevin Decker <kpdecker@gmail.com> | 2014-01-15 08:42:32 -0800 |
commit | 5659db4877b7e28284bb7edb08d8c1d081d5726e (patch) | |
tree | 4782d5640c0b6a80ea3b78d388b20a785b3bb5ff /lib/handlebars/compiler/javascript-compiler.js | |
parent | cb80f4684323f2924d4251eeb3d7b12cc37ea6d7 (diff) | |
parent | d385e2cab64d169f912348f4f4281d64ae6b7b2f (diff) | |
download | handlebars.js-5659db4877b7e28284bb7edb08d8c1d081d5726e.zip handlebars.js-5659db4877b7e28284bb7edb08d8c1d081d5726e.tar.gz handlebars.js-5659db4877b7e28284bb7edb08d8c1d081d5726e.tar.bz2 |
Merge pull request #634 from wycats/name-option
It would be great to have the helper name passed to `blockHelperMissing`
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r-- | lib/handlebars/compiler/javascript-compiler.js | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index d6baf13..abdc805 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -224,11 +224,11 @@ JavaScriptCompiler.prototype = { // `{{#this.foo}}...{{/this.foo}}`, resolve the value of `foo`, and // replace it on the stack with the result of properly // invoking blockHelperMissing. - blockValue: function() { + blockValue: function(name) { this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing'; var params = ["depth0"]; - this.setupParams(0, params); + this.setupParams(name, 0, params); this.replaceStack(function(current) { params.splice(1, 0, current); @@ -247,7 +247,7 @@ JavaScriptCompiler.prototype = { // We're being a bit cheeky and reusing the options value from the prior exec var params = ["depth0"]; - this.setupParams(0, params, true); + this.setupParams('', 0, params, true); this.flushInline(); @@ -504,20 +504,15 @@ JavaScriptCompiler.prototype = { this.context.aliases.helperMissing = 'helpers.helperMissing'; this.useRegister('helper'); - var helper = this.lastHelper = this.setupHelper(paramSize, name, true); + var helper = this.setupHelper(paramSize, name); var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context'); - var lookup = 'helper = ' + helper.name + ' || ' + nonHelper; + var lookup = 'helper = ' + helper.name + ' || ' + nonHelper + ' || helperMissing'; if (helper.paramsInit) { lookup += ',' + helper.paramsInit; } - this.push( - '(' - + lookup - + ',helper ' - + '? helper.call(' + helper.callParams + ') ' - + ': helperMissing.call(' + helper.helperMissingParams + '))'); + this.push('(' + lookup + ',helper.call(' + helper.callParams + '))'); // Always flush subexpressions. This is both to prevent the compounding size issue that // occurs when the code has to be duplicated for inlining and also to prevent errors @@ -824,23 +819,23 @@ JavaScriptCompiler.prototype = { .replace(/\u2029/g, '\\u2029') + '"'; }, - setupHelper: function(paramSize, name, missingParams) { + setupHelper: function(paramSize, name, blockHelper) { var params = [], - paramsInit = this.setupParams(paramSize, params, missingParams); + paramsInit = this.setupParams(name, paramSize, params, blockHelper); var foundHelper = this.nameLookup('helpers', name, 'helper'); return { params: params, paramsInit: paramsInit, name: foundHelper, - callParams: ["depth0"].concat(params).join(", "), - helperMissingParams: missingParams && ["depth0", this.quotedString(name)].concat(params).join(", ") + callParams: ["depth0"].concat(params).join(", ") }; }, - setupOptions: function(paramSize, params) { + setupOptions: function(helper, paramSize, params) { var options = [], contexts = [], types = [], param, inverse, program; + options.push("name:" + this.quotedString(helper)); options.push("hash:" + this.popStack()); if (this.stringParams) { @@ -892,8 +887,8 @@ JavaScriptCompiler.prototype = { // the params and contexts arguments are passed in arrays // to fill in - setupParams: function(paramSize, params, useRegister) { - var options = '{' + this.setupOptions(paramSize, params).join(',') + '}'; + setupParams: function(helperName, paramSize, params, useRegister) { + var options = '{' + this.setupOptions(helperName, paramSize, params).join(',') + '}'; if (useRegister) { this.useRegister('options'); |