const j = require("jscodeshift");
const fs = require("fs");
const path = require("path");
const jsContent = fs
.readFileSync(path.join(__dirname, "./test.js"))
.toString("utf-8");
let rootAst = j(jsContent);
ast = rootAst.find(j.CallExpression, {
callee: {
object: {
name: "app",
},
property: {
name: "get",
},
},
});
ast.find(j.Identifier, { name: "get" }).forEach((path) => {
j(path).replaceWith(j.identifier("post"));
});
ast.find(j.FunctionExpression).forEach((path) => {
j(path).replaceWith(
j.arrowFunctionExpression(path.value.params, path.value.body, false)
);
});
ast.find(j.ArrowFunctionExpression).forEach((path) => {
j(path).insertAfter(
j.arrowFunctionExpression(
path.value.params,
path.value.body,
false
)
);
});
ast.find(j.ArrowFunctionExpression).forEach((path) => {
j(path).replaceWith()
})
ast = rootAst.find(j.ExpressionStatement).forEach((path) => {
j(path).insertAfter(`console.log(111)`)
})
console.log(rootAst.toSource());