[Pkg-javascript-commits] [node-detective] 01/119: implementation that passes a simple string test
Bastien Roucariès
rouca at moszumanska.debian.org
Wed Sep 6 09:44:29 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 809493d9921a4b5ca9e3f531a3cb1f7cd0a426a9
Author: James Halliday <mail at substack.net>
Date: Fri Jun 17 17:55:39 2011 -0700
implementation that passes a simple string test
---
index.js | 27 +++++++++++++++++++++++++++
test/strings.js | 8 ++++++++
test/strings/src.js | 3 +++
3 files changed, 38 insertions(+)
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..63729a0
--- /dev/null
+++ b/index.js
@@ -0,0 +1,27 @@
+var burrito = require('burrito');
+
+var exports = module.exports = function (src) {
+ return exports.find(src).strings;
+};
+
+exports.find = function (src) {
+ var modules = { strings : [], expressions : [] };
+
+ burrito(src, function (node) {
+ var isRequire = node.name === 'call'
+ && node.value[0][0] === 'name'
+ && node.value[0][1] === 'require'
+ ;
+ if (isRequire) {
+ var expr = node.value[1][0];
+
+ if (expr[0].name === 'string') {
+ modules.strings.push(expr[1]);
+ }
+ else {
+ modules.expressions.push(burrito.deparse(expr));
+ }
+ }
+ });
+ return modules;
+};
diff --git a/test/strings.js b/test/strings.js
new file mode 100644
index 0000000..2837e87
--- /dev/null
+++ b/test/strings.js
@@ -0,0 +1,8 @@
+var assert = require('assert');
+var detective = require('../');
+var fs = require('fs');
+var src = fs.readFileSync(__dirname + '/strings/src.js');
+
+exports.single = function () {
+ assert.deepEqual(detective(src), [ 'a', 'b', 'c' ]);
+};
diff --git a/test/strings/src.js b/test/strings/src.js
new file mode 100644
index 0000000..62e5cf6
--- /dev/null
+++ b/test/strings/src.js
@@ -0,0 +1,3 @@
+require('a');
+require('b');
+require('c');
--
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