emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 397ef04 005/271: Detect globals.


From: Jackson Ray Hamilton
Subject: [elpa] master 397ef04 005/271: Detect globals.
Date: Thu, 05 Feb 2015 18:29:21 +0000

branch: master
commit 397ef04ca3999a4070fbad48c0a153696e31087d
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Detect globals.
---
 tokenizer/cli.js |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/tokenizer/cli.js b/tokenizer/cli.js
index 457ca74..9ac8262 100644
--- a/tokenizer/cli.js
+++ b/tokenizer/cli.js
@@ -16,16 +16,37 @@ process.stdin.on('readable', function () {
 });
 
 process.stdin.on('end', function () {
-    var tokens;
+    var data, tokens;
 
     // Generate a syntax tree for the input.
     JSLINT(whole);
+    data = JSLINT.data();
 
     // Minimize an otherwise-circular structure.
-    tokens = JSLINT.data().tokens.map(function (token) {
+    tokens = data.tokens.map(function (token) {
+        var origin = token,
+            level;
+
+        // We always consider the function keyword to be "part" of the scope it
+        // creates, even if the name leaks in the case of function statements.
+        if (token.kind !== 'function') {
+            // Find a variable/parameter's origin.
+            while (origin.master) {
+                origin = origin.master;
+            }
+        }
+
+        // Globality is not indicated by origin function.
+        if (token.kind !== 'function' &&
+                data.global.indexOf(token.string) > -1) {
+            level = 0;
+        } else {
+            level = origin.function.level;
+        }
+
         return {
             from: token.from,
-            level: token.function.level,
+            level: level,
             line: token.line,
             thru: token.thru
         };



reply via email to

[Prev in Thread] Current Thread [Next in Thread]