aboutsummaryrefslogtreecommitdiff
path: root/tmp/test-node.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-08-20 17:19:30 +0300
committerMihai Bazon <mihai@bazon.net>2012-08-20 17:32:35 +0300
commit458e251d7ed6e9ac97849237264caa40a40c76b3 (patch)
treec342018676bce94131d20ee33e06666d991a9480 /tmp/test-node.js
parent1fe0ff9fff86b5d5fba3f4d1499479d2f23511df (diff)
downloadtracifyjs-458e251d7ed6e9ac97849237264caa40a40c76b3.tar.gz
tracifyjs-458e251d7ed6e9ac97849237264caa40a40c76b3.zip
added mangler and other stuff
Diffstat (limited to 'tmp/test-node.js')
-rwxr-xr-xtmp/test-node.js77
1 files changed, 46 insertions, 31 deletions
diff --git a/tmp/test-node.js b/tmp/test-node.js
index 3c3d7b56..a80d0935 100755
--- a/tmp/test-node.js
+++ b/tmp/test-node.js
@@ -22,43 +22,58 @@
load_global("../lib/scope.js");
load_global("../lib/output.js");
+ AST_Node.warn_function = function(txt) {
+ sys.debug(txt);
+ };
+
///
var filename = process.argv[2];
- console.time("parse");
- var ast = parse(fs.readFileSync(filename, "utf8"));
- console.timeEnd("parse");
+ var code = fs.readFileSync(filename, "utf8");
+ var ast = time_it("parse", function() {
+ return parse(code);
+ });
var stream = OutputStream({ beautify: true });
- console.time("figure_out_scope");
- ast.figure_out_scope();
- console.timeEnd("figure_out_scope");
- console.time("generate");
- ast.print(stream);
- console.timeEnd("generate");
- //sys.puts(stream.get());
+ 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);
- 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."); }
+ };
})();