Skip to content

Commit

Permalink
Added support for dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
gmathieu authored and mrjoelkemp committed Aug 27, 2017
1 parent 7baaf06 commit 393a968
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ module.exports = function(src) {
dependencies.push(node.source.value);
}
break;
case 'CallExpression':
if (node.callee.type === 'Import' && node.arguments.length) {
dependencies.push(node.arguments[0].value);
}
default:
return;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"homepage": "https://github.com/mrjoelkemp/node-detective-es6",
"dependencies": {
"node-source-walk": "^3.0.0"
"node-source-walk": "^3.3.0"
},
"devDependencies": {
"jscs": "~2.4.0",
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ describe('detective-es6', function() {
assert(deps[0] === 'foo');
});

it('handles dynamic imports', function() {
var deps = detective('import("foo").then(foo => foo());');

assert(deps.length === 1);
assert(deps[0] === 'foo');
})

it('returns an empty list for non-es6 modules', function() {
var deps = detective('var foo = require("foo");');
assert(!deps.length);
Expand Down

0 comments on commit 393a968

Please sign in to comment.