                 n.elements = @visitArray n.elements
                 n
 
+        visitObjectPattern: (n) ->
+                n.properties = @visitArray n.properties
+                n
+
         toString: () -> "TreeVisitor"

syntax = (require 'esprima').Syntax
debug = require 'debug'

_ArrayExpression = syntax.ArrayExpression
_ArrayPattern = syntax.ArrayPattern
_ArrowFunctionExpression = syntax.ArrowFunctionExpression
_AssignmentExpression = syntax.AssignmentExpression
_BinaryExpression = syntax.BinaryExpression
_BlockStatement = syntax.BlockStatement
_BreakStatement = syntax.BreakStatement
_CallExpression = syntax.CallExpression
_CatchClause = syntax.CatchClause
_ClassBody = syntax.ClassBody
_ClassDeclaration = syntax.ClassDeclaration
_ClassExpression = syntax.ClassExpression
_ClassHeritage = syntax.ClassHeritage
_ComprehensionBlock = syntax.ComprehensionBlock
_ComprehensionExpression = syntax.ComprehensionExpression
_ConditionalExpression = syntax.ConditionalExpression
_ContinueStatement = syntax.ContinueStatement
_DebuggerStatement = syntax.DebuggerStatement
_DoWhileStatement = syntax.DoWhileStatement
_EmptyStatement = syntax.EmptyStatement
_ExportDeclaration = syntax.ExportDeclaration
_ExportBatchSpecifier = syntax.ExportBatchSpecifier
_ExportSpecifier = syntax.ExportSpecifier
_ExpressionStatement = syntax.ExpressionStatement
_ForInStatement = syntax.ForInStatement
_ForOfStatement = syntax.ForOfStatement
_ForStatement = syntax.ForStatement
_FunctionDeclaration = syntax.FunctionDeclaration
_FunctionExpression = syntax.FunctionExpression
_Identifier = syntax.Identifier
_IfStatement = syntax.IfStatement
_ImportDeclaration = syntax.ImportDeclaration
_ImportSpecifier = syntax.ImportSpecifier
_LabeledStatement = syntax.LabeledStatement
_Literal = syntax.Literal
_LogicalExpression = syntax.LogicalExpression
_MemberExpression = syntax.MemberExpression
_MethodDefinition = syntax.MethodDefinition
_ModuleDeclaration = syntax.ModuleDeclaration
_NewExpression = syntax.NewExpression
_ObjectExpression = syntax.ObjectExpression
_ObjectPattern = syntax.ObjectPattern
_Program = syntax.Program
_Property = syntax.Property
_ReturnStatement = syntax.ReturnStatement
_SequenceExpression = syntax.SequenceExpression
_SpreadElement = syntax.SpreadElement
_SwitchCase = syntax.SwitchCase
_SwitchStatement = syntax.SwitchStatement
_TaggedTemplateExpression = syntax.TaggedTemplateExpression
_TemplateElement = syntax.TemplateElement
_TemplateLiteral = syntax.TemplateLiteral
_ThisExpression = syntax.ThisExpression
_ThrowStatement = syntax.ThrowStatement
_TryStatement = syntax.TryStatement
_UnaryExpression = syntax.UnaryExpression
_UpdateExpression = syntax.UpdateExpression
_VariableDeclaration = syntax.VariableDeclaration
_VariableDeclarator = syntax.VariableDeclarator
_WhileStatement = syntax.WhileStatement
_WithStatement = syntax.WithStatement
_YieldExpression = syntax.YieldExpression


