diff --git a/lib/handlebars/compiler/visitor.js b/lib/handlebars/compiler/visitor.js index 6a0373e19..a4eb2b44b 100644 --- a/lib/handlebars/compiler/visitor.js +++ b/lib/handlebars/compiler/visitor.js @@ -4,8 +4,64 @@ Visitor.prototype = { constructor: Visitor, accept: function(object) { - return this[object.type](object); - } + return object && this[object.type] && this[object.type](object); + }, + + program: function(program) { + var statements = program.statements, + i, l; + + for(i=0, l=statements.length; i bar }} {{/foo}}')); + }); + + it('should traverse to stubs', function() { + var visitor = new Handlebars.Visitor(); + + visitor.PARTIAL_NAME = function(partialName) { + equal(partialName.name, 'bar'); + }; + + visitor.STRING = function(string) { + equal(string.string, '2'); + }; + visitor.NUMBER = function(number) { + equal(number.stringModeValue, 1); + }; + visitor.BOOLEAN = function(bool) { + equal(bool.stringModeValue, true); + }; + visitor.ID = function(id) { + equal(id.original, 'foo.bar'); + }; + visitor.content = function(content) { + equal(content.string, ' '); + }; + visitor.comment = function(comment) { + equal(comment.comment, 'comment'); + }; + + visitor.accept(Handlebars.parse('{{#foo.bar (foo.bar 1 "2" true) foo=@foo.bar}}{{!comment}}{{> bar }} {{/foo.bar}}')); + }); +});