getVariableDeclarators: function()

in src/collections/Node.js [103:120]


  getVariableDeclarators: function(nameGetter) {
    return this.map(function(path) {
      /*jshint curly:false*/
      let scope = path.scope;
      if (!scope) return;
      const name = nameGetter.apply(path, arguments);
      if (!name) return;
      scope = scope.lookup(name);
      if (!scope) return;
      const bindings = scope.getBindings()[name];
      if (!bindings) return;
      const decl = Collection.fromPaths(bindings)
        .closest(types.VariableDeclarator);
      if (decl.length === 1) {
        return decl.paths()[0];
      }
    }, types.VariableDeclarator);
  },