npmtest-auto-install (v0.0.1)

Code coverage report for node-npmtest-auto-install/auto-install/node_modules/detective-es6/index.js

Statements: 93.75% (15 / 16)      Branches: 85.71% (12 / 14)      Functions: 100% (2 / 2)      Lines: 100% (15 / 15)      Ignored: none     

All files » node-npmtest-auto-install/auto-install/node_modules/detective-es6/ » index.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 371               1 159   159   159   159 7251008   64 64   64     56 10   56   7250888       159      
var Walker = require('node-source-walk');
 
/**
 * Extracts the dependencies of the supplied es6 module
 *
 * @param  {String|Object} src - File's content or AST
 * @return {String[]}
 */
module.exports = function(src) {
  var walker = new Walker();
 
  var dependencies = [];
 
  Iif (!src) { throw new Error('src not given'); }
 
  walker.walk(src, function(node) {
    switch (node.type) {
      case 'ImportDeclaration':
        Eif (node.source && node.source.value) {
          dependencies.push(node.source.value);
        }
        break;
      case 'ExportNamedDeclaration':
      case 'ExportAllDeclaration':
        if (node.source && node.source.value) {
          dependencies.push(node.source.value);
        }
        break;
      default:
        return;
    }
  });
 
  return dependencies;
};