Allow replaceStack to work with the inline stack
This commit is contained in:
@@ -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);
|
||||
|
||||
// Prevent modification of the context depth variable. Through replaceStack
|
||||
if (/^depth/.test(stack)) {
|
||||
stack = this.nextStack();
|
||||
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();
|
||||
|
||||
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;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user