全部的節點的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