Skip to content

Commit

Permalink
Fix evaluation of paths and subexprs
Browse files Browse the repository at this point in the history
Fixes #743
  • Loading branch information
kpdecker committed Mar 5, 2014
1 parent 058c0fb commit 55782f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/handlebars/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
},
Expand Down
13 changes: 8 additions & 5 deletions lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
16 changes: 16 additions & 0 deletions spec/subexpressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}}';

Expand Down

0 comments on commit 55782f0

Please sign in to comment.