index.js
function findReferrer(candidate, container) {
  var result;
  if (candidate) {

    // initially for the parent of the candidate node
    container = container || candidate.parent;

    // consider keys in the node until we have a result
    var keys = getKeys(container);
    for (var i = 0; !result && (i < keys.length); i++) {
      var key = keys[i];
      if (WHITE_LIST.test(key)) {
        var value = container[key];

        // found
        if (value === candidate) {
          result = {
            object: container,
            key   : key
          };
        }
        // recurse
        else if (value && (typeof value === 'object')) {
          result = findReferrer(candidate, value);
        }
      }
    }
  }

  // complete
  return result;
}
function findReferrer(candidate, container) {
  var result;
  if (candidate) {

    // initially for the parent of the candidate node
    container = container || candidate.parent;

    // consider keys in the node until we have a result
    var keys = getKeys(container);
    for (var i = 0; !result && (i < keys.length); i++) {
      var key = keys[i];
      if (WHITE_LIST.test(key)) {
        var value = container[key];

        // found
        if (value === candidate) {
          result = {
            object: container,
            key   : key
          };
        }
        // recurse
        else if (value && (typeof value === 'object')) {
          result = findReferrer(candidate, value);
        }
      }
    }
  }

  // complete
  return result;
}
function findReferrer ( candidate , container ) { var result ; if ( candidate ) { // initially for the parent of the candidate node container = container || candidate . parent ; // consider keys in the node until we have a result var keys = getKeys ( container ) ; for ( var i = 0 ; ! result && ( i < keys . length ) ; i ++ ) { var key = keys [ i ] ; if ( WHITE_LIST . test ( key ) ) { var value = container [ key ] ; // found if ( value === candidate ) { result = { object : container , key : key } ; } // recurse else if ( value && ( typeof value === 'object' ) ) { result = findReferrer ( candidate , value ) ; } } } } // complete return result ; }
Find the object and field that refers to the given node.
@param {object} candidate An esprima AST node to match
@param {object} [container] Optional container to search within or the candidate parent where omitted
@returns {{object:object, key:*}} The object and its key where the candidate node is a value
Find the object and field that refers to the given node .