diff options
author | kpdecker <kpdecker@gmail.com> | 2014-01-04 09:14:22 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-01-04 09:19:58 -0600 |
commit | 6d996ef2706c6f0f9fd60e18ea90b5565096c568 (patch) | |
tree | bf03405123482d3fb1cf2f52c407b40a0fa258b0 /lib/handlebars/compiler/javascript-compiler.js | |
parent | 55c7cbbbfa830d225e91440836b440f8019e3ac0 (diff) | |
download | handlebars.js-6d996ef2706c6f0f9fd60e18ea90b5565096c568.zip handlebars.js-6d996ef2706c6f0f9fd60e18ea90b5565096c568.tar.gz handlebars.js-6d996ef2706c6f0f9fd60e18ea90b5565096c568.tar.bz2 |
Simplify ambiguous code
Remove if conditional in favor of boolean failover.
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r-- | lib/handlebars/compiler/javascript-compiler.js | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 7539068..cdf1693 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -220,7 +220,7 @@ JavaScriptCompiler.prototype = { // On stack, after: return value of blockHelperMissing // // The purpose of this opcode is to take a block of the form - // `{{#foo}}...{{/foo}}`, resolve the value of `foo`, and + // `{{#this.foo}}...{{/this.foo}}`, resolve the value of `foo`, and // replace it on the stack with the result of properly // invoking blockHelperMissing. blockValue: function() { @@ -244,8 +244,11 @@ JavaScriptCompiler.prototype = { ambiguousBlockValue: function() { this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing'; + // We're being a bit cheeky and reusing the options value from the prior exec var params = ["depth0"]; - this.setupParams(0, params); + this.setupParams(0, params, true); + + this.flushInline(); var current = this.topStack(); params.splice(1, 0, current); @@ -555,15 +558,12 @@ JavaScriptCompiler.prototype = { var helper = this.setupHelper(0, name, helperCall); var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper'); - var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context'); - var nextStack = this.nextStack(); - if (helper.paramsInit) { - this.pushSource(helper.paramsInit); - } - this.pushSource('if (helper = ' + helperName + ') { ' + nextStack + ' = helper.call(' + helper.callParams + '); }'); - this.pushSource('else { helper = ' + nonHelper + '; ' + nextStack + ' = typeof helper === functionType ? helper.call(' + helper.callParams + ') : helper; }'); + this.push( + '((helper = ' + helperName + ' || ' + nonHelper + + (helper.paramsInit ? '),(' + helper.paramsInit : '') + '),' + + '(typeof helper === functionType ? helper.call(' + helper.callParams + ') : helper))'); }, // [invokePartial] |