var esprima = require('esprima')
var escodegen = require('escodegen')
function formatJS(content){ //context是要格式的js
var ast=esprima.parseScript(content.toString());
var ast_to_json=JSON.stringify(ast);
console.log(ast_to_json);
var ast1=JSON.parse(ast_to_json);
var code=escodegen.generate(ast1);
console.log(code);
return code;
}
在线生成AST语法树
http://esprima.org/demo/parse.html