esprima 与 escodegen 格式化代码(带注释)

var jsContentStr1 = fs.readFileSync(path.join(__dirname,"output","newGenEpos.js"),"utf-8");

let jsBodyArr1 = esprima.parseScript(jsContentStr1,{
    range: true,
    tokens: true,
    comment: true
}).body;


let tree = esprima.parseScript(jsContentStr1,{
    range: true,
    tokens: true,
    comment: true
});
tree = escodegen.attachComments(tree, tree.comments, tree.tokens);
escodegen.generate(tree.body[0],{comment:true})

  

 
posted @ 2022-12-28 23:11  今天起个早  阅读(157)  评论(0编辑  收藏  举报