lib/optimiser.js
function findScope (ast, item) {
  var scopes = [],
      found = false;
  traverse.traverse(ast, {
    enter: function (node, parent) {
      if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
        scopes.push(node);
      }
      else if (node === item) {
        found = scopes[scopes.length - 1];
        this.break();
      }
    },
    leave: function (node, parent) {
      if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
        scopes.pop();
      }
    }
  });
  return found ? found.body : false;
}
function findScope (ast, item) {
  var scopes = [],
      found = false;
  traverse.traverse(ast, {
    enter: function (node, parent) {
      if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
        scopes.push(node);
      }
      else if (node === item) {
        found = scopes[scopes.length - 1];
        this.break();
      }
    },
    leave: function (node, parent) {
      if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
        scopes.pop();
      }
    }
  });
  return found ? found.body : false;
}
function findScope ( ast , item ) { var scopes = [ ] , found = false ; traverse . traverse ( ast , { enter : function ( node , parent ) { if ( node . type === 'FunctionDeclaration' || node . type === 'FunctionExpression' ) { scopes . push ( node ) ; } else if ( node === item ) { found = scopes [ scopes . length - 1 ] ; this . break ( ) ; } } , leave : function ( node , parent ) { if ( node . type === 'FunctionDeclaration' || node . type === 'FunctionExpression' ) { scopes . pop ( ) ; } } } ) ; return found ? found . body : false ; }
Find the scope for an item in the AST.
Find the scope for an item in the AST .