[Pkg-javascript-commits] [node-detective] 108/119: skip traversing branches without the "word"

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:44:40 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 eae753394b6a99be5f0fe629be7dec059810219a
Author: Andres Suarez <zertosh at gmail.com>
Date:   Sun Nov 1 00:02:56 2015 -0700

    skip traversing branches without the "word"
    
    inspired by #58
---
 index.js | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index 16e1446..2ab6395 100644
--- a/index.js
+++ b/index.js
@@ -43,9 +43,12 @@ exports.find = function (src, opts) {
     
     var ast = parse(src, opts.parse);
     
-    walk.simple(ast, {
-        CallExpression: function (node) {
-            if (!isRequire(node)) return;
+    function visit(node, st, c) {
+        var hasRequire = wordRe.test(src.slice(node.start, node.end));
+        if (!hasRequire) return;
+        walk.base[node.type](node, st, c);
+        if (node.type !== 'CallExpression') return;
+        if (isRequire(node)) {
             if (node.arguments.length) {
                 var arg = node.arguments[0];
                 if (arg.type === 'Literal') {
@@ -57,6 +60,11 @@ exports.find = function (src, opts) {
             }
             if (opts.nodes) modules.nodes.push(node);
         }
+    }
+    
+    walk.recursive(ast, null, {
+        Statement: visit,
+        Expression: visit
     });
     
     return modules;

-- 
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