美文网首页
删掉代码中所有的console语句

删掉代码中所有的console语句

作者: 成熟稳重的李先生 | 来源:发表于2021-03-13 01:12 被阅读0次
const core = require('@babel/core');
const sourceCode = `
function sum(a,b) {
  console.log(123)
  return a+b+c;
}
`;

let DeleteLog = {
    visitor: {
        CallExpression(nodePath) {
            let node = nodePath.node.callee;
            if (node.object.name === 'console') {
                nodePath.remove();
            }
        },
    },
};

const targetCode = core.transform(sourceCode, {
    plugins: [DeleteLog],
});
console.log(targetCode.code);

相关文章

网友评论

      本文标题:删掉代码中所有的console语句

      本文链接:https://www.haomeiwen.com/subject/rmitcltx.html