From 393a968d9420d5e1afff8f583850f0559a2bbefc Mon Sep 17 00:00:00 2001 From: Guillaume Mathieu Date: Sun, 27 Aug 2017 12:49:19 -0700 Subject: [PATCH] Added support for dynamic import Refs https://github.com/dependents/node-source-walk/pull/23 Closes gh-11 --- index.js | 4 ++++ package.json | 2 +- test/test.js | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 54019d5..6bfb853 100644 --- a/index.js +++ b/index.js @@ -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; } diff --git a/package.json b/package.json index 2dd8722..ac43b7c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/test.js b/test/test.js index 53a86f8..73be43a 100644 --- a/test/test.js +++ b/test/test.js @@ -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);