Skip to content

Commit

Permalink
Merge pull request #60 from substack/fast-traverse
Browse files Browse the repository at this point in the history
skip traversing branches without the "word"
  • Loading branch information
zertosh committed Nov 1, 2015
2 parents bc63227 + eae7533 commit b5cfd30
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions index.js
Expand Up @@ -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') {
Expand All @@ -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;
Expand Down

0 comments on commit b5cfd30

Please sign in to comment.