如何获得typeof
AST中的变量是什么?
const code = `const foo = () => {
const baz = this;
}`;
我想找到 typeof 的变量globalThis
。(例如baz
是typeof globalThis
)
知道怎么做吗?
转换代码:
module.exports = (fileInfo, api, options) => {
const j = api.jscodeshift;
const root = j(fileInfo.source);
root.find(j.Identifier)
.forEach(x => {
if (x.value.name === 'baz') {
console.log({ x });
// type: typeof globalThis??
}
});
return root.toSource();
}