https://www.cnblogs.com/hanyanling/p/13246736.html
const fs = require('fs'); const {parse} = require("@babel/parser"); const traverse = require("@babel/traverse").default; const t = require("@babel/types"); const generator = require("@babel/generator").default; let jscode = fs.readFileSync("./demo.js", { encoding: "utf-8" }); let ast = parse(jscode); const Identifier2value = { VariableDeclarator(path) {
} } traverse(ast, Identifier2value); let {code} = generator(ast); fs.writeFileSync('./demoNew.js', code,{ encoding :'utf-8' })