Simplify ambiguous code
Remove if conditional in favor of boolean failover.
This commit is contained in:
@@ -364,6 +364,7 @@ Compiler.prototype = {
|
||||
var options = this.options;
|
||||
|
||||
// if ambiguous, we can possibly resolve the ambiguity now
|
||||
// An eligible helper is one that does not have a complex path, i.e. `this.foo`, `../foo` etc.
|
||||
if (isEligible && !isHelper) {
|
||||
var name = sexpr.id.parts[0];
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user