UglifyJS/tmp/test-node.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2012-05-27 11:36:51 +00:00
#! /usr/bin/env node
2012-05-27 14:25:31 +00:00
(function(){
2012-05-27 11:36:51 +00:00
2012-05-27 14:25:31 +00:00
var fs = require("fs");
var vm = require("vm");
var sys = require("util");
2012-05-27 11:36:51 +00:00
2012-05-27 14:25:31 +00:00
function load_global(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);
}
2012-05-27 14:25:31 +00:00
};
2012-05-27 11:36:51 +00:00
load_global("../lib/utils.js");
load_global("../lib/ast.js");
load_global("../lib/parse.js");
load_global("../lib/output.js");
2012-05-27 11:36:51 +00:00
2012-05-27 14:25:31 +00:00
///
2012-05-27 11:36:51 +00:00
2012-05-27 14:25:31 +00:00
var filename = process.argv[2];
//console.time("parse");
2012-05-27 14:25:31 +00:00
var ast = parse(fs.readFileSync(filename, "utf8"));
//console.timeEnd("parse");
2012-05-27 14:25:31 +00:00
//console.time("generate");
var stream = OutputStream({ beautify: true });
ast.print(stream);
//console.timeEnd("generate");
sys.puts(stream.get());
2012-08-16 15:11:04 +00:00
// console.time("walk");
// var w = new TreeWalker(function(node){
// console.log(node.TYPE + " [ start: " + node.start.line + ":" + node.start.col + ", end: " + node.end.line + ":" + node.end.col + "] " + node.name);
// });
// ast.walk(w);
// console.timeEnd("walk");
//console.log(JSON.stringify(ast));
2012-05-27 14:25:31 +00:00
})();