Inline stack helper implementation
This commit is contained in:
@@ -419,6 +419,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
this.stackVars = [];
|
||||
this.registers = { list: [] };
|
||||
this.compileStack = [];
|
||||
this.inlineStack = [];
|
||||
|
||||
this.compileChildren(environment, options);
|
||||
|
||||
@@ -917,11 +918,20 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
return item;
|
||||
},
|
||||
|
||||
pushStack: function(item) {
|
||||
var stack = this.incrStack();
|
||||
this.source.push(stack + " = " + item + ";");
|
||||
this.compileStack.push(stack);
|
||||
return stack;
|
||||
pushStack: function(item, inline) {
|
||||
if (inline) {
|
||||
this.inlineStack.push(item);
|
||||
return item;
|
||||
} else {
|
||||
this.flushInline();
|
||||
|
||||
var stack = this.incrStack();
|
||||
if (item) {
|
||||
this.source.push(stack + " = " + item + ";");
|
||||
}
|
||||
this.compileStack.push(stack);
|
||||
return stack;
|
||||
}
|
||||
},
|
||||
|
||||
replaceStack: function(callback) {
|
||||
@@ -937,33 +947,55 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
return stack;
|
||||
},
|
||||
|
||||
nextStack: function(skipCompileStack) {
|
||||
var name = this.incrStack();
|
||||
this.compileStack.push(name);
|
||||
return name;
|
||||
nextStack: function() {
|
||||
return this.pushStack();
|
||||
},
|
||||
|
||||
incrStack: function() {
|
||||
this.stackSlot++;
|
||||
if(this.stackSlot > this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); }
|
||||
return this.topStackName();
|
||||
},
|
||||
topStackName: function() {
|
||||
return "stack" + this.stackSlot;
|
||||
},
|
||||
flushInline: function() {
|
||||
var inlineStack = this.inlineStack;
|
||||
if (inlineStack.length) {
|
||||
this.inlineStack = [];
|
||||
for (var i = 0, len = inlineStack.length; i < len; i++) {
|
||||
var entry = inlineStack[i];
|
||||
if (entry instanceof Literal) {
|
||||
this.compileStack.push(entry);
|
||||
} else {
|
||||
this.pushStack(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
isInline: function() {
|
||||
return this.inlineStack.length;
|
||||
},
|
||||
|
||||
popStack: function() {
|
||||
var item = this.compileStack.pop();
|
||||
popStack: function(wrapped) {
|
||||
var inline = this.isInline(),
|
||||
item = (inline ? this.inlineStack : this.compileStack).pop();
|
||||
|
||||
if (item instanceof Literal) {
|
||||
if (!wrapped && (item instanceof Literal)) {
|
||||
return item.value;
|
||||
} else {
|
||||
this.stackSlot--;
|
||||
if (!inline) {
|
||||
this.stackSlot--;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
},
|
||||
|
||||
topStack: function() {
|
||||
var item = this.compileStack[this.compileStack.length - 1];
|
||||
topStack: function(wrapped) {
|
||||
var stack = (this.isInline() ? this.inlineStack : this.compileStack),
|
||||
item = stack[stack.length - 1];
|
||||
|
||||
if (item instanceof Literal) {
|
||||
if (!wrapped && (item instanceof Literal)) {
|
||||
return item.value;
|
||||
} else {
|
||||
return item;
|
||||
|
||||
Reference in New Issue
Block a user