diff options
author | kpdecker <kpdecker@gmail.com> | 2014-08-13 11:41:27 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-08-13 11:41:27 -0500 |
commit | f6dc5ad7163b8b7c51d9816afa39741f47313602 (patch) | |
tree | fd4be6bd57495d20c42cf0113757565c5708bbc4 /lib/handlebars/compiler/javascript-compiler.js | |
parent | 867322adf28a2babfa22c46558d388091b5756e8 (diff) | |
download | handlebars.js-f6dc5ad7163b8b7c51d9816afa39741f47313602.zip handlebars.js-f6dc5ad7163b8b7c51d9816afa39741f47313602.tar.gz handlebars.js-f6dc5ad7163b8b7c51d9816afa39741f47313602.tar.bz2 |
Create contextName helper for context lookup
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r-- | lib/handlebars/compiler/javascript-compiler.js | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index c92cf58..0472dbb 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -230,7 +230,7 @@ JavaScriptCompiler.prototype = { blockValue: function(name) { this.aliases.blockHelperMissing = 'helpers.blockHelperMissing'; - var params = ["depth0"]; + var params = [this.contextName(0)]; this.setupParams(name, 0, params); this.replaceStack(function(current) { @@ -249,7 +249,7 @@ JavaScriptCompiler.prototype = { this.aliases.blockHelperMissing = 'helpers.blockHelperMissing'; // We're being a bit cheeky and reusing the options value from the prior exec - var params = ["depth0"]; + var params = [this.contextName(0)]; this.setupParams('', 0, params, true); this.flushInline(); @@ -341,7 +341,7 @@ JavaScriptCompiler.prototype = { // // Pushes the value of the current context onto the stack. pushContext: function() { - this.pushStackLiteral('depth' + this.lastContext); + this.pushStackLiteral(this.contextName(this.lastContext)); }, // [lookupOnContext] @@ -410,7 +410,7 @@ JavaScriptCompiler.prototype = { resolvePossibleLambda: function() { this.aliases.lambda = 'this.lambda'; - this.push('lambda(' + this.popStack() + ', depth0)'); + this.push('lambda(' + this.popStack() + ', ' + this.contextName(0) + ')'); }, // [pushStringParam] @@ -422,8 +422,7 @@ JavaScriptCompiler.prototype = { // provides the string value of a parameter along with its // depth rather than resolving it immediately. pushStringParam: function(string, type) { - this.pushStackLiteral('depth' + this.lastContext); - + this.pushContext(); this.pushString(type); // If it's a subexpression, the string result @@ -847,6 +846,10 @@ JavaScriptCompiler.prototype = { } }, + contextName: function(context) { + return 'depth' + context; + }, + quotedString: function(str) { return '"' + str .replace(/\\/g, '\\\\') @@ -878,7 +881,7 @@ JavaScriptCompiler.prototype = { params: params, paramsInit: paramsInit, name: foundHelper, - callParams: ["depth0"].concat(params).join(", ") + callParams: [this.contextName(0)].concat(params).join(", ") }; }, |