[Pkg-javascript-commits] [node-detective] 50/119: adding option to include node for each require in a nodes array

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:44:34 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-detective.

commit 47bc4de751520dc48a2e09ffcdb3bcb0166d5727
Author: Thorsten Lorenz <thlorenz at gmx.de>
Date:   Sat Mar 30 22:10:55 2013 -0400

    adding option to include node for each require in a nodes array
---
 index.js        |  2 ++
 readme.markdown |  3 +++
 test/both.js    | 15 +++++++++++++++
 3 files changed, 20 insertions(+)

diff --git a/index.js b/index.js
index 46ffed1..56f3266 100644
--- a/index.js
+++ b/index.js
@@ -44,6 +44,7 @@ exports.find = function (src, opts) {
     }
     
     var modules = { strings : [], expressions : [] };
+    if (opts.nodes) modules.nodes = [];
     
     if (src.indexOf(word) == -1) return modules;
     
@@ -56,6 +57,7 @@ exports.find = function (src, opts) {
         else {
             modules.expressions.push(escodegen.generate(node.arguments[0]));
         }
+        if (opts.nodes) modules.nodes.push(node);
     });
     
     return modules;
diff --git a/readme.markdown b/readme.markdown
index a3c823d..8181801 100644
--- a/readme.markdown
+++ b/readme.markdown
@@ -57,6 +57,9 @@ The "expressions" array will contain the stringified expressions.
 Optionally you can specify a different function besides `"require"` to analyze
 with `opts.word`.
 
+You can also specify `opts.nodes = true` in order to include a "nodes" array 
+which contains an AST node for each of the require() calls.
+
 # install
 
 With [npm](https://npmjs.org) do:
diff --git a/test/both.js b/test/both.js
index 7e09243..f09f1f8 100644
--- a/test/both.js
+++ b/test/both.js
@@ -7,5 +7,20 @@ test('both', function (t) {
     var modules = detective.find(src);
     t.deepEqual(modules.strings, [ 'a', 'b' ]);
     t.deepEqual(modules.expressions, [ "'c' + x", "'d' + y" ]);
+    t.notOk(modules.nodes, 'has no nodes');
+    t.end();
+});
+
+test('both with nodes specified in opts', function (t) {
+    var modules = detective.find(src, { nodes: true });
+    t.deepEqual(modules.strings, [ 'a', 'b' ]);
+    t.deepEqual(modules.expressions, [ "'c' + x", "'d' + y" ]);
+    t.deepEqual(
+      modules.nodes.map(function (n) { 
+        var arg = n.arguments[0];
+        return arg.value || arg.left.value; 
+      }),
+      [ 'a', 'b', 'c', 'd' ],
+      'has a node for each require');
     t.end();
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-detective.git



More information about the Pkg-javascript-commits mailing list