Minimizable id aliases.
This commit is contained in:
@@ -323,6 +323,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
this.stackSlot = 0;
|
||||
this.stackVars = [];
|
||||
this.aliases = {};
|
||||
this.registers = {list: []};
|
||||
|
||||
this.compileChildren(environment, options, asObject);
|
||||
@@ -374,12 +375,13 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
preamble: function() {
|
||||
var out = [];
|
||||
out.push("var buffer = " + this.initializeBuffer() + ", currentContext = context");
|
||||
|
||||
var copies = "helpers = helpers || Handlebars.helpers;";
|
||||
if(this.environment.usePartial) { copies = copies + " partials = partials || Handlebars.partials;"; }
|
||||
out.push(copies);
|
||||
|
||||
out.push("var buffer = " + this.initializeBuffer() + ", currentContext = context, execRef");
|
||||
|
||||
// track the last context pushed into place to allow skipping the
|
||||
// getContext opcode when it would be a noop
|
||||
this.lastContext = 0;
|
||||
@@ -390,10 +392,16 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
var locals = this.stackVars.concat(this.registers.list);
|
||||
|
||||
if(locals.length > 0) {
|
||||
this.source[0] = this.source[0] + ", " + locals.join(", ");
|
||||
this.source[1] = this.source[1] + ", " + locals.join(", ");
|
||||
}
|
||||
|
||||
this.source[0] = this.source[0] + ";";
|
||||
// Generate minimizer alias mappings
|
||||
var aliases = []
|
||||
for (var alias in this.aliases) {
|
||||
this.source[1] = this.source[1] + ', ' + alias + '=' + this.aliases[alias];
|
||||
}
|
||||
|
||||
this.source[1] = this.source[1] + ";";
|
||||
|
||||
this.source.push("return buffer;");
|
||||
|
||||
@@ -442,13 +450,14 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
appendEscaped: function() {
|
||||
var opcode = this.nextOpcode(1), extra = "";
|
||||
this.aliases.escapeExpression = 'this.escapeExpression';
|
||||
|
||||
if(opcode[0] === 'appendContent') {
|
||||
extra = " + " + this.quotedString(opcode[1][0]);
|
||||
this.eat(opcode);
|
||||
}
|
||||
|
||||
this.source.push(this.appendToBuffer("this.escapeExpression(" + this.popStack() + ")" + extra));
|
||||
this.source.push(this.appendToBuffer("escapeExpression(" + this.popStack() + ")" + extra));
|
||||
},
|
||||
|
||||
getContext: function(depth) {
|
||||
@@ -506,7 +515,9 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
invokeMustache: function(paramSize, original) {
|
||||
this.populateParams(paramSize, this.quotedString(original), "{}", null, function(nextStack, helperMissingString, id) {
|
||||
this.source.push("else if(" + id + "=== undefined) { " + nextStack + " = helpers.helperMissing.call(" + helperMissingString + "); }");
|
||||
this.aliases.helperMissing = 'helpers.helperMissing';
|
||||
this.aliases.undef = 'void 0';
|
||||
this.source.push("else if(" + id + "=== undef) { " + nextStack + " = helperMissing.call(" + helperMissingString + "); }");
|
||||
this.source.push("else { " + nextStack + " = " + id + "; }");
|
||||
});
|
||||
},
|
||||
@@ -516,7 +527,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
var mainProgram = this.programExpression(guid);
|
||||
|
||||
this.populateParams(paramSize, null, mainProgram, inverse, function(nextStack, helperMissingString, id) {
|
||||
this.source.push("else { " + nextStack + " = helpers.blockHelperMissing.call(" + helperMissingString + "); }");
|
||||
this.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
|
||||
this.source.push("else { " + nextStack + " = blockHelperMissing.call(" + helperMissingString + "); }");
|
||||
});
|
||||
},
|
||||
|
||||
@@ -562,7 +574,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
var nextStack = this.nextStack();
|
||||
|
||||
this.source.push("if(typeof " + id + " === 'function') { " + nextStack + " = " + id + ".call(" + paramString + "); }");
|
||||
this.aliases.functionType = '"function"';
|
||||
this.source.push("if(typeof " + id + " === functionType) { " + nextStack + " = " + id + ".call(" + paramString + "); }");
|
||||
fn.call(this, nextStack, helperMissingString, id);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user