apps/kirjs/src/app/modules/ast/samples/find-console-log/remove-console-log.ts
function removeConsoleLog(
code,
{ babelGenerator, babylon, babelTraverse, types }
) {
const ast = babylon.parse(code);
let hasConsoleLog = false;
babelTraverse(ast, {
MemberExpression(path) {
if (
types.isIdentifier(path.node.object, { name: 'console' }) &&
types.isIdentifier(path.node.property, { name: 'log' }) &&
types.isCallExpression(path.parent) &&
path.parentKey === 'callee'
) {
hasConsoleLog = true;
}
}
});
return hasConsoleLog;
}