diff options
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 { |