summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/javascript-compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-08-23 07:43:09 -0500
committerkpdecker <kpdecker@gmail.com>2014-08-23 07:43:09 -0500
commit3531e041174509c6c3c69417b1714dcda6bccb3e (patch)
tree5157050d8b097936e2f60838a952db1d1ee69184 /lib/handlebars/compiler/javascript-compiler.js
parentc3fde1c01c7f51dafdc2886296fbe3d7471db0a1 (diff)
downloadhandlebars.js-3531e041174509c6c3c69417b1714dcda6bccb3e.zip
handlebars.js-3531e041174509c6c3c69417b1714dcda6bccb3e.tar.gz
handlebars.js-3531e041174509c6c3c69417b1714dcda6bccb3e.tar.bz2
Optimize replaceStack for inline methods
Only use case was with inline input so most of this code was unnecessary.
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js64
1 files changed, 24 insertions, 40 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index c02e023..25d45d1 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -731,9 +731,7 @@ JavaScriptCompiler.prototype = {
this.flushInline();
var stack = this.incrStack();
- if (item) {
- this.pushSource(stack + " = " + item + ";");
- }
+ this.pushSource(stack + " = " + item + ";");
this.compileStack.push(stack);
return stack;
},
@@ -745,54 +743,40 @@ JavaScriptCompiler.prototype = {
createdStack,
usedLiteral;
- // If we are currently inline then we want to merge the inline statement into the
- // replacement statement via ','
- if (inline) {
- var top = this.popStack(true);
+ /* istanbul ignore next */
+ if (!this.isInline()) {
+ throw new Exception('replaceStack on non-inline');
+ }
- if (top instanceof Literal) {
- // Literals do not need to be inlined
- stack = top.value;
- usedLiteral = true;
+ // We want to merge the inline statement into the replacement statement via ','
+ var top = this.popStack(true);
- if (chain) {
- prefix = stack;
- }
- } else {
- // Get or create the current stack name for use by the inline
- createdStack = !this.stackSlot;
- var name = !createdStack ? this.topStackName() : this.incrStack();
+ if (top instanceof Literal) {
+ // Literals do not need to be inlined
+ stack = top.value;
+ usedLiteral = true;
- prefix = '(' + this.push(name) + ' = ' + top + (chain ? ')' : '),');
- stack = this.topStack();
+ if (chain) {
+ prefix = stack;
}
} else {
+ // Get or create the current stack name for use by the inline
+ createdStack = !this.stackSlot;
+ var name = !createdStack ? this.topStackName() : this.incrStack();
+
+ prefix = '(' + this.push(name) + ' = ' + top + (chain ? ')' : '),');
stack = this.topStack();
}
var item = callback.call(this, stack);
- if (inline) {
- if (!usedLiteral) {
- this.popStack();
- }
- if (createdStack) {
- this.stackSlot--;
- }
- this.push('(' + prefix + item + ')');
- } else {
- // Prevent modification of the context depth variable. Through replaceStack
- if (!/^stack/.test(stack)) {
- stack = this.nextStack();
- }
-
- this.pushSource(stack + " = (" + prefix + item + ");");
+ if (!usedLiteral) {
+ this.popStack();
}
- return stack;
- },
-
- nextStack: function() {
- return this.pushStack();
+ if (createdStack) {
+ this.stackSlot--;
+ }
+ this.push('(' + prefix + item + ')');
},
incrStack: function() {