ast api

types

// 判断node是否为布尔类型
types.isBooleanLiteral(node)
// 判断node是否为switch
types.isSwitchStatement(node)


path

// 停止当前节点遍历
path.stop()
// 
path.skip()

// 父级path操作

// 父节点路径
path.findParent((path)=>{bool})

// 查找节点路径 和findParent区别是find包含自身节点路径
path.find(path=>{bool})

path.findFunctionParent

path.findStatementParent

//同级path操作

// 是否有兄弟节点
path.inList   

// 所在容器
path.container
// 容器名
path.listKey
// 当前节点在容器内的索引
path.key
// 获取同级兄弟节点路径
path.getSibling(index)

// 头部加入节点 返回包装成path的节点对象 或列表
path.unshiftContainer("节点下的属性名", node)
// 尾部加入节点 返回包装成path的节点对象 或列表
path.pushContainer("节点下的属性名", node)

scope

//获取标识符的作用域  返回Node对象
path.scope.block

//获取函数的作用域
path.scope.parent.block

// 获取标志符的绑定
scope.getBinding("变量【标识符】名称")
// 获取自身节点的绑定
scope.getOwnBinding()
// 标识符被引用的地方
scope. referencePaths
//标识符被赋值或修改的地方
scope. constantViolations 
// scope遍历
scope.traverse(node节点, {
      节点类型(p){

       }
})

// 变量名修改
scope.rename(path.node.name, path.scope.generateUidIdentifier('_0x2ba6ea').name)

//是否有标识符的绑定
scope.hasBinding('a')
//是否有标识符的绑定
scope.hasOwnBinding('a')

// 获取所有绑定 {a: binding, b: binding}
scope.getAllBindings()
// 查询当前节点是否有a标识符的引用
scope.hasRefence('a')
// 获取当前节点中绑定的a的标识符,返回的是Identifier的node对象
scope.getBindingIdentifier('a')


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容