summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js43
1 files changed, 35 insertions, 8 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 3405eab..f9bec39 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -933,18 +933,45 @@ Handlebars.JavaScriptCompiler = function() {};
}
},
- replaceStack: function(callback) {
- this.flushInline();
+ replaceStack: function(callback, allowInline) {
+ var prefix = '',
+ inline = this.isInline(),
+ stack;
- var stack = this.topStack(),
- item = callback.call(this, stack);
+ // 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);
+
+ if (top instanceof Literal) {
+ // Literals do not need to be inlined
+ stack = top.value;
+ } else {
+ // Get or create the current stack name for use by the inline
+ var name = allowInline && this.stackSlot ? this.topStackName() : this.incrStack();
- // Prevent modification of the context depth variable. Through replaceStack
- if (/^depth/.test(stack)) {
- stack = this.nextStack();
+ prefix = '(' + this.pushStack(name, true) + ' = ' + top + '),\n\t\t';
+ stack = this.topStack();
+ }
+ } else {
+ stack = this.topStack();
}
- this.source.push(stack + " = " + item + ";");
+ var item = callback.call(this, stack);
+
+ if (inline && allowInline) {
+ if (this.inlineStack.length || this.compileStack.length) {
+ this.popStack();
+ }
+ this.pushStack('(' + prefix + item + ')', true);
+ } else {
+ // Prevent modification of the context depth variable. Through replaceStack
+ if (!/^stack/.test(stack)) {
+ stack = this.nextStack();
+ }
+
+ this.source.push(stack + " = (" + prefix + item + ");");
+ }
return stack;
},