UglifyJS/tmp/test-node.js
Mihai Bazon 7ae1c600a2 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.)
2012-08-21 13:53:16 +03:00

33 lines
761 B
JavaScript
Executable File

#! /usr/bin/env node
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."); }
};