exports.TreeVisitor = class TreeVisitor
        # for collections, returns all non-null.  for single item properties,

                #debug.log -> "#{n.type}>"
                
                switch n.type
                        when ArrayExpression         then rv = @visitArrayExpression n
                        when ArrayPattern            then rv = @visitArrayPattern n
                        when ArrowFunctionExpression then rv = @visitArrowFunctionExpression n
                        when AssignmentExpression    then rv = @visitAssignmentExpression n
                        when BinaryExpression        then rv = @visitBinaryExpression n
                        when BlockStatement          then rv = @visitBlock n
                        when BreakStatement          then rv = @visitBreak n
                        when CallExpression          then rv = @visitCallExpression n
                        when CatchClause             then rv = @visitCatchClause n
                        when ClassBody               then rv = @visitClassBody n
                        when ClassDeclaration        then rv = @visitClassDeclaration n
                        when ClassExpression         then throw new Error "Unhandled AST node type: #{n.type}"
                        when ClassHeritage           then throw new Error "Unhandled AST node type: #{n.type}"
                        when ComprehensionBlock      then throw new Error "Unhandled AST node type: #{n.type}"
                        when ComprehensionExpression then throw new Error "Unhandled AST node type: #{n.type}"
                        when ConditionalExpression   then rv = @visitConditionalExpression n
                        when ContinueStatement       then rv = @visitContinue n
                        when DebuggerStatement       then throw new Error "Unhandled AST node type: #{n.type}"
                        when DoWhileStatement        then rv = @visitDo n
                        when EmptyStatement          then rv = @visitEmptyStatement n
                        when ExportDeclaration       then rv = @visitExportDeclaration n
                        when ExportBatchSpecifier    then throw new Error "Unhandled AST node type: #{n.type}"
                        when ExportSpecifier         then throw new Error "Unhandled AST node type: #{n.type}"
                        when ExpressionStatement     then rv = @visitExpressionStatement n
                        when ForInStatement          then rv = @visitForIn n
                        when ForOfStatement          then rv = @visitForOf n
                        when ForStatement            then rv = @visitFor n
                        when FunctionDeclaration     then rv = @visitFunctionDeclaration n
                        when FunctionExpression      then rv = @visitFunctionExpression n
                        when Identifier              then rv = @visitIdentifier n
                        when IfStatement             then rv = @visitIf n
                        when ImportDeclaration       then rv = @visitImportDeclaration n
                        when ImportSpecifier         then rv = @visitImportSpecifier n
                        when LabeledStatement        then rv = @visitLabeledStatement n
                        when Literal                 then rv = @visitLiteral n
                        when LogicalExpression       then rv = @visitLogicalExpression n
                        when MemberExpression        then rv = @visitMemberExpression n
                        when MethodDefinition        then rv = @visitMethodDefinition n
                        when ModuleDeclaration       then rv = @visitModuleDeclaration n
                        when NewExpression           then rv = @visitNewExpression n
                        when ObjectExpression        then rv = @visitObjectExpression n
                        when ObjectPattern           then rv = @visitObjectPattern n
                        when Program                 then rv = @visitProgram n
                        when Property                then rv = @visitProperty n
                        when ReturnStatement         then rv = @visitReturn n
                        when SequenceExpression      then rv = @visitSequenceExpression n
                        when SpreadElement           then throw new Error "Unhandled AST node type: #{n.type}"
                        when SwitchCase              then rv = @visitCase n
                        when SwitchStatement         then rv = @visitSwitch n
                        when TaggedTemplateExpression then throw new Error "Unhandled AST node type: #{n.type}"
                        when TemplateElement         then throw new Error "Unhandled AST node type: #{n.type}"
                        when TemplateLiteral         then throw new Error "Unhandled AST node type: #{n.type}"
                        when ThisExpression          then rv = @visitThisExpression n
                        when ThrowStatement          then rv = @visitThrow n
                        when TryStatement            then rv = @visitTry n
                        when UnaryExpression         then rv = @visitUnaryExpression n
                        when UpdateExpression        then rv = @visitUpdateExpression n
                        when VariableDeclaration     then rv = @visitVariableDeclaration n
                        when VariableDeclarator      then rv = @visitVariableDeclarator n
                        when WhileStatement          then rv = @visitWhile n
                        when WithStatement           then rv = @visitWith n
                        when YieldExpression         then throw new Error "Unhandled AST node type: #{n.type}"
                        else
                            throw new Error "PANIC: unknown parse node type #{n.type}"
                
