Permalink
Browse files

use the latest esprima, remove support for (require)

  • Loading branch information...
1 parent a15e9b9 commit 545eb29c05ef947b624dc7451377c0cdf480aab8 @substack substack committed Feb 2, 2013
Showing with 8 additions and 21 deletions.
  1. +1 −1 example/strings.js
  2. +5 −2 index.js
  3. +2 −2 package.json
  4. +0 −7 test/files/skip.js
  5. +0 −9 test/skip.js
View
@@ -1,4 +1,4 @@
-var detective = require('detective');
+var detective = require('../');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/strings_src.js');
View
@@ -3,13 +3,16 @@ var esprima = require('esprima');
var traverse = function (node, cb) {
if (Array.isArray(node)) {
node.forEach(function (x) {
+ x.parent = node;
traverse(x, cb);
});
}
else if (node && typeof node === 'object') {
cb(node);
Object.keys(node).forEach(function (key) {
+ if (key === 'parent' || !node[key]) return;
+ node[key].parent = node;
traverse(node[key], cb);
});
}
@@ -35,7 +38,7 @@ exports.find = function (src, opts) {
&& node.type === 'CallExpression'
&& c.type === 'Identifier'
&& c.name === word
- && src.slice(c.range[0], c.range[1] + 1) === word
+ && src.slice(c.range[0], c.range[1]) === word
;
}
@@ -51,7 +54,7 @@ exports.find = function (src, opts) {
}
else {
var r = node.arguments[0].range;
- var s = src.slice(r[0], r[1] + 1);
+ var s = src.slice(r[0], r[1]);
modules.expressions.push(s);
}
});
View
@@ -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.1",
+ "version" : "1.0.0",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/node-detective.git"
@@ -22,7 +22,7 @@
"test" : "tap test/*.js"
},
"dependencies" : {
- "esprima" : "~0.9.9"
+ "esprima" : "~1.0.2"
},
"devDependencies" : {
"tap" : "~0.2.6"
View
@@ -1,7 +0,0 @@
-var a = require('a');
-var x = (require)('x');
-var b = require('b');
-var y = (function () { return (require)('y') })();
-var c = require('c');
-var abc = a.b(c);
-(require)('z').x.y();
View
@@ -1,9 +0,0 @@
-var test = require('tap').test;
-var detective = require('../');
-var fs = require('fs');
-var src = fs.readFileSync(__dirname + '/files/skip.js');
-
-test('skip', function (t) {
- t.deepEqual(detective(src), [ 'a', 'b', 'c' ]);
- t.end();
-});

0 comments on commit 545eb29

Please sign in to comment.