[Pkg-javascript-commits] [node-lexical-scope] 05/83: differentiate between implicit and exported globals

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 f5106948ec43f0b75bb035e28a41ee0675767630
Author: James Halliday <mail at substack.net>
Date:   Sun Feb 17 14:34:16 2013 +1000

    differentiate between implicit and exported globals
---
 example/detect.js |  2 +-
 example/src.js    |  9 +++++++++
 index.js          | 18 +++++++++++++++---
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/example/detect.js b/example/detect.js
index e04db0e..2ca21eb 100644
--- a/example/detect.js
+++ b/example/detect.js
@@ -4,4 +4,4 @@ var src = fs.readFileSync(__dirname + '/src.js');
 
 var scope = detect(src);
 console.dir(scope.globals);
-console.dir(scope.locals);
+//console.dir(scope.locals);
diff --git a/example/src.js b/example/src.js
index df1213d..ff45a92 100644
--- a/example/src.js
+++ b/example/src.js
@@ -1,7 +1,14 @@
 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) {
@@ -9,9 +16,11 @@ foo(function () {
         var xyz = 4;
         x += 10;
         x.zzzzzz;
+        ZZZ=6;
     });
     function doom () {
     }
+    ZZZ.foo();
 
 });
 
diff --git a/index.js b/index.js
index 2575b44..97f496a 100644
--- a/index.js
+++ b/index.js
@@ -2,7 +2,8 @@ var falafel = require('falafel');
 
 module.exports = function (src) {
     var locals = {};
-    var globals = {};
+    var implicit = {};
+    var exported = {};
     
     falafel(String(src), function (node) {
         if (node.type === 'VariableDeclaration') {
@@ -26,11 +27,22 @@ module.exports = function (src) {
             
             if (isFunction(node.parent)) return;
             
-            globals[node.name] = true;
+            if (node.parent.type === 'AssignmentExpression') {
+                exported[node.name] = true;
+            }
+            if (!exported[node.name]) {
+                implicit[node.name] = true;
+            }
         }
     });
     
-    return { locals: locals, globals: globals };
+    return {
+        locals: locals,
+        globals: {
+            implicit: Object.keys(implicit),
+            exported: Object.keys(exported)
+        }
+    };
     
     function lookup (node) {
         for (var p = node; p; p = p.parent) {

-- 
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