Code coverage report for lib/infer/finders.js

Statements: 100% (20 / 20)      Branches: 100% (13 / 13)      Functions: 100% (3 / 3)      Lines: 100% (20 / 20)      Ignored: none     

All files » lib/infer/ » finders.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 3925   25   478 9     469 324       469 28       441 111     330     25 342 342     25 136 136     25 25 25  
var n = require('ast-types').namedTypes;
 
function findTarget(node) {
 
  if (!node) {
    return node;
  }
 
  if (node.value) {
    node = node.value;
  }
 
  // var x = TARGET;
  if (n.VariableDeclaration.check(node)) {
    return node.declarations[0].init;
  }
 
  // foo.x = TARGET
  if (n.ExpressionStatement.check(node)) {
    return node.expression.right;
  }
 
  return node;
}
 
function findType(node, type) {
  var target = findTarget(node);
  return n[type].check(target) && target;
}
 
function findClass(node) {
  var target = findTarget(node);
  return (n.ClassDeclaration.check(target) || n.ClassExpression.check(target)) && target;
}
 
module.exports.findTarget = findTarget;
module.exports.findType = findType;
module.exports.findClass = findClass;