Updated the path parsing in lookupFor to be a bit smarter and added parse errors for some of the more tricky ones.

This commit is contained in:
Alan Johnson
2010-08-03 23:26:40 -04:00
parent 327744afaf
commit 4569684998
2 changed files with 9 additions and 4 deletions
+1 -1
View File
@@ -106,7 +106,7 @@ Handlebars.Compiler.prototype = {
}
break;
case ".":
throw new HandleBars.ParseError("'.' is not supported in path expressions.")
// do nothing - using .'s is pretty dumb, but it's also basically free for us to support
break;
default:
readDepth = true;
+8 -3
View File
@@ -31,8 +31,7 @@ test("nested paths", function() {
"Goodbye beautiful world!", "Nested paths access nested objects");
});
test("dumb nested paths", function() {
var string = "{{#goodbyes}}{{../name/../name}}{{/goodbyes}}";
test("bad idea nested paths", function() {
var caught = false;
try {
Handlebars.compile("{{#goodbyes}}{{../name/../name}}{{/goodbyes}}");
@@ -41,9 +40,14 @@ test("dumb nested paths", function() {
caught = true;
}
}
equals(caught, true, "Jumping out of context (..) doesn't work after moving into context.");
equals(caught, true, "Cannot jump (..) into previous context after moving into context.");
var string = "{{#goodbyes}}{{.././world}} {{/goodbyes}}";
var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};
shouldCompileTo(string, hash, "world world world ", "Same context (.) is ignored in paths");
});
module("blocks");
test("array", function() {
@@ -54,6 +58,7 @@ test("array", function() {
shouldCompileTo(string, {goodbyes: [], world: "world"}, "cruel world!",
"Arrays ignore the contents when empty");
});
test("nested iteration", function() {