summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2011-07-31 11:25:40 -0500
committerkpdecker <kpdecker@gmail.com>2011-07-31 11:25:40 -0500
commitc7e8ddd6b572e3b26c93708c7ff0fd1e08261054 (patch)
tree47302c14199f9028058efcbfebde7f6b97f44a95 /lib/handlebars/compiler/compiler.js
parent6fcebec713da4a792de24f663455ce3b32e00462 (diff)
downloadhandlebars.js-c7e8ddd6b572e3b26c93708c7ff0fd1e08261054.zip
handlebars.js-c7e8ddd6b572e3b26c93708c7ff0fd1e08261054.tar.gz
handlebars.js-c7e8ddd6b572e3b26c93708c7ff0fd1e08261054.tar.bz2
Minimizable id aliases.
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js27
1 files changed, 20 insertions, 7 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 639e7f2..d7ff3a7 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -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(", ");
+ }
+
+ // Generate minimizer alias mappings
+ var aliases = []
+ for (var alias in this.aliases) {
+ this.source[1] = this.source[1] + ', ' + alias + '=' + this.aliases[alias];
}
- this.source[0] = this.source[0] + ";";
+ 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);
},