aboutsummaryrefslogtreecommitdiff
path: root/tmp/test-node.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-08-21 12:55:56 +0300
committerMihai Bazon <mihai@bazon.net>2012-08-21 13:53:16 +0300
commit7ae1c600a24e2f43feb839c5fd1625f6261751b5 (patch)
treeabe06f041accc5dc0a4d277ae29612f2ee5af080 /tmp/test-node.js
parent92bd53b513c6cf030d96ed627efc50dd1875ba85 (diff)
downloadtracifyjs-7ae1c600a24e2f43feb839c5fd1625f6261751b5.tar.gz
tracifyjs-7ae1c600a24e2f43feb839c5fd1625f6261751b5.zip
some reorganization
(moved pretty much everything that relates to scope in scope.js, added a module for NodeJS that can be used with require() and exports everything.)
Diffstat (limited to 'tmp/test-node.js')
-rwxr-xr-xtmp/test-node.js109
1 files changed, 30 insertions, 79 deletions
diff --git a/tmp/test-node.js b/tmp/test-node.js
index b78fccbc..01716ad6 100755
--- a/tmp/test-node.js
+++ b/tmp/test-node.js
@@ -1,81 +1,32 @@
#! /usr/bin/env node
-(function(){
-
- var fs = require("fs");
- var vm = require("vm");
- var sys = require("util");
- var path = require("path");
-
- function load_global(file) {
- file = path.resolve(path.dirname(module.filename), file);
- try {
- var code = fs.readFileSync(file, "utf8");
- return vm.runInThisContext(code, file);
- } catch(ex) {
- sys.debug("ERROR in file: " + file + " / " + ex);
- process.exit(1);
- }
- };
-
- load_global("../lib/utils.js");
- load_global("../lib/ast.js");
- load_global("../lib/parse.js");
- load_global("../lib/scope.js");
- load_global("../lib/output.js");
-
- AST_Node.warn_function = function(txt) {
- sys.debug(txt);
- };
-
- ///
-
- var filename = process.argv[2];
- var code = fs.readFileSync(filename, "utf8");
-
- var ast = time_it("parse", function() {
- return parse(code);
- });
- var stream = OutputStream({ beautify: true });
- time_it("scope", function(){
- ast.figure_out_scope();
- });
- time_it("mangle", function(){
- ast.mangle_names();
- });
- time_it("generate", function(){
- ast.print(stream);
- });
- sys.puts(stream.get());
-
- // var w = new TreeWalker(function(node, descend){
- // if (node.start) {
- // console.log(node.TYPE + " [" + node.start.line + ":" + node.start.col + "]");
- // } else {
- // console.log(node.TYPE + " [NO START]");
- // }
- // if (node instanceof AST_Scope) {
- // if (node.uses_eval) console.log("!!! uses eval");
- // if (node.uses_with) console.log("!!! uses with");
- // }
- // if (node instanceof AST_SymbolDeclaration) {
- // console.log("--- declaration " + node.name + (node.global ? " [global]" : ""));
- // }
- // else if (node instanceof AST_SymbolRef) {
- // console.log("--- reference " + node.name + " to " + (node.symbol ? node.symbol.name : "global"));
- // if (node.symbol) {
- // console.log(" declaration at: " + node.symbol.start.line + ":" + node.symbol.start.col);
- // }
- // }
- // });
- // ast._walk(w);
-
- ast.scope_warnings();
-
- function time_it(name, cont) {
- var t1 = new Date().getTime();
- try { return cont(); }
- finally { sys.debug("// " + name + ": " + ((new Date().getTime() - t1) / 1000).toFixed(3) + " sec."); }
- };
-
-})();
+var sys = require("util");
+var fs = require("fs");
+
+var UglifyJS = require("../tools/node.js");
+
+var filename = process.argv[2];
+var code = fs.readFileSync(filename, "utf8");
+
+var ast = time_it("parse", function() {
+ return UglifyJS.parse(code);
+});
+var stream = UglifyJS.OutputStream({ beautify: true });
+time_it("scope", function(){
+ ast.figure_out_scope();
+});
+time_it("mangle", function(){
+ ast.mangle_names();
+});
+time_it("generate", function(){
+ ast.print(stream);
+});
+sys.puts(stream.get());
+
+ast.scope_warnings();
+
+function time_it(name, cont) {
+ var t1 = new Date().getTime();
+ try { return cont(); }
+ finally { sys.debug("// " + name + ": " + ((new Date().getTime() - t1) / 1000).toFixed(3) + " sec."); }
+};