added -m and -c options
This commit is contained in:
@@ -17,28 +17,44 @@ Use a single dash to read input from the standard input.\
|
|||||||
.describe("stats", "Display operations run time on STDERR")
|
.describe("stats", "Display operations run time on STDERR")
|
||||||
.describe("v", "Verbose")
|
.describe("v", "Verbose")
|
||||||
.describe("b", "Beautify output")
|
.describe("b", "Beautify output")
|
||||||
|
.describe("m", "Don't mangle names")
|
||||||
|
.describe("c", "Compressor options")
|
||||||
|
|
||||||
.alias("p", "prefix")
|
.alias("p", "prefix")
|
||||||
.alias("o", "output")
|
.alias("o", "output")
|
||||||
.alias("v", "verbose")
|
.alias("v", "verbose")
|
||||||
.alias("b", "beautify")
|
.alias("b", "beautify")
|
||||||
|
.alias("c", "options")
|
||||||
|
|
||||||
.boolean("b")
|
.boolean("b")
|
||||||
.boolean("v")
|
.boolean("v")
|
||||||
.boolean("stats")
|
.boolean("stats")
|
||||||
|
.boolean("m")
|
||||||
|
|
||||||
.argv
|
.argv
|
||||||
;
|
;
|
||||||
|
|
||||||
for (var i in ARGS) if (ARGS.hasOwnProperty(i) && /-/.test(i)) {
|
function normalize(o) {
|
||||||
ARGS[i.replace(/-/g, "_")] = ARGS[i];
|
for (var i in o) if (o.hasOwnProperty(i) && /-/.test(i)) {
|
||||||
|
o[i.replace(/-/g, "_")] = o[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
normalize(ARGS);
|
||||||
|
|
||||||
if (ARGS.h || ARGS.help) {
|
if (ARGS.h || ARGS.help) {
|
||||||
sys.puts(optimist.help());
|
sys.puts(optimist.help());
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var COMPRESSOR_OPTIONS = {};
|
||||||
|
if (ARGS.c) {
|
||||||
|
ARGS.c.replace(/^\s+|\s+$/g).split(/\s*,+\s*/).forEach(function(opt){
|
||||||
|
var a = opt.split(/\s*=\s*/);
|
||||||
|
COMPRESSOR_OPTIONS[a[0]] = new Function("return(" + a[1] + ")")();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var files = ARGS._.slice();
|
var files = ARGS._.slice();
|
||||||
|
|
||||||
if (files.length == 0)
|
if (files.length == 0)
|
||||||
@@ -117,7 +133,7 @@ function do_file_1(file) {
|
|||||||
ast.figure_out_scope();
|
ast.figure_out_scope();
|
||||||
});
|
});
|
||||||
time_it("squeeze", function(){
|
time_it("squeeze", function(){
|
||||||
var compressor = UglifyJS.Compressor({});
|
var compressor = UglifyJS.Compressor(COMPRESSOR_OPTIONS);
|
||||||
ast = ast.squeeze(compressor);
|
ast = ast.squeeze(compressor);
|
||||||
});
|
});
|
||||||
ast.filename = file;
|
ast.filename = file;
|
||||||
@@ -127,7 +143,9 @@ function do_file_1(file) {
|
|||||||
function do_file_2(ast) {
|
function do_file_2(ast) {
|
||||||
time_it("scope", function(){
|
time_it("scope", function(){
|
||||||
ast.figure_out_scope();
|
ast.figure_out_scope();
|
||||||
|
if (!ARGS.m) {
|
||||||
ast.compute_char_frequency();
|
ast.compute_char_frequency();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
@@ -137,7 +155,7 @@ function do_file_3(ast) {
|
|||||||
// if (ARGS.v) {
|
// if (ARGS.v) {
|
||||||
// sys.error("Mangling/generating " + file);
|
// sys.error("Mangling/generating " + file);
|
||||||
// }
|
// }
|
||||||
time_it("mangle", function(){
|
if (!ARGS.m) time_it("mangle", function(){
|
||||||
ast.mangle_names();
|
ast.mangle_names();
|
||||||
});
|
});
|
||||||
time_it("generate", function(){
|
time_it("generate", function(){
|
||||||
|
|||||||
75
tmp/todo
Normal file
75
tmp/todo
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
a = a + x ==> a+=x
|
||||||
|
|
||||||
|
*******
|
||||||
|
|
||||||
|
join consecutive var statements
|
||||||
|
|
||||||
|
*******
|
||||||
|
|
||||||
|
x == false ==> x == 0
|
||||||
|
x == true ==> x == 1
|
||||||
|
|
||||||
|
should warn too;
|
||||||
|
JS is so sloppy that this could be an indication of a bug.
|
||||||
|
|
||||||
|
*******
|
||||||
|
|
||||||
|
x, x ==> x
|
||||||
|
x = foo, x ==> x
|
||||||
|
|
||||||
|
other similar cases?
|
||||||
|
|
||||||
|
*******
|
||||||
|
|
||||||
|
Try to concatenate all scripts somehow before starting minification;
|
||||||
|
the issue will be keeping track of the current source file for
|
||||||
|
generating source maps. perhaps store that in the AST? Have a single
|
||||||
|
AST_Toplevel for all files.
|
||||||
|
|
||||||
|
XXX? Not sure if this is worth the trouble.
|
||||||
|
|
||||||
|
*******
|
||||||
|
|
||||||
|
discard spurious break statements
|
||||||
|
|
||||||
|
*******
|
||||||
|
|
||||||
|
for (...) {
|
||||||
|
if (foo) continue;
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
==>
|
||||||
|
|
||||||
|
for (...) {
|
||||||
|
if (!foo) { ... }
|
||||||
|
}
|
||||||
|
|
||||||
|
*******
|
||||||
|
|
||||||
|
The following seems to compress suboptimally. Should probably run more
|
||||||
|
passes somewhere.
|
||||||
|
|
||||||
|
function setOpacity(el, o) {
|
||||||
|
if (o != null) {
|
||||||
|
if (o == "" && o != 0) {
|
||||||
|
is_ie
|
||||||
|
? el.style.filter = ""
|
||||||
|
: el.style.opacity = "";
|
||||||
|
} else {
|
||||||
|
is_ie
|
||||||
|
? el.style.filter = "alpha(opacity=" + Math.round(o * 100) + ")"
|
||||||
|
: el.style.opacity = o;
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
} else {
|
||||||
|
if (!is_ie)
|
||||||
|
return parseFloat(el.style.opacity);
|
||||||
|
else
|
||||||
|
if (/alpha\(opacity=([0-9.])+\)/.test(el.style.opacity))
|
||||||
|
return parseFloat(RegExp.$1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*******
|
||||||
|
|
||||||
Reference in New Issue
Block a user