nycJSorg/angular-presentation

View on GitHub
apps/kirjs/src/app/modules/ast/samples/find-console-log/remove-console-log.ts

Summary

Maintainability
B
5 hrs
Test Coverage
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;
}