[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));
});
- [elpa] master 099e8c1 003/271: Write basic tokenizer cli., (continued)
- [elpa] master 099e8c1 003/271: Write basic tokenizer cli., Jackson Ray Hamilton, 2015/02/05
- [elpa] master fef44f5 038/271: Fix broken link., Jackson Ray Hamilton, 2015/02/05
- [elpa] master e4ee2ec 042/271: Catch parse errors., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d372de1 029/271: Clean up cruft., Jackson Ray Hamilton, 2015/02/05
- [elpa] master b1b7f9d 032/271: Optimize tokens by connecting tail ends., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 2cdd91e 043/271: Write new scopifier with comment detection., Jackson Ray Hamilton, 2015/02/05
- [elpa] master eb14005 041/271: Rename scopify to scopifier. Use vectors., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f482c62 035/271: Use remove-text-properties as a temporary comment fix., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 615163a 045/271: Update screenshot., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f4e075f 047/271: Readme updates., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 6cd2827 044/271: Cleanup old scopifier.,
Jackson Ray Hamilton <=
- [elpa] master 2b8bc05 052/271: Remove buggy tail optimization. Move stdin cruft to cli., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f75af43 036/271: Fix installation instructions., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d881130 049/271: Rename test., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 40c9d93 048/271: Readme updates., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 348b4ca 056/271: Teeny., Jackson Ray Hamilton, 2015/02/05
- [elpa] master c9a7a2d 050/271: Add tail-end optimization., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d2114ae 053/271: Remove indentation level., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 028370d 054/271: Refactor to be more functional., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 0e64e85 055/271: Simplify to 2 arrays., Jackson Ray Hamilton, 2015/02/05
- [elpa] master ff988f3 051/271: Fix duplicate tokens and tail-end bug., Jackson Ray Hamilton, 2015/02/05