tasks/lib/removeloggingcalls.js
function(nodes, methods) {
        var segmentsToBlank = [];

        for (var i = 0, ii = nodes.length; i < ii; ++i) {
            // checks if the statement is a CallExpression
            if (nodes[i].type === 'CallExpression' &&
                    nodes[i].callee.type === 'MemberExpression') {
                var nodeExpression = nodes[i];
                // checks if the called function is a property of console or window.console
                if (nodeExpression.callee.object.name === 'console' || (
                        nodeExpression.callee.object.property !== undefined &&
                        nodeExpression.callee.object.object !== undefined &&
                        nodeExpression.callee.object.property.name === 'console' &&
                        nodeExpression.callee.object.object.name === 'window'
                )) {
                    // push the node if the current function is within the methods array
                    if (methods.indexOf(nodeExpression.callee.property.name) > -1) {
                        segmentsToBlank.push(nodeExpression.range);
                    }
                }
            }
        }
        // sort the range segments list
        segmentsToBlank.sort(function(a, b) {
            return a[0] - b[0];
        });
        // handle the case of nested segments : "console.log(console.log('foo'))"
        removeNestedSegments(segmentsToBlank);
        return segmentsToBlank;
    }
function(nodes, methods) {
        var segmentsToBlank = [];

        for (var i = 0, ii = nodes.length; i < ii; ++i) {
            // checks if the statement is a CallExpression
            if (nodes[i].type === 'CallExpression' &&
                    nodes[i].callee.type === 'MemberExpression') {
                var nodeExpression = nodes[i];
                // checks if the called function is a property of console or window.console
                if (nodeExpression.callee.object.name === 'console' || (
                        nodeExpression.callee.object.property !== undefined &&
                        nodeExpression.callee.object.object !== undefined &&
                        nodeExpression.callee.object.property.name === 'console' &&
                        nodeExpression.callee.object.object.name === 'window'
                )) {
                    // push the node if the current function is within the methods array
                    if (methods.indexOf(nodeExpression.callee.property.name) > -1) {
                        segmentsToBlank.push(nodeExpression.range);
                    }
                }
            }
        }
        // sort the range segments list
        segmentsToBlank.sort(function(a, b) {
            return a[0] - b[0];
        });
        // handle the case of nested segments : "console.log(console.log('foo'))"
        removeNestedSegments(segmentsToBlank);
        return segmentsToBlank;
    }
function ( nodes , methods ) { var segmentsToBlank = [ ] ; for ( var i = 0 , ii = nodes . length ; i < ii ; ++ i ) { // checks if the statement is a CallExpression if ( nodes [ i ] . type === 'CallExpression' && nodes [ i ] . callee . type === 'MemberExpression' ) { var nodeExpression = nodes [ i ] ; // checks if the called function is a property of console or window.console if ( nodeExpression . callee . object . name === 'console' || ( nodeExpression . callee . object . property !== undefined && nodeExpression . callee . object . object !== undefined && nodeExpression . callee . object . property . name === 'console' && nodeExpression . callee . object . object . name === 'window' ) ) { // push the node if the current function is within the methods array if ( methods . indexOf ( nodeExpression . callee . property . name ) > - 1 ) { segmentsToBlank . push ( nodeExpression . range ) ; } } } } // sort the range segments list segmentsToBlank . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] ; } ) ; // handle the case of nested segments : "console.log(console.log('foo'))" removeNestedSegments ( segmentsToBlank ) ; return segmentsToBlank ; }
Identify nodes that relate to console statements
@param {Node[]} nodes the list of nodes
@param {Node[]} methods the methods to identify
@param {String[]} methods the properties (functions) to catch for blanking
Identify nodes that relate to console statements