summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2013-05-27 19:47:17 -0400
committerkpdecker <kpdecker@gmail.com>2013-05-27 19:47:17 -0400
commit503e32208bcc9e9f5d9052b4a7e732bf707be15e (patch)
tree00d071f21db925e8685915882a4b78bf6a4a4fcb
parent15186dc9ddfcce7d83a2284b065ddf0bb2cf4657 (diff)
downloadhandlebars.js-503e32208bcc9e9f5d9052b4a7e732bf707be15e.zip
handlebars.js-503e32208bcc9e9f5d9052b4a7e732bf707be15e.tar.gz
handlebars.js-503e32208bcc9e9f5d9052b4a7e732bf707be15e.tar.bz2
Improve tracking of original path values
-rw-r--r--dist/handlebars.js23
-rw-r--r--lib/handlebars/compiler/ast.js19
-rw-r--r--src/handlebars.yy4
3 files changed, 28 insertions, 18 deletions
diff --git a/dist/handlebars.js b/dist/handlebars.js
index cb3d8a9..56b6fea 100644
--- a/dist/handlebars.js
+++ b/dist/handlebars.js
@@ -280,9 +280,9 @@ case 45: this.$ = new yy.DataNode($$[$0]);
break;
case 46: this.$ = new yy.IdNode($$[$0]);
break;
-case 47: $$[$0-2].push($$[$0]); this.$ = $$[$0-2];
+case 47: $$[$0-2].push({part: $$[$0], separator: $$[$0-1]}); this.$ = $$[$0-2];
break;
-case 48: this.$ = [$$[$0]];
+case 48: this.$ = [{part: $$[$0]}];
break;
}
},
@@ -733,21 +733,24 @@ Handlebars.AST.HashNode = function(pairs) {
Handlebars.AST.IdNode = function(parts) {
this.type = "ID";
- this.original = parts.join(".");
- var dig = [], depth = 0;
+ var original = "",
+ dig = [],
+ depth = 0;
for(var i=0,l=parts.length; i<l; i++) {
- var part = parts[i];
+ var part = parts[i].part;
+ original += (parts[i].separator || '') + part;
if (part === ".." || part === "." || part === "this") {
- if (dig.length > 0) { throw new Handlebars.Exception("Invalid path: " + this.original); }
+ if (dig.length > 0) { throw new Handlebars.Exception("Invalid path: " + original); }
else if (part === "..") { depth++; }
else { this.isScoped = true; }
}
else { dig.push(part); }
}
+ this.original = original;
this.parts = dig;
this.string = dig.join('.');
this.depth = depth;
@@ -771,13 +774,15 @@ Handlebars.AST.DataNode = function(id) {
Handlebars.AST.StringNode = function(string) {
this.type = "STRING";
- this.string = string;
- this.stringModeValue = string;
+ this.original =
+ this.string =
+ this.stringModeValue = string;
};
Handlebars.AST.IntegerNode = function(integer) {
this.type = "INTEGER";
- this.integer = integer;
+ this.original =
+ this.integer = integer;
this.stringModeValue = Number(integer);
};
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js
index 850c605..c178960 100644
--- a/lib/handlebars/compiler/ast.js
+++ b/lib/handlebars/compiler/ast.js
@@ -67,21 +67,24 @@ Handlebars.AST.HashNode = function(pairs) {
Handlebars.AST.IdNode = function(parts) {
this.type = "ID";
- this.original = parts.join(".");
- var dig = [], depth = 0;
+ var original = "",
+ dig = [],
+ depth = 0;
for(var i=0,l=parts.length; i<l; i++) {
- var part = parts[i];
+ var part = parts[i].part;
+ original += (parts[i].separator || '') + part;
if (part === ".." || part === "." || part === "this") {
- if (dig.length > 0) { throw new Handlebars.Exception("Invalid path: " + this.original); }
+ if (dig.length > 0) { throw new Handlebars.Exception("Invalid path: " + original); }
else if (part === "..") { depth++; }
else { this.isScoped = true; }
}
else { dig.push(part); }
}
+ this.original = original;
this.parts = dig;
this.string = dig.join('.');
this.depth = depth;
@@ -105,13 +108,15 @@ Handlebars.AST.DataNode = function(id) {
Handlebars.AST.StringNode = function(string) {
this.type = "STRING";
- this.string = string;
- this.stringModeValue = string;
+ this.original =
+ this.string =
+ this.stringModeValue = string;
};
Handlebars.AST.IntegerNode = function(integer) {
this.type = "INTEGER";
- this.integer = integer;
+ this.original =
+ this.integer = integer;
this.stringModeValue = Number(integer);
};
diff --git a/src/handlebars.yy b/src/handlebars.yy
index 7e6321f..4e3a826 100644
--- a/src/handlebars.yy
+++ b/src/handlebars.yy
@@ -107,7 +107,7 @@ path
;
pathSegments
- : pathSegments SEP ID { $1.push($3); $$ = $1; }
- | ID { $$ = [$1]; }
+ : pathSegments SEP ID { $1.push({part: $3, separator: $2}); $$ = $1; }
+ | ID { $$ = [{part: $1}]; }
;