如何将 ast-node 转换为底层 javascript 其代表的字符串
How to convert an ast-node to a string of the underlying javascript its representing
如何将节点转换为 javascript?
// target file
function execute() {
var a = 'a'
}
// jscodeshift
export default(file, api) => {
const j = api.jscodeshift
const root = j(file.source)
var node = root.find(j.VariableDeclaration)
// i want to see what node looks like in javascript.
return root.toSource()
}
推测存在您搜索的非空集合:
var node = root.find(j.VariableDeclaration).at(0).get();
// in js node looks like
return j(node).toSource();
如何将节点转换为 javascript?
// target file
function execute() {
var a = 'a'
}
// jscodeshift
export default(file, api) => {
const j = api.jscodeshift
const root = j(file.source)
var node = root.find(j.VariableDeclaration)
// i want to see what node looks like in javascript.
return root.toSource()
}
推测存在您搜索的非空集合:
var node = root.find(j.VariableDeclaration).at(0).get();
// in js node looks like
return j(node).toSource();