Access context objects directly rather than using currentContext var.
This commit is contained in:
@@ -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)); }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user