summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/javascript-compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2013-07-29 23:51:05 -0500
committerkpdecker <kpdecker@gmail.com>2013-10-14 22:50:49 -0500
commit4cf49732a232c64b752097e8ef3f0faf1fa574ed (patch)
tree359cdf7deaa16e52ac090c72abd92337bc4bb8a2 /lib/handlebars/compiler/javascript-compiler.js
parent0cc6e270f971f6ad7e916bfab82e889419affa27 (diff)
downloadhandlebars.js-4cf49732a232c64b752097e8ef3f0faf1fa574ed.zip
handlebars.js-4cf49732a232c64b752097e8ef3f0faf1fa574ed.tar.gz
handlebars.js-4cf49732a232c64b752097e8ef3f0faf1fa574ed.tar.bz2
Push Source helper method
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index 283c20c..e3eddd9 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -141,7 +141,7 @@ JavaScriptCompiler.prototype = {
}
if (!this.environment.isSimple) {
- this.source.push("return buffer;");
+ this.pushSource("return buffer;");
}
var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"];
@@ -232,7 +232,7 @@ JavaScriptCompiler.prototype = {
// Use the options value generated from the invocation
params[params.length-1] = 'options';
- this.source.push("if (!" + this.lastHelper + ") { " + current + " = blockHelperMissing.call(" + params.join(", ") + "); }");
+ this.pushSource("if (!" + this.lastHelper + ") { " + current + " = blockHelperMissing.call(" + params.join(", ") + "); }");
},
// [appendContent]
@@ -242,7 +242,7 @@ JavaScriptCompiler.prototype = {
//
// Appends the string value of `content` to the current buffer
appendContent: function(content) {
- this.source.push(this.appendToBuffer(this.quotedString(content)));
+ this.pushSource(this.appendToBuffer(this.quotedString(content)));
},
// [append]
@@ -259,9 +259,9 @@ JavaScriptCompiler.prototype = {
// when we examine local
this.flushInline();
var local = this.popStack();
- this.source.push("if(" + local + " || " + local + " === 0) { " + this.appendToBuffer(local) + " }");
+ this.pushSource("if(" + local + " || " + local + " === 0) { " + this.appendToBuffer(local) + " }");
if (this.environment.isSimple) {
- this.source.push("else { " + this.appendToBuffer("''") + " }");
+ this.pushSource("else { " + this.appendToBuffer("''") + " }");
}
},
@@ -274,7 +274,7 @@ JavaScriptCompiler.prototype = {
appendEscaped: function() {
this.context.aliases.escapeExpression = 'this.escapeExpression';
- this.source.push(this.appendToBuffer("escapeExpression(" + this.popStack() + ")"));
+ this.pushSource(this.appendToBuffer("escapeExpression(" + this.popStack() + ")"));
},
// [getContext]
@@ -498,8 +498,8 @@ JavaScriptCompiler.prototype = {
var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context');
var nextStack = this.nextStack();
- this.source.push('if (' + nextStack + ' = ' + helperName + ') { ' + nextStack + ' = ' + nextStack + '.call(' + helper.callParams + '); }');
- this.source.push('else { ' + nextStack + ' = ' + nonHelper + '; ' + nextStack + ' = typeof ' + nextStack + ' === functionType ? ' + nextStack + '.call(' + helper.callParams + ') : ' + nextStack + '; }');
+ this.pushSource('if (' + nextStack + ' = ' + helperName + ') { ' + nextStack + ' = ' + nextStack + '.call(' + helper.callParams + '); }');
+ this.pushSource('else { ' + nextStack + ' = ' + nonHelper + '; ' + nextStack + ' = typeof ' + nextStack + ' === functionType ? ' + nextStack + '.call(' + helper.callParams + ') : ' + nextStack + '; }');
},
// [invokePartial]
@@ -606,7 +606,7 @@ JavaScriptCompiler.prototype = {
register: function(name, val) {
this.useRegister(name);
- this.source.push(name + " = " + val + ";");
+ this.pushSource(name + " = " + val + ";");
},
useRegister: function(name) {
@@ -620,12 +620,16 @@ JavaScriptCompiler.prototype = {
return this.push(new Literal(item));
},
+ pushSource: function(source) {
+ this.source.push(source);
+ },
+
pushStack: function(item) {
this.flushInline();
var stack = this.incrStack();
if (item) {
- this.source.push(stack + " = " + item + ";");
+ this.pushSource(stack + " = " + item + ";");
}
this.compileStack.push(stack);
return stack;
@@ -668,7 +672,7 @@ JavaScriptCompiler.prototype = {
stack = this.nextStack();
}
- this.source.push(stack + " = (" + prefix + item + ");");
+ this.pushSource(stack + " = (" + prefix + item + ");");
}
return stack;
},