The following nodes were instances of AST_BlockStatement: AST_Scope, AST_SwitchBlock, AST_SwitchBranch. Also, AST_Try, AST_Catch, AST_Finally were having a body instanceof AST_BlockStatement. Overloading the meaning of AST_BlockStatement this way turned out to be a mess; we now have an AST_Block class that is the base class for things having a block of statements (might or might not be bracketed). The `this.body` of AST_Scope, AST_Try, AST_Catch, AST_Finally is now an array of statements (as they inherit from AST_Block). Avoiding calling superclass's _walk function in walkers (turns out we walked a node multiple times).
55 lines
1.4 KiB
JavaScript
Executable File
55 lines
1.4 KiB
JavaScript
Executable File
#! /usr/bin/env node
|
|
|
|
var sys = require("util");
|
|
var fs = require("fs");
|
|
|
|
var UglifyJS = require("../tools/node");
|
|
|
|
var filename = process.argv[2];
|
|
var code = fs.readFileSync(filename, "utf8");
|
|
|
|
var ast = time_it("parse", function() {
|
|
return UglifyJS.parse(code);
|
|
});
|
|
|
|
time_it("scope", function(){
|
|
// 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.
|
|
ast.figure_out_scope();
|
|
});
|
|
|
|
ast.scope_warnings();
|
|
|
|
time_it("mangle", function(){
|
|
ast.mangle_names();
|
|
});
|
|
|
|
time_it("compress", function(){
|
|
var compressor = new UglifyJS.Compressor({
|
|
// sequences : true,
|
|
// properties : true,
|
|
// dead_code : true,
|
|
// keep_comps : true,
|
|
// drop_debugger : true,
|
|
// unsafe : true,
|
|
// warnings : true
|
|
});
|
|
ast = ast.squeeze(compressor);
|
|
});
|
|
|
|
var stream = UglifyJS.OutputStream({ beautify: true });
|
|
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."); }
|
|
};
|