const types=require("@babel/types");//生成节点,判断类型
const generator=require("@babel/generator").default;//生成代码
const fs=require("fs");
/*
function losenine(a,b){
var c=1000;
var d=a+b+c;
return "losenine";
}
*/
var node=types.functionDeclaration(
types.identifier("losenine"),
[types.identifier("a"),types.identifier("b")],
types.blockStatement([
types.variableDeclaration("var",[types.variableDeclarator(types.identifier("c"),types.bigIntLiteral("1000"))]),
types.variableDeclaration("var",[types.variableDeclarator(types.identifier("d"),
types.binaryExpression("+",
types.binaryExpression("+",
types.identifier("a"),types.identifier("b")),
types.identifier("c")))]),
types.returnStatement(types.stringLiteral("losenine"))
])
);
console.log(node);
let code=generator(node);
console.log(code.code);
fs.writeFile("./generatorJS.js",code.code,function(err){console.log(err)});