]> code.delx.au - gnu-emacs-elpa/commitdiff
Restore test files. Start on uglify tokenizer.
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Thu, 20 Nov 2014 16:35:57 +0000 (08:35 -0800)
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Thu, 20 Nov 2014 16:35:57 +0000 (08:35 -0800)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
package.json [new file with mode: 0644]
scopify.js [new file with mode: 0644]
test/context-coloring-test.el [new file with mode: 0644]
test/fixtures/monad.js [new file with mode: 0644]
test/scopify.js [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b7ec7e5
--- /dev/null
@@ -0,0 +1,3 @@
+*.elc
+*.log
+node_modules/
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..8b142f2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+all:
+       exit
+
+test:
+       mocha
+       emacs -batch -l ert -l test/context-coloring-test.el -f ert-run-tests-batch-and-exit
+
+.PHONY: all test clean
diff --git a/package.json b/package.json
new file mode 100644 (file)
index 0000000..c5cd241
--- /dev/null
@@ -0,0 +1,29 @@
+{
+  "name": "context-coloring",
+  "version": "0.0.0",
+  "description": "JavaScript syntax highlighting for grown-ups.",
+  "main": "index.js",
+  "directories": {
+    "test": "test"
+  },
+  "scripts": {
+    "test": "make test"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/jacksonrayhamilton/context-coloring.git"
+  },
+  "author": "Jackson Ray Hamilton",
+  "license": "GPL-3.0+",
+  "bugs": {
+    "url": "https://github.com/jacksonrayhamilton/context-coloring/issues"
+  },
+  "homepage": "https://github.com/jacksonrayhamilton/context-coloring",
+  "devDependencies": {
+    "matcha": "^0.6.0",
+    "mocha": "^2.0.1"
+  },
+  "dependencies": {
+    "uglify-js": "^2.4.15"
+  }
+}
diff --git a/scopify.js b/scopify.js
new file mode 100644 (file)
index 0000000..1d21142
--- /dev/null
@@ -0,0 +1,51 @@
+/*jslint node: true */
+
+'use strict';
+
+var UglifyJS = require('uglify-js'),
+    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 scopes = [],
+        symbols = [],
+        toplevel = UglifyJS.parse(whole),
+        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,
+                                 node.end.endpos]);
+                }
+            } else if (node instanceof UglifyJS.AST_Symbol) {
+                symbols.push([node.thedef.scope.level,
+                              node.start.pos,
+                              node.end.endpos]);
+            }
+        });
+    toplevel.figure_out_scope();
+    toplevel.walk(walker);
+    console.log('scopes', scopes);
+    console.log('symbols', symbols);
+    // TODO: Flatten a monad.
+    // scopes [ [ 0, 0, 206 ], [ 1, 0, 206 ], [ 2, 30, 203 ], [ 3, 115, 174 ] ]
+    // symbols [ [ 0, 9, 14 ],
+    //   [ 2, 39, 43 ],
+    //   [ 2, 44, 49 ],
+    //   [ 2, 65, 70 ],
+    //   [ 0, 73, 79 ],
+    //   [ 2, 102, 107 ],
+    //   [ 3, 125, 129 ],
+    //   [ 3, 152, 156 ],
+    //   [ 2, 157, 162 ],
+    //   [ 2, 191, 196 ] ]
+});
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
new file mode 100644 (file)
index 0000000..7bd0b2c
--- /dev/null
@@ -0,0 +1,3 @@
+(ert-deftest context-coloring-test-color ()
+  "Tests something. Not sure what yet."
+  (should (equal t t)))
diff --git a/test/fixtures/monad.js b/test/fixtures/monad.js
new file mode 100644 (file)
index 0000000..4a2e19c
--- /dev/null
@@ -0,0 +1,9 @@
+function MONAD() {
+    return function unit(value) {
+        var monad = Object.create(null);
+        monad.bind = function (func) {
+            return func(value);
+        };
+        return monad;
+    };
+}
diff --git a/test/scopify.js b/test/scopify.js
new file mode 100644 (file)
index 0000000..4525199
--- /dev/null
@@ -0,0 +1,16 @@
+/*jslint node: true */
+/*global describe, it */
+
+'use strict';
+
+var assert = require('assert');
+
+describe('scopify', function () {
+
+    it('should work', function () {
+
+        assert.strictEqual(true, true);
+
+    });
+
+});