美文网首页
2019-10-29 NodeJS auto export al

2019-10-29 NodeJS auto export al

作者: 五大RobertWu伍洋 | 来源:发表于2019-10-29 15:38 被阅读0次

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