Fix evaluation of paths and subexprs

Fixes #743
This commit is contained in:
kpdecker
2014-03-05 17:49:39 -06:00
parent 058c0fb6ba
commit 55782f08c5
3 changed files with 25 additions and 8 deletions
+1 -3
View File
@@ -372,9 +372,7 @@ Compiler.prototype = {
},
pushParams: function(params) {
var i = params.length;
while(i--) {
for(var i=0, l=params.length; i<l; i++) {
this.pushParam(params[i]);
}
},
@@ -915,16 +915,19 @@ JavaScriptCompiler.prototype = {
options.inverse = inverse;
}
for (var i = 0; i < paramSize; i++) {
// The parameters go on to the stack in order (making sure that they are evaluated in order)
// so we need to pop them off the stack in reverse order
var i = paramSize;
while (i--) {
param = this.popStack();
params.push(param);
params[i] = param;
if (this.trackIds) {
ids.push(this.popStack());
ids[i] = this.popStack();
}
if (this.stringParams) {
types.push(this.popStack());
contexts.push(this.popStack());
types[i] = this.popStack();
contexts[i] = this.popStack();
}
}
+16
View File
@@ -29,6 +29,22 @@ describe('subexpressions', function() {
shouldCompileTo(string, [context, helpers], "val is true");
});
it("mixed paths and helpers", function() {
var string = '{{blog baz.bat (equal a b) baz.bar}}';
var context = { bar: "LOL", baz: {bat: 'foo!', bar: 'bar!'} };
var helpers = {
blog: function(val, that, theOther) {
console.log(arguments);
return "val is " + val + ', ' + that + ' and ' + theOther;
},
equal: function(x, y) {
return x === y;
}
};
shouldCompileTo(string, [context, helpers], "val is foo!, true and bar!");
});
it("supports much nesting", function() {
var string = '{{blog (equal (equal true true) true)}}';