所有的节点的transform方法都对应同一个函数:
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方法为一个空函数
以下节点有自定义的descend方法
AST_LabeledStatement,AST_SimpleStatement,AST_Block,AST_DWLoop,AST_For,AST_ForIn,
AST_With,AST_Exit,AST_LoopControl,AST_If,AST_Switch,AST_Case,AST_Try,AST_Catch,
AST_Definitions,AST_VarDef,AST_Lambda,AST_Call,AST_Seq,AST_Dot,AST_Sub,
AST_Unary,AST_Binary,AST_Conditional,AST_Array,AST_Object,AST_ObjectProperty
时间: 2024-10-10 10:50:37