Skip to content

Commit

Permalink
Restore helperMissing for ambiguous statements
Browse files Browse the repository at this point in the history
Fixes #318 (regression)
Partial fix for #783
  • Loading branch information
kpdecker committed Aug 23, 2014
1 parent cde008b commit 0c7c37d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ JavaScriptCompiler.prototype = {
// `knownHelpersOnly` flags at compile-time.
invokeAmbiguous: function(name, helperCall) {
this.aliases.functionType = '"function"';
this.aliases.helperMissing = 'helpers.helperMissing';
this.useRegister('helper');

var nonHelper = this.popStack();
Expand All @@ -561,7 +562,7 @@ JavaScriptCompiler.prototype = {
var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');

this.push(
'((helper = ' + helperName + ' || ' + nonHelper
'((helper = (helper = ' + helperName + ' || ' + nonHelper + ') != null ? helper : helperMissing'
+ (helper.paramsInit ? '),(' + helper.paramsInit : '') + '),'
+ '(typeof helper === functionType ? helper.call(' + helper.callParams + ') : helper))');
},
Expand Down
15 changes: 15 additions & 0 deletions spec/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,21 @@ describe('helpers', function() {

shouldCompileTo(string, [context, helpers], "Hello <a>world</a>");
});

it("if a value is not found, custom helperMissing is used", function() {
var string = "{{hello}} {{link_to}}";
var context = { hello: "Hello", world: "world" };

var helpers = {
helperMissing: function(options) {
if(options.name === "link_to") {
return new Handlebars.SafeString("<a>winning</a>");
}
}
};

shouldCompileTo(string, [context, helpers], "Hello <a>winning</a>");
});
});

describe("knownHelpers", function() {
Expand Down

0 comments on commit 0c7c37d

Please sign in to comment.