[Pkg-javascript-commits] [node-detective] 37/119: fix (require)("skipme")
Bastien Roucariès
rouca at moszumanska.debian.org
Wed Sep 6 09:44:33 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 a15e9b95895467ff67e59a7875b344d50743f607
Author: James Halliday <mail at substack.net>
Date: Tue Aug 21 13:16:01 2012 -0700
fix (require)("skipme")
---
index.js | 32 +++++++++-----------------------
package.json | 2 +-
2 files changed, 10 insertions(+), 24 deletions(-)
diff --git a/index.js b/index.js
index 724d742..cbd8c8a 100644
--- a/index.js
+++ b/index.js
@@ -16,11 +16,6 @@ var traverse = function (node, cb) {
};
var walk = function (src, cb) {
- var ast = esprima.parse(src);
- traverse(ast, cb);
-};
-
-var walkSlow = function (src, cb) {
var ast = esprima.parse(src, { range : true });
traverse(ast, cb);
};
@@ -35,9 +30,12 @@ exports.find = function (src, opts) {
if (typeof src !== 'string') src = String(src);
function isRequire (node) {
- return node.type === 'CallExpression'
- && node.callee.type === 'Identifier'
- && node.callee.name === word
+ var c = node.callee;
+ return c
+ && node.type === 'CallExpression'
+ && c.type === 'Identifier'
+ && c.name === word
+ && src.slice(c.range[0], c.range[1] + 1) === word
;
}
@@ -45,8 +43,6 @@ exports.find = function (src, opts) {
if (src.indexOf(word) == -1) return modules;
- var slowPass = false;
-
walk(src, function (node) {
if (!isRequire(node)) return;
if (node.arguments.length
@@ -54,21 +50,11 @@ exports.find = function (src, opts) {
modules.strings.push(node.arguments[0].value);
}
else {
- slowPass = true;
+ var r = node.arguments[0].range;
+ var s = src.slice(r[0], r[1] + 1);
+ modules.expressions.push(s);
}
});
- if (slowPass) {
- walkSlow(src, function (node) {
- if (!isRequire(node)) return;
- if (!node.arguments.length
- || node.arguments[0].type !== 'Literal') {
- var r = node.arguments[0].range;
- var s = src.slice(r[0], r[1] + 1);
- modules.expressions.push(s);
- }
- });
- }
-
return modules;
};
diff --git a/package.json b/package.json
index 4fccd42..af79e06 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name" : "detective",
"description" : "Find all calls to require() no matter how crazily nested using a proper walk of the AST",
- "version" : "0.2.0",
+ "version" : "0.2.1",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/node-detective.git"
--
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