1.使用第三方包 recast
安装方法:npm i recast
2.recast使用方法
const recast = require("recast");
function a(b, c){
return b + c
}
const ast = recast.parse(a)
console.log( ast.program.body[0] )
a是基础Identifier(标志)对象,用来作为函数的唯一标志
body里面是BlockStatement(块状域)对象,用来表示:{return b + c}
BlockStatement里面是ReturnStatement(Return域)对象,用来表示:return b + c
ReturnStatement里面是BinaryExpression(二项式)对象,用来表示:b+c
BinaryExpression里面是三部分:left(b),operator(+),right(c)
网友评论