ast api

作者: ArtioL | 来源:发表于2021-12-23 12:28 被阅读0次

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')


相关文章

  • ast api

    types path scope

  • IDL Code Generator Design For Co

    前言 框架Overview IDL AST AST Struct

  • Golang标准库——go(1)

    ast ast ast包声明用于表示Go包语法树的类型。 func FileExports FileExports...

  • JS编译——AST

    JS编译——AST AST 抽象语法树(Abstract Syntax Tree,AST),或简称语法树(Synt...

  • 【转向JavaScript系列】AST in Modern Ja

    What is AST 什么是AST?AST是Abstract Syntax Tree(抽象语法树)的缩写。传说中...

  • AST与babel

    AST 什么是ast ast又称抽象语法树,以树形结构描述代码,一般是json对象。与ast相关的操作通常有三...

  • 2018-03-29

    js_Ast structure seems that it is a pure ast tree, but i ...

  • ast语法树变成render字符串

    ast语法树变成render字符串 ast语法树变成字符串generate(ast)=>html元素: hello...

  • AST

    什么是ast ast就是把一段代码,然后转换成一颗语法树。 ast 如何工作 1, 词法分析 2,句法分析 ast...

  • vue3原理

    AST AST:抽象语法树,Abstract Syntax Tree。TypeScript、babel、webpa...

网友评论

      本文标题:ast api

      本文链接:https://www.haomeiwen.com/subject/njyqqrtx.html