2012-05-27 11:36:51 +00:00
|
|
|
#! /usr/bin/env node
|
|
|
|
|
|
2012-08-21 09:55:56 +00:00
|
|
|
var sys = require("util");
|
|
|
|
|
var fs = require("fs");
|
|
|
|
|
|
2012-08-22 12:21:58 +00:00
|
|
|
var UglifyJS = require("../tools/node");
|
2012-08-21 09:55:56 +00:00
|
|
|
|
|
|
|
|
var filename = process.argv[2];
|
|
|
|
|
var code = fs.readFileSync(filename, "utf8");
|
|
|
|
|
|
|
|
|
|
var ast = time_it("parse", function() {
|
|
|
|
|
return UglifyJS.parse(code);
|
|
|
|
|
});
|
2012-08-27 08:48:07 +00:00
|
|
|
|
2012-08-21 09:55:56 +00:00
|
|
|
time_it("scope", function(){
|
2012-08-27 08:48:07 +00:00
|
|
|
// calling figure_out_scope is a prerequisite for mangle_names,
|
|
|
|
|
// scope_warnings and compress
|
|
|
|
|
//
|
|
|
|
|
// perhaps figure_out_scope should be called automatically by the
|
|
|
|
|
// parser, but there might be instances where the functionality is
|
|
|
|
|
// not needed.
|
2012-08-21 09:55:56 +00:00
|
|
|
ast.figure_out_scope();
|
|
|
|
|
});
|
2012-08-21 17:06:57 +00:00
|
|
|
|
2012-09-04 12:36:14 +00:00
|
|
|
ast.scope_warnings();
|
2012-08-27 08:48:07 +00:00
|
|
|
|
|
|
|
|
time_it("mangle", function(){
|
|
|
|
|
ast.mangle_names();
|
|
|
|
|
});
|
2012-08-21 17:06:57 +00:00
|
|
|
|
2012-08-21 12:45:05 +00:00
|
|
|
time_it("compress", function(){
|
|
|
|
|
var compressor = new UglifyJS.Compressor({
|
2012-08-27 08:48:07 +00:00
|
|
|
// sequences : true,
|
|
|
|
|
// properties : true,
|
|
|
|
|
// dead_code : true,
|
|
|
|
|
// keep_comps : true,
|
|
|
|
|
// drop_debugger : true,
|
|
|
|
|
// unsafe : true,
|
|
|
|
|
// warnings : true
|
2012-08-21 12:45:05 +00:00
|
|
|
});
|
|
|
|
|
ast = ast.squeeze(compressor);
|
|
|
|
|
});
|
2012-08-27 08:00:26 +00:00
|
|
|
|
2012-09-05 08:31:02 +00:00
|
|
|
var stream = UglifyJS.OutputStream({ beautify: true });
|
2012-08-21 09:55:56 +00:00
|
|
|
time_it("generate", function(){
|
|
|
|
|
ast.print(stream);
|
|
|
|
|
});
|
|
|
|
|
sys.puts(stream.get());
|
|
|
|
|
|
|
|
|
|
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."); }
|
|
|
|
|
};
|