[Pkg-javascript-commits] [node-lexical-scope] 06/83: passing tests

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:45:45 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-lexical-scope.

commit 6904dd0c62b8197ad8baa8b15749ae8b8f28f31b
Author: James Halliday <mail at substack.net>
Date:   Sun Feb 17 14:54:44 2013 +1000

    passing tests
---
 example/detect.js      |  3 +--
 index.js               | 12 ++++++++----
 test/detect.js         | 17 +++++++++++++++++
 test/sources/detect.js | 29 +++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/example/detect.js b/example/detect.js
index 2ca21eb..7b98e48 100644
--- a/example/detect.js
+++ b/example/detect.js
@@ -3,5 +3,4 @@ var fs = require('fs');
 var src = fs.readFileSync(__dirname + '/src.js');
 
 var scope = detect(src);
-console.dir(scope.globals);
-//console.dir(scope.locals);
+console.dir(scope);
diff --git a/index.js b/index.js
index 97f496a..b619b52 100644
--- a/index.js
+++ b/index.js
@@ -28,16 +28,20 @@ module.exports = function (src) {
             if (isFunction(node.parent)) return;
             
             if (node.parent.type === 'AssignmentExpression') {
-                exported[node.name] = true;
+                exported[node.name] = keyOf(node).length;
             }
-            if (!exported[node.name]) {
-                implicit[node.name] = true;
+            if (!exported[node.name]
+            || exported[node.name] < keyOf(node).length) {
+                implicit[node.name] = keyOf(node).length;
             }
         }
     });
     
     return {
-        locals: locals,
+        locals: Object.keys(locals).reduce(function (acc, key) {
+            acc[key] = Object.keys(locals[key]);
+            return acc;
+        }, {}),
         globals: {
             implicit: Object.keys(implicit),
             exported: Object.keys(exported)
diff --git a/test/detect.js b/test/detect.js
new file mode 100644
index 0000000..67c978d
--- /dev/null
+++ b/test/detect.js
@@ -0,0 +1,17 @@
+var test = require('tape');
+var detect = require('../');
+var fs = require('fs');
+var src = fs.readFileSync(__dirname + '/sources/detect.js');
+
+test('check locals and globals', function (t) {
+    t.plan(3);
+    
+    var scope = detect(src);
+    t.same(scope.globals.implicit, [
+        'w', 'foo', 'process', 'console', 'xyz'
+    ]);
+    t.same(scope.globals.exported, [
+        'w', 'RAWR', 'BLARG', 'ZZZ'
+    ]);
+    t.same(scope.locals[''], [ 'x', 'y', 'z', 'beep' ]);
+});
diff --git a/test/sources/detect.js b/test/sources/detect.js
new file mode 100644
index 0000000..6213514
--- /dev/null
+++ b/test/sources/detect.js
@@ -0,0 +1,29 @@
+var x = 5;
+var y = 3, z = 2;
+
+w.foo();
+w = 2;
+
+RAWR=444;
+RAWR.foo();
+
+BLARG=3;
+
+foo(function () {
+    var BAR = 3;
+    process.nextTick(function (ZZZZZZZZZZZZ) {
+        console.log('beep boop');
+        var xyz = 4;
+        x += 10;
+        x.zzzzzz;
+        ZZZ=6;
+    });
+    function doom () {
+    }
+    ZZZ.foo();
+
+});
+
+function beep () {}
+
+console.log(xyz);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-lexical-scope.git



More information about the Pkg-javascript-commits mailing list