diff options
author | kpdecker <kpdecker@gmail.com> | 2011-07-29 20:53:47 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2011-07-29 20:53:47 -0500 |
commit | a927125909825a3fd9e696ac37f01b2e7fdf5560 (patch) | |
tree | fa13d2f54b4b2da88b383b4141aebe15aa9e1212 /lib/handlebars/compiler.js | |
parent | 9062cac3f0b62f6c3805c79fb7c3f5e07ca98462 (diff) | |
download | handlebars.js-a927125909825a3fd9e696ac37f01b2e7fdf5560.zip handlebars.js-a927125909825a3fd9e696ac37f01b2e7fdf5560.tar.gz handlebars.js-a927125909825a3fd9e696ac37f01b2e7fdf5560.tar.bz2 |
Can access context variables masked by helpers by scoping with 'this.'
Diffstat (limited to 'lib/handlebars/compiler.js')
-rw-r--r-- | lib/handlebars/compiler.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/handlebars/compiler.js b/lib/handlebars/compiler.js index b8a9e04..843e0b9 100644 --- a/lib/handlebars/compiler.js +++ b/lib/handlebars/compiler.js @@ -26,7 +26,7 @@ Handlebars.JavaScriptCompiler = function() {}; Compiler.MULTI_PARAM_OPCODES = { appendContent: 1, getContext: 1, - lookupWithHelpers: 1, + lookupWithHelpers: 2, lookup: 1, invokeMustache: 2, pushString: 1, @@ -214,7 +214,7 @@ Handlebars.JavaScriptCompiler = function() {}; this.opcode('getContext', id.depth); - this.opcode('lookupWithHelpers', id.parts[0] || null); + this.opcode('lookupWithHelpers', id.parts[0] || null, id.isScoped || false); for(var i=1, l=id.parts.length; i<l; i++) { this.opcode('lookup', id.parts[i]); @@ -479,15 +479,22 @@ Handlebars.JavaScriptCompiler = function() {}; } }, - lookupWithHelpers: function(name) { + lookupWithHelpers: function(name, isScoped) { if(name) { var topStack = this.nextStack(); - var toPush = "if('" + name + "' in helpers) { " + topStack + + var lookupScoped = topStack + " = " + this.nameLookup('currentContext', name, 'context'), + toPush; + + if (isScoped) { + toPush = lookupScoped; + } else { + toPush = "if('" + name + "' in helpers) { " + topStack + " = " + this.nameLookup('helpers', name, 'helper') + - "; } else { " + topStack + " = " + - this.nameLookup('currentContext', name, 'context') + + "; } else { " + + lookupScoped + "; }"; + } this.source.push(toPush); } else { |