exports.attach = function(Handlebars) { // BEGIN(BROWSER) Handlebars.AST = {}; Handlebars.AST.ProgramNode = function(statements, inverse) { this.type = "program"; this.statements = statements; if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); } }; Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) { this.type = "mustache"; this.escaped = !unescaped; this.hash = hash; var id = this.id = rawParams[0]; var params = this.params = rawParams.slice(1); // a mustache is an eligible helper if: // * its id is simple (a single part, not `this` or `..`) var eligibleHelper = this.eligibleHelper = id.isSimple; // 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(id, context) { this.type = "partial"; // TODO: disallow complex IDs this.id = id; 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, inverse, close) { verifyMatch(mustache.id, close); this.type = "block"; this.mustache = mustache; this.program = program; this.inverse = inverse; if (this.inverse && !this.program) { this.isInverse = true; } }; Handlebars.AST.ContentNode = function(string) { this.type = "content"; this.string = string; }; Handlebars.AST.HashNode = function(pairs) { this.type = "hash"; this.pairs = pairs; }; Handlebars.AST.IdNode = function(parts) { this.type = "ID"; this.original = parts.join("."); var dig = [], depth = 0; for(var i=0,l=parts.length; i