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

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

[elpa] master 6cd2827 044/271: Cleanup old scopifier.


From: Jackson Ray Hamilton
Subject: [elpa] master 6cd2827 044/271: Cleanup old scopifier.
Date: Thu, 05 Feb 2015 18:29:39 +0000

branch: master
commit 6cd28275ae4328c418c302f0c3f602fad32a2093
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Cleanup old scopifier.
---
 context-coloring.el  |    6 +-
 package.json         |    3 +-
 scopifier-esprima.js |  123 -------------------------------------------------
 scopifier.js         |  124 ++++++++++++++++++++++++++++++++++++++++----------
 4 files changed, 103 insertions(+), 153 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index 98edb8b..82708e4 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -127,7 +127,7 @@ For example: \"context-coloring-depth-1-face\"."
   "This file's directory.")
 
 (defconst context-coloring-scopifier-path
-  (expand-file-name "./scopifier-esprima.js" context-coloring-path)
+  (expand-file-name "./scopifier.js" context-coloring-path)
   "Path to the external scopifier executable.")
 
 (defconst context-coloring-delay 0.25
@@ -193,7 +193,7 @@ calling FUNCTION with the parsed list of tokens."
                                 (with-current-buffer buffer
                                   (context-coloring-apply-tokens tokens))
                                 (setq context-coloring-scopifier-process nil)
-                                (message "Colorized (after %f seconds)." (- 
(float-time) start-time))
+                                ;; (message "Colorized (after %f seconds)." (- 
(float-time) start-time))
                                 )))))
 
   ;; Give the process its input.
@@ -206,7 +206,7 @@ calling FUNCTION with the parsed list of tokens."
 (defun context-coloring-colorize ()
   (interactive)
   (setq context-coloring-colorize-start-time (float-time))
-  (message "%s" "Colorizing.")
+  ;; (message "%s" "Colorizing.")
   (context-coloring-scopify))
 
 (defun context-coloring-change-function (start end length)
diff --git a/package.json b/package.json
index 09d3be2..8d3982a 100644
--- a/package.json
+++ b/package.json
@@ -25,7 +25,6 @@
   },
   "dependencies": {
     "escope": "^1.0.1",
-    "esprima": "^1.2.2",
-    "uglify-js": "^2.4.15"
+    "esprima": "^1.2.2"
   }
 }
diff --git a/scopifier-esprima.js b/scopifier-esprima.js
deleted file mode 100644
index 29bdc85..0000000
--- a/scopifier-esprima.js
+++ /dev/null
@@ -1,123 +0,0 @@
-/*jslint node: true */
-
-'use strict';
-
-var escope = require('escope'),
-    esprima = require('esprima'),
-    whole = '';
-
-process.stdin.setEncoding('utf8');
-
-process.stdin.on('readable', function () {
-    var chunk = process.stdin.read();
-    if (chunk !== null) {
-        whole += chunk;
-    }
-});
-
-process.stdin.on('end', function () {
-    var ast,
-        analyzedScopes,
-        scopes = [],
-        symbols = [],
-        comments = [],
-        emacsified;
-
-    // Gracefully handle parse errors by doing nothing.
-    try {
-        ast = esprima.parse(whole, {
-            comment: true,
-            range: true
-        });
-        analyzedScopes = escope.analyze(ast).scopes;
-    } catch (error) {
-        process.exit(1);
-    }
-
-    analyzedScopes.forEach(function (scope) {
-        if (scope.level === undefined) {
-            if (scope.upper) {
-                if (scope.upper.functionExpressionScope) {
-                    // Pretend function expression scope doesn't exist.
-                    scope.level = scope.upper.level;
-                    scope.variables = 
scope.upper.variables.concat(scope.variables);
-                } else {
-                    scope.level = scope.upper.level + 1;
-                }
-            } else {
-                scope.level = 0;
-            }
-            if (scope.functionExpressionScope) {
-                // We've only given the scope a level for posterity's sake.
-                return;
-            }
-            scopes.push([
-                scope.level,
-                scope.block.range[0],
-                scope.block.range[1]
-            ]);
-            scope.variables.forEach(function (variable) {
-                var definitions = [],
-                    references = [];
-                variable.defs.forEach(function (definition) {
-                    var range = definition.name.range;
-                    definitions.push([
-                        scope.level,
-                        range[0],
-                        range[1]
-                    ]);
-                });
-                variable.references.forEach(function (reference) {
-                    var range = reference.identifier.range,
-                        isDefined = definitions.some(function (definition) {
-                            // Check for identical definitions.
-                            return definition[1] === range[0] &&
-                                definition[2] === range[1];
-                        });
-                    if (isDefined) {
-                        return;
-                    }
-                    references.push([
-                        scope.level,
-                        range[0],
-                        range[1]
-                    ]);
-                });
-                Array.prototype.push.apply(symbols, definitions);
-                Array.prototype.push.apply(symbols, references);
-            });
-            scope.references.forEach(function (reference) {
-                var range;
-                if (reference.resolved) {
-                    return;
-                }
-                // Handle global references.
-                range = reference.identifier.range;
-                symbols.push([
-                    0,
-                    range[0],
-                    range[1]
-                ]);
-            });
-        }
-    });
-
-    ast.comments.forEach(function (comment) {
-        var range = comment.range;
-        comments.push([
-            -1,
-            range[0],
-            range[1]
-        ]);
-    });
-
-    emacsified = scopes.concat(symbols.concat(comments));
-
-    emacsified.forEach(function (instruction) {
-        // Emacs starts counting from 1.
-        instruction[1] += 1;
-        instruction[2] += 1;
-    });
-
-    console.log(JSON.stringify(emacsified));
-});
diff --git a/scopifier.js b/scopifier.js
index 263fb54..29bdc85 100644
--- a/scopifier.js
+++ b/scopifier.js
@@ -2,7 +2,8 @@
 
 'use strict';
 
