diff options
author | kpdecker <kpdecker@gmail.com> | 2013-01-19 18:21:05 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2013-01-19 18:21:05 -0600 |
commit | e9ac494ffd76c9d3a4312a595c271c2ffe662d74 (patch) | |
tree | ac64ced1cb2756f9bd0712fc23c82b534b4da597 /lib/handlebars/compiler/compiler.js | |
parent | cb50caaf5336c43310ebfebaa38695b9fce6bfb7 (diff) | |
download | handlebars.js-e9ac494ffd76c9d3a4312a595c271c2ffe662d74.zip handlebars.js-e9ac494ffd76c9d3a4312a595c271c2ffe662d74.tar.gz handlebars.js-e9ac494ffd76c9d3a4312a595c271c2ffe662d74.tar.bz2 |
Allow replaceStack to work with the inline stack
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 43 |
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; }, |