Move aliases and registers into context object.
This commit is contained in:
@@ -319,12 +319,15 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
this.environment = environment;
|
||||
this.options = options || {};
|
||||
|
||||
this.context = {
|
||||
aliases: {},
|
||||
registers: {list: []}
|
||||
};
|
||||
|
||||
this.preamble();
|
||||
|
||||
this.stackSlot = 0;
|
||||
this.stackVars = [];
|
||||
this.aliases = {};
|
||||
this.registers = {list: []};
|
||||
|
||||
this.compileChildren(environment, options, asObject);
|
||||
|
||||
@@ -380,7 +383,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
if(this.environment.usePartial) { copies = copies + " partials = partials || Handlebars.partials;"; }
|
||||
out.push(copies);
|
||||
|
||||
out.push("var buffer = " + this.initializeBuffer() + ", currentContext = context, execRef");
|
||||
out.push("var buffer = " + this.initializeBuffer() + ", currentContext = context");
|
||||
|
||||
// track the last context pushed into place to allow skipping the
|
||||
// getContext opcode when it would be a noop
|
||||
@@ -389,7 +392,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
},
|
||||
|
||||
createFunctionContext: function(asObject) {
|
||||
var locals = this.stackVars.concat(this.registers.list);
|
||||
var locals = this.stackVars.concat(this.context.registers.list);
|
||||
|
||||
if(locals.length > 0) {
|
||||
this.source[1] = this.source[1] + ", " + locals.join(", ");
|
||||
@@ -397,8 +400,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
// Generate minimizer alias mappings
|
||||
var aliases = []
|
||||
for (var alias in this.aliases) {
|
||||
this.source[1] = this.source[1] + ', ' + alias + '=' + this.aliases[alias];
|
||||
for (var alias in this.context.aliases) {
|
||||
this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias];
|
||||
}
|
||||
|
||||
this.source[1] = this.source[1] + ";";
|
||||
@@ -450,7 +453,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
appendEscaped: function() {
|
||||
var opcode = this.nextOpcode(1), extra = "";
|
||||
this.aliases.escapeExpression = 'this.escapeExpression';
|
||||
this.context.aliases.escapeExpression = 'this.escapeExpression';
|
||||
|
||||
if(opcode[0] === 'appendContent') {
|
||||
extra = " + " + this.quotedString(opcode[1][0]);
|
||||
@@ -513,8 +516,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
invokeMustache: function(paramSize, original) {
|
||||
this.populateParams(paramSize, this.quotedString(original), "{}", null, function(nextStack, helperMissingString, id) {
|
||||
this.aliases.helperMissing = 'helpers.helperMissing';
|
||||
this.aliases.undef = 'void 0';
|
||||
this.context.aliases.helperMissing = 'helpers.helperMissing';
|
||||
this.context.aliases.undef = 'void 0';
|
||||
this.source.push("else if(" + id + "=== undef) { " + nextStack + " = helperMissing.call(" + helperMissingString + "); }");
|
||||
this.source.push("else { " + nextStack + " = " + id + "; }");
|
||||
});
|
||||
@@ -525,7 +528,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
var mainProgram = this.programExpression(guid);
|
||||
|
||||
this.populateParams(paramSize, null, mainProgram, inverse, function(nextStack, helperMissingString, id) {
|
||||
this.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
|
||||
this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
|
||||
this.source.push("else { " + nextStack + " = blockHelperMissing.call(" + helperMissingString + "); }");
|
||||
});
|
||||
},
|
||||
@@ -572,7 +575,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
var nextStack = this.nextStack();
|
||||
|
||||
this.aliases.functionType = '"function"';
|
||||
this.context.aliases.functionType = '"function"';
|
||||
this.source.push("if(typeof " + id + " === functionType) { " + nextStack + " = " + id + ".call(" + paramString + "); }");
|
||||
fn.call(this, nextStack, helperMissingString, id);
|
||||
},
|
||||
@@ -645,9 +648,9 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
},
|
||||
|
||||
useRegister: function(name) {
|
||||
if(!this.registers[name]) {
|
||||
this.registers[name] = true;
|
||||
this.registers.list.push(name);
|
||||
if(!this.context.registers[name]) {
|
||||
this.context.registers[name] = true;
|
||||
this.context.registers.list.push(name);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user