From d8825b1961857834ee0c3cec8b663bc9185f3028 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Mon, 30 Jul 2012 21:12:03 -0500 Subject: [PATCH 1/2] this parameter tests --- spec/qunit_spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js index aca8fcbc..9f2728e3 100644 --- a/spec/qunit_spec.js +++ b/spec/qunit_spec.js @@ -163,6 +163,20 @@ test("this keyword in paths", function() { shouldCompileTo(string, hash, "helloHelloHELLO", "This keyword evaluates in more complex paths"); }); +test("this keyword in helpers", function() { + var helpers = {foo: function(value, options) { + return 'bar ' + value; + }}; + var string = "{{#goodbyes}}{{foo this}}{{/goodbyes}}"; + var hash = {goodbyes: ["goodbye", "Goodbye", "GOODBYE"]}; + shouldCompileTo(string, [hash, helpers], "bar goodbyebar Goodbyebar GOODBYE", + "This keyword in paths evaluates to current context"); + + string = "{{#hellos}}{{foo this/text}}{{/hellos}}"; + hash = {hellos: [{text: "hello"}, {text: "Hello"}, {text: "HELLO"}]}; + shouldCompileTo(string, [hash, helpers], "bar hellobar Hellobar HELLO", "This keyword evaluates in more complex paths"); +}); + module("inverted sections"); test("inverted sections with unset value", function() { From 4ffe1b8e5a0871a9c3befe16825ddfad84d1f5c0 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Mon, 30 Jul 2012 21:40:25 -0500 Subject: [PATCH 2/2] Fix handling of this parameters in helpers Fixes issue introduced in 727eb26cb6a9e89ab08596dedbabcec0becb4d75 --- lib/handlebars/compiler/compiler.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index ca59725f..108d0551 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -240,7 +240,13 @@ Handlebars.JavaScriptCompiler = function() {}; ID: function(id) { this.addDepth(id.depth); this.opcode('getContext', id.depth); - this.opcode('lookupOnContext', id.parts[0]); + + var name = id.parts[0]; + if (!name) { + this.opcode('pushContext'); + } else { + this.opcode('lookupOnContext', id.parts[0]); + } for(var i=1, l=id.parts.length; i