vendor/handlebars/lib/handlebars/compiler/ast.js in handlebars-0.3.2 vs vendor/handlebars/lib/handlebars/compiler/ast.js in handlebars-0.4.0
- old
+ new
@@ -9,45 +9,54 @@
this.type = "program";
this.statements = statements;
if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
};
- Handlebars.AST.MustacheNode = function(params, hash, unescaped) {
+ Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) {
this.type = "mustache";
- this.id = params[0];
- this.params = params.slice(1);
- this.hash = hash;
this.escaped = !unescaped;
- };
+ this.hash = hash;
- Handlebars.AST.PartialNode = function(id, context) {
- this.type = "partial";
+ var id = this.id = rawParams[0];
+ var params = this.params = rawParams.slice(1);
- // TODO: disallow complex IDs
+ // a mustache is an eligible helper if:
+ // * its id is simple (a single part, not `this` or `..`)
+ var eligibleHelper = this.eligibleHelper = id.isSimple;
- this.id = id;
- this.context = context;
+ // a mustache is definitely a helper if:
+ // * it is an eligible helper, and
+ // * it has at least one parameter or hash segment
+ this.isHelper = eligibleHelper && (params.length || hash);
+
+ // if a mustache is an eligible helper but not a definite
+ // helper, it is ambiguous, and will be resolved in a later
+ // pass or at runtime.
};
+ Handlebars.AST.PartialNode = function(partialName, context) {
+ this.type = "partial";
+ this.partialName = partialName;
+ this.context = context;
+ };
+
var verifyMatch = function(open, close) {
if(open.original !== close.original) {
throw new Handlebars.Exception(open.original + " doesn't match " + close.original);
}
};
- Handlebars.AST.BlockNode = function(mustache, program, close) {
+ Handlebars.AST.BlockNode = function(mustache, program, inverse, close) {
verifyMatch(mustache.id, close);
this.type = "block";
this.mustache = mustache;
this.program = program;
- };
+ this.inverse = inverse;
- Handlebars.AST.InverseNode = function(mustache, program, close) {
- verifyMatch(mustache.id, close);
- this.type = "inverse";
- this.mustache = mustache;
- this.program = program;
+ if (this.inverse && !this.program) {
+ this.isInverse = true;
+ }
};
Handlebars.AST.ContentNode = function(string) {
this.type = "content";
this.string = string;
@@ -65,33 +74,54 @@
var dig = [], depth = 0;
for(var i=0,l=parts.length; i<l; i++) {
var part = parts[i];
- if(part === "..") { depth++; }
- else if(part === "." || part === "this") { this.isScoped = true; }
+ if (part === ".." || part === "." || part === "this") {
+ if (dig.length > 0) { throw new Handlebars.Exception("Invalid path: " + this.original); }
+ else if (part === "..") { depth++; }
+ else { this.isScoped = true; }
+ }
else { dig.push(part); }
}
this.parts = dig;
this.string = dig.join('.');
this.depth = depth;
- this.isSimple = (dig.length === 1) && (depth === 0);
+
+ // an ID is simple if it only has one part, and that part is not
+ // `..` or `this`.
+ this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
+
+ this.stringModeValue = this.string;
};
+ Handlebars.AST.PartialNameNode = function(name) {
+ this.type = "PARTIAL_NAME";
+ this.name = name;
+ };
+
+ Handlebars.AST.DataNode = function(id) {
+ this.type = "DATA";
+ this.id = id;
+ };
+
Handlebars.AST.StringNode = function(string) {
this.type = "STRING";
this.string = string;
+ this.stringModeValue = string;
};
Handlebars.AST.IntegerNode = function(integer) {
this.type = "INTEGER";
this.integer = integer;
+ this.stringModeValue = Number(integer);
};
Handlebars.AST.BooleanNode = function(bool) {
this.type = "BOOLEAN";
this.bool = bool;
+ this.stringModeValue = bool === "true";
};
Handlebars.AST.CommentNode = function(comment) {
this.type = "comment";
this.comment = comment;