nycJSorg/angular-presentation

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

Summary

Maintainability
A
0 mins
Test Coverage
function removeConsoleLogSolved(
  code,
  { babelGenerator, babylon, babelTraverse, types }
) {
  const ast = babylon.parse(code);

  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'
      ) {
        path.parentPath.remove();
      }
    }
  });

  return babelGenerator(ast).code;
}