-var UglifyJS = require('uglify-js'),
+var escope = require('escope'),
+    esprima = require('esprima'),
     whole = '';
 
 process.stdin.setEncoding('utf8');
@@ -15,35 +16,108 @@ process.stdin.on('readable', function () {
 });
 
 process.stdin.on('end', function () {
-    var scopes = [],
+    var ast,
+        analyzedScopes,
+        scopes = [],
         symbols = [],
-        walker = new UglifyJS.TreeWalker(function (node) {
-            if (node instanceof UglifyJS.AST_Scope) {
-                if (node.level === undefined) {
-                    node.level = node.parent_scope ? node.parent_scope.level + 
1 : 0;
-                    scopes.push([node.level,
-                                 node.start.pos + 1,
-                                 node.end.endpos + 1]);
-                }
-            } else if (node instanceof UglifyJS.AST_Symbol) {
-                // We don't care about symbols without definitions.
-                if (node.thedef === undefined) {
-                    return;
-                }
-                symbols.push([node.thedef.scope.level,
-                              node.start.pos + 1,
-                              node.end.endpos + 1]);
-            }
-        }),
-        toplevel;
+        comments = [],
+        emacsified;
 
+    // Gracefully handle parse errors by doing nothing.
     try {
-        toplevel = UglifyJS.parse(whole);
-        toplevel.figure_out_scope();
-        toplevel.walk(walker);
+        ast = esprima.parse(whole, {
+            comment: true,
+            range: true
+        });
+        analyzedScopes = escope.analyze(ast).scopes;
     } catch (error) {
         process.exit(1);
     }
 
-    console.log(JSON.stringify(scopes.concat(symbols)));
+    analyzedScopes.forEach(function (scope) {
+        if (scope.level === undefined) {
+            if (scope.upper) {
+                if (scope.upper.functionExpressionScope) {
+                    // Pretend function expression scope doesn't exist.
+                    scope.level = scope.upper.level;
+                    scope.variables = 
scope.upper.variables.concat(scope.variables);
+                } else {
+                    scope.level = scope.upper.level + 1;
+                }
+            } else {
+                scope.level = 0;
+            }
+            if (scope.functionExpressionScope) {
+                // We've only given the scope a level for posterity's sake.
+                return;
+            }
+            scopes.push([
+                scope.level,
+                scope.block.range[0],
+                scope.block.range[1]
+            ]);
+            scope.variables.forEach(function (variable) {
+                var definitions = [],
+                    references = [];
+                variable.defs.forEach(function (definition) {
+                    var range = definition.name.range;
+                    definitions.push([
+                        scope.level,
+                        range[0],
+                        range[1]
+                    ]);
+                });
+                variable.references.forEach(function (reference) {
+                    var range = reference.identifier.range,
+                        isDefined = definitions.some(function (definition) {
+                            // Check for identical definitions.
+                            return definition[1] === range[0] &&
+                                definition[2] === range[1];
+                        });
+                    if (isDefined) {
+                        return;
+                    }
+                    references.push([
+                        scope.level,
+                        range[0],
+                        range[1]
+                    ]);
+                });
+                Array.prototype.push.apply(symbols, definitions);
+                Array.prototype.push.apply(symbols, references);
+            });
+            scope.references.forEach(function (reference) {
+                var range;
+                if (reference.resolved) {
+                    return;
+                }
+                // Handle global references.
+                range = reference.identifier.range;
+                symbols.push([
+                    0,
+                    range[0],
+                    range[1]
+                ]);
+            });
+        }
+    });
+
+    ast.comments.forEach(function (comment) {
+        var range = comment.range;
+        comments.push([
+            -1,
+            range[0],
+            range[1]
+        ]);
+    });
+
+    emacsified = scopes.concat(symbols.concat(comments));
+
+    emacsified.forEach(function (instruction) {
+        // Emacs starts counting from 1.
+        instruction[1] += 1;
+        instruction[2] += 1;
+    });
+
+    console.log(JSON.stringify(emacsified));
 });



reply via email to

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