2019-10-29 NodeJS auto export al
acorn helps fix the issue of esprima
const autoParse = () => {
const acorn = require("acorn");
const fs = require("fs");
const program = fs.readFileSync(__filename, "utf8");
const parsed = acorn.parse(program);
parsed.body.forEach(fn => {
if (fn.type.endsWith("VariableDeclaration")) {
const fnv = fn.declarations[0];
module.exports[fnv.id.name] = eval(fnv.id.name);
}
if (fn.type.endsWith("FunctionDeclaration")) {
module.exports[fn.id.name] = eval(fn.id.name);
}
});
};
autoParse();
本文标题:2019-10-29 NodeJS auto export al
本文链接:https://www.haomeiwen.com/subject/jrhgvctx.html
网友评论