全部的节点的transform方法都对应同一个函数:node
node.DEFMETHOD("transform", function(tw, in_list){ var x, y; tw.push(this); if (tw.before) x = tw.before(this, descend, in_list); if (x === undefined) { if (!tw.after) { x = this; descend(x, tw); } else { tw.stack[tw.stack.length - 1] = x = this.clone(); descend(x, tw); y = tw.after(x, in_list); if (y !== undefined) x = y; } } tw.pop(); return x; });
不一样的是每一个节点能够有不一样的descend方法 函数
AST_Node的descend方法为一个空函数oop
如下节点有自定义的descend方法this
AST_LabeledStatement,AST_SimpleStatement,AST_Block,AST_DWLoop,AST_For,AST_ForIn,spa
AST_With,AST_Exit,AST_LoopControl,AST_If,AST_Switch,AST_Case,AST_Try,AST_Catch,code
AST_Definitions,AST_VarDef,AST_Lambda,AST_Call,AST_Seq,AST_Dot,AST_Sub,orm
AST_Unary,AST_Binary,AST_Conditional,AST_Array,AST_Object,AST_ObjectPropertyblog