aboutsummaryrefslogtreecommitdiff
path: root/tmp/test-node.js
blob: 01ae35a7d4a052ac31fe8610edcec70df8d6d879 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /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."); }
};