index.js
function prune(code) {
  var ast = esprima.parse(code);

  estraverse.replace(ast, {
    leave: function leave(node, parent) {
      var ret;

      if ('IfStatement' === node.type) {
        if ('BinaryExpression' !== node.test.type) return;

        if ('self' === node.test.left.argument.name) {
          node.alternate = null;
        } else if ('global' === node.test.left.argument.name) {
          ret = node.alternate;
        }

        return ret;
      }

      if (
          'BlockStatement' === node.type
        && 'FunctionExpression' === parent.type
      ) {
        return node.body[0].alternate.alternate;
      }
    }
  });

  return escodegen.generate(ast, {
    format: {
      indent: { style: '  ' },
      semicolons: false,
      compact: true
    }
  });
}
function prune(code) {
  var ast = esprima.parse(code);

  estraverse.replace(ast, {
    leave: function leave(node, parent) {
      var ret;

      if ('IfStatement' === node.type) {
        if ('BinaryExpression' !== node.test.type) return;

        if ('self' === node.test.left.argument.name) {
          node.alternate = null;
        } else if ('global' === node.test.left.argument.name) {
          ret = node.alternate;
        }

        return ret;
      }

      if (
          'BlockStatement' === node.type
        && 'FunctionExpression' === parent.type
      ) {
        return node.body[0].alternate.alternate;
      }
    }
  });

  return escodegen.generate(ast, {
    format: {
      indent: { style: '  ' },
      semicolons: false,
      compact: true
    }
  });
}
function prune ( code ) { var ast = esprima . parse ( code ) ; estraverse . replace ( ast , { leave : function leave ( node , parent ) { var ret ; if ( 'IfStatement' === node . type ) { if ( 'BinaryExpression' !== node . test . type ) return ; if ( 'self' === node . test . left . argument . name ) { node . alternate = null ; } else if ( 'global' === node . test . left . argument . name ) { ret = node . alternate ; } return ret ; } if ( 'BlockStatement' === node . type && 'FunctionExpression' === parent . type ) { return node . body [ 0 ] . alternate . alternate ; } } } ) ; return escodegen . generate ( ast , { format : { indent : { style : '  ' } , semicolons : false , compact : true } } ) ; }
Prune unwanted branches from the given source code.

@param {String} code Source code to prune
@returns {String} Pruned source code
@api private
Prune unwanted branches from the given source code .