[Pkg-javascript-commits] [node-detective] 58/119: Allow passing isRequire detector as an option
Bastien Roucariès
rouca at moszumanska.debian.org
Wed Sep 6 09:44:35 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 ad583cd41db1419a02e0f578f9a821346981e2e3
Author: Andrey Popp <8mayday at gmail.com>
Date: Sat Sep 14 21:20:05 2013 +0400
Allow passing isRequire detector as an option
---
index.js | 2 +-
test/files/isrequire.js | 14 ++++++++++++++
test/isrequire.js | 20 ++++++++++++++++++++
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/index.js b/index.js
index e8d3fc8..b33ca72 100644
--- a/index.js
+++ b/index.js
@@ -36,7 +36,7 @@ exports.find = function (src, opts) {
if (typeof src !== 'string') src = String(src);
src = '(function(){' + src.replace(/^#![^\n]*\n/, '') + '\n})()';
- function isRequire (node) {
+ var isRequire = opts.isRequire || function (node) {
var c = node.callee;
return c
&& node.type === 'CallExpression'
diff --git a/test/files/isrequire.js b/test/files/isrequire.js
new file mode 100644
index 0000000..4421002
--- /dev/null
+++ b/test/files/isrequire.js
@@ -0,0 +1,14 @@
+var a = require.async('a');
+var b = require.async('b');
+var c = require.async('c');
+var abc = a.b(c);
+
+var EventEmitter = require.async('events').EventEmitter;
+
+var x = require.async('doom')(5,6,7);
+x(8,9);
+c.load('notthis');
+var y = require.async('y') * 100;
+
+var EventEmitter2 = require.async('events2').EventEmitter();
+
diff --git a/test/isrequire.js b/test/isrequire.js
new file mode 100644
index 0000000..aa2ce36
--- /dev/null
+++ b/test/isrequire.js
@@ -0,0 +1,20 @@
+var test = require('tap').test;
+var detective = require('../');
+var fs = require('fs');
+var src = fs.readFileSync(__dirname + '/files/isrequire.js');
+
+test('word', function (t) {
+ t.deepEqual(
+ detective(src, { isRequire: function(node) {
+ return (node.type === 'CallExpression' &&
+ node.callee.type === 'MemberExpression' &&
+ node.callee.object.type == 'Identifier' &&
+ node.callee.object.name == 'require' &&
+ node.callee.property.type == 'Identifier' &&
+ node.callee.property.name == 'async')
+ } }),
+ [ 'a', 'b', 'c', 'events', 'doom', 'y', 'events2' ]
+ );
+ t.end();
+});
+
--
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