mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-07-30 09:49:07 +00:00
update
This commit is contained in:
49
node_modules/detective-es6/index.js
generated
vendored
Normal file
49
node_modules/detective-es6/index.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
var Walker = require('node-source-walk');
|
||||
|
||||
/**
|
||||
* Extracts the dependencies of the supplied es6 module
|
||||
*
|
||||
* @param {String|Object} src - File's content or AST
|
||||
* @param {Object} options - optional extra settings
|
||||
* @return {String[]}
|
||||
*/
|
||||
module.exports = function(src, options) {
|
||||
const walker = new Walker();
|
||||
|
||||
const dependencies = [];
|
||||
|
||||
if (typeof src === 'undefined') { throw new Error('src not given'); }
|
||||
|
||||
if (src === '') {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
walker.walk(src, function(node) {
|
||||
switch (node.type) {
|
||||
case 'ImportDeclaration':
|
||||
if (options && options.skipTypeImports && node.importKind == 'type') {
|
||||
break;
|
||||
}
|
||||
if (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;
|
||||
case 'CallExpression':
|
||||
if (node.callee.type === 'Import' && node.arguments.length) {
|
||||
dependencies.push(node.arguments[0].value);
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
return dependencies;
|
||||
};
|
Reference in New Issue
Block a user