Skip to content

Commit

Permalink
modernize, fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Mar 2, 2013
2 parents 07ead9a + 06d5cb4 commit aa50907
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var esprima = require('esprima');
var escodegen = require('escodegen');

var traverse = function (node, cb) {
if (Array.isArray(node)) {
Expand All @@ -19,7 +20,7 @@ var traverse = function (node, cb) {
};

var walk = function (src, cb) {
var ast = esprima.parse(src, { range : true });
var ast = esprima.parse(src);
traverse(ast, cb);
};

Expand All @@ -39,7 +40,6 @@ exports.find = function (src, opts) {
&& node.type === 'CallExpression'
&& c.type === 'Identifier'
&& c.name === word
&& src.slice(c.range[0], c.range[1]) === word
;
}

Expand All @@ -54,9 +54,7 @@ exports.find = function (src, opts) {
modules.strings.push(node.arguments[0].value);
}
else {
var r = node.arguments[0].range;
var s = src.slice(r[0], r[1]);
modules.expressions.push(s);
modules.expressions.push(escodegen.generate(node.arguments[0]));
}
});

Expand Down
15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -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" : "1.1.0",
"version" : "2.0.0",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/node-detective.git"
Expand All @@ -13,22 +13,15 @@
"analyze",
"ast"
],
"directories" : {
"lib" : ".",
"example" : "example",
"test" : "test"
},
"scripts" : {
"test" : "tap test/*.js"
},
"dependencies" : {
"esprima" : "~1.0.2"
"esprima" : "1.0.2",
"escodegen": "0.0.15"
},
"devDependencies" : {
"tap" : "~0.2.6"
},
"engines" : {
"node" : ">=0.6.0"
"tap" : "~0.4.0"
},
"license" : "MIT",
"author" : {
Expand Down
2 changes: 1 addition & 1 deletion test/both.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ var src = fs.readFileSync(__dirname + '/files/both.js');
test('both', function (t) {
var modules = detective.find(src);
t.deepEqual(modules.strings, [ 'a', 'b' ]);
t.deepEqual(modules.expressions, [ "'c'+x", "'d'+y" ]);
t.deepEqual(modules.expressions, [ "'c' + x", "'d' + y" ]);
t.end();
});

0 comments on commit aa50907

Please sign in to comment.