diff options
author | kpdecker <kpdecker@gmail.com> | 2011-07-31 17:17:14 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2011-07-31 17:17:14 -0500 |
commit | 1a88356dc3ec86376392405b23f3cba1eaff8f73 (patch) | |
tree | 70b1c4813b20a0991589b9a79f89fb76386562cc /lib/handlebars/compiler/compiler.js | |
parent | 5d4b549dc3209c0230d7d4d16c0fca0ea5b153c7 (diff) | |
download | handlebars.js-1a88356dc3ec86376392405b23f3cba1eaff8f73.zip handlebars.js-1a88356dc3ec86376392405b23f3cba1eaff8f73.tar.gz handlebars.js-1a88356dc3ec86376392405b23f3cba1eaff8f73.tar.bz2 |
Access context objects directly rather than using currentContext var.
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 4a60c05..26df606 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -186,7 +186,7 @@ Handlebars.JavaScriptCompiler = function() {}; if(partial.context) { this.ID(partial.context); } else { - this.opcode('push', 'context'); + this.opcode('push', 'depth0'); } this.opcode('invokePartial', id.original); @@ -390,7 +390,7 @@ Handlebars.JavaScriptCompiler = function() {}; out.push(''); } - out.push("var buffer = " + this.initializeBuffer() + ", currentContext = context"); + out.push("var buffer = " + this.initializeBuffer()); // track the last context pushed into place to allow skipping the // getContext opcode when it would be a noop @@ -425,7 +425,7 @@ Handlebars.JavaScriptCompiler = function() {}; this.source.push("return buffer;"); - var params = this.isChild ? ["context", "data"] : ["Handlebars", "context", "helpers", "partials", "data"]; + var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"]; for(var i=0, l=this.environment.depths.list.length; i<l; i++) { params.push("depth" + this.environment.depths.list[i]); @@ -468,12 +468,6 @@ Handlebars.JavaScriptCompiler = function() {}; getContext: function(depth) { if(this.lastContext !== depth) { this.lastContext = depth; - - if(depth === 0) { - this.source.push("currentContext = context;"); - } else { - this.source.push("currentContext = depth" + depth + ";"); - } } }, @@ -484,17 +478,17 @@ Handlebars.JavaScriptCompiler = function() {}; var toPush; if (isScoped) { - toPush = topStack + " = " + this.nameLookup('currentContext', name, 'context'); + toPush = topStack + " = " + this.nameLookup('depth' + this.lastContext, name, 'context'); } else { toPush = topStack + " = " + this.nameLookup('helpers', name, 'helper') + " || " - + this.nameLookup('currentContext', name, 'context'); + + this.nameLookup('depth' + this.lastContext, name, 'context'); } this.source.push(toPush); } else { - this.pushStack("currentContext"); + this.pushStack('depth' + this.lastContext); } }, @@ -504,7 +498,7 @@ Handlebars.JavaScriptCompiler = function() {}; }, pushStringParam: function(string) { - this.pushStack("currentContext"); + this.pushStack('depth' + this.lastContext); this.pushString(string); }, @@ -572,8 +566,8 @@ Handlebars.JavaScriptCompiler = function() {}; }, populateCall: function(params, id, helperId, fn) { - var paramString = ["context"].concat(params).join(", "); - var helperMissingString = ["context"].concat(helperId).concat(params).join(", "); + var paramString = ["depth0"].concat(params).join(", "); + var helperMissingString = ["depth0"].concat(helperId).concat(params).join(", "); var nextStack = this.nextStack(); @@ -622,7 +616,7 @@ Handlebars.JavaScriptCompiler = function() {}; for(var i=0, l = depths.length; i<l; i++) { depth = depths[i]; - if(depth === 1) { programParams.push("context"); } + if(depth === 1) { programParams.push("depth0"); } else { programParams.push("depth" + (depth - 1)); } } |