summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-03-05 17:49:39 -0600
committerkpdecker <kpdecker@gmail.com>2014-03-05 17:49:39 -0600
commit55782f08c58e0ee0902545d77b79e89fe11ae840 (patch)
treed35bb57a458d39f119752b40e6022fb9f5ec0f16
parent058c0fb6ba67acb06eb64a2385904da0972ccac8 (diff)
downloadhandlebars.js-55782f08c58e0ee0902545d77b79e89fe11ae840.zip
handlebars.js-55782f08c58e0ee0902545d77b79e89fe11ae840.tar.gz
handlebars.js-55782f08c58e0ee0902545d77b79e89fe11ae840.tar.bz2
Fix evaluation of paths and subexprs
Fixes #743
-rw-r--r--lib/handlebars/compiler/compiler.js4
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js13
-rw-r--r--spec/subexpressions.js16
3 files changed, 25 insertions, 8 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 99d6f4f..c702d00 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -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]);
}
},
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index 514dfcc..8bb5da6 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -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();
}
}
diff --git a/spec/subexpressions.js b/spec/subexpressions.js
index ab2bc32..dee3b16 100644
--- a/spec/subexpressions.js
+++ b/spec/subexpressions.js
@@ -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)}}';