diff options
-rw-r--r-- | dist/handlebars.js | 3 | ||||
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 3 | ||||
-rw-r--r-- | spec/qunit_spec.js | 8 |
3 files changed, 12 insertions, 2 deletions
diff --git a/dist/handlebars.js b/dist/handlebars.js index a5f0bf7..418b804 100644 --- a/dist/handlebars.js +++ b/dist/handlebars.js @@ -1743,8 +1743,9 @@ JavaScriptCompiler.prototype = { this.context.aliases.helperMissing = 'helpers.helperMissing'; var helper = this.lastHelper = this.setupHelper(paramSize, name, true); + var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context'); - this.push(helper.name); + this.push(helper.name + ' || ' + nonHelper); this.replaceStack(function(name) { return name + ' ? ' + name + '.call(' + helper.callParams + ") " + ": helperMissing.call(" + diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 7777456..c003ce6 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -866,8 +866,9 @@ JavaScriptCompiler.prototype = { this.context.aliases.helperMissing = 'helpers.helperMissing'; var helper = this.lastHelper = this.setupHelper(paramSize, name, true); + var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context'); - this.push(helper.name); + this.push(helper.name + ' || ' + nonHelper); this.replaceStack(function(name) { return name + ' ? ' + name + '.call(' + helper.callParams + ") " + ": helperMissing.call(" + diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js index 317841f..14dbee7 100644 --- a/spec/qunit_spec.js +++ b/spec/qunit_spec.js @@ -165,6 +165,14 @@ test("functions", function() { "functions are bound to the context"); }); +test("functions with context argument", function() { + shouldCompileTo("{{awesome frank}}", + {awesome: function(context) { return context; }, + frank: "Frank"}, + "Frank", "functions are called with context arguments"); +}); + + test("paths with hyphens", function() { shouldCompileTo("{{foo-bar}}", {"foo-bar": "baz"}, "baz", "Paths can contain hyphens (-)"); shouldCompileTo("{{foo.foo-bar}}", {foo: {"foo-bar": "baz"}}, "baz", "Paths can contain hyphens (-)"); |