This commit is contained in:
Mihai Bazon
2012-08-27 11:00:26 +03:00
parent 4437e7af19
commit 8dfa9fe7e5
4 changed files with 17 additions and 10 deletions

View File

@@ -20,7 +20,7 @@ keep_some_blocks: {
// 1. // 1.
if (foo) { if (foo) {
{{{}}} {{{}}}
if (bar) baz(); if (bar) { baz(); }
{{}} {{}}
} else { } else {
stuff(); stuff();

View File

@@ -33,11 +33,17 @@ dead_code_2_should_warn: {
x = 10; x = 10;
throw "foo"; throw "foo";
// completely discarding the `if` would introduce some // completely discarding the `if` would introduce some
// bugs. UglifyJS v1 doesn't deal with this issue. // bugs. UglifyJS v1 doesn't deal with this issue; in v2
// we copy any declarations to the upper scope.
if (x) { if (x) {
y(); y();
var x; var x;
function g(){}; function g(){};
// but nested declarations should not be kept.
(function(){
var q;
function y(){};
})();
} }
} }
} }

View File

@@ -22,11 +22,11 @@ function log() {
} }
function log_directory(dir) { function log_directory(dir) {
log("--- Entering [{dir}]", { dir: dir }); log("*** Entering [{dir}]", { dir: dir });
} }
function log_start_file(file) { function log_start_file(file) {
log("*** {file}", { file: file }); log("--- {file}", { file: file });
} }
function log_test(name) { function log_test(name) {

View File

@@ -11,27 +11,28 @@ var code = fs.readFileSync(filename, "utf8");
var ast = time_it("parse", function() { var ast = time_it("parse", function() {
return UglifyJS.parse(code); return UglifyJS.parse(code);
}); });
var stream = UglifyJS.OutputStream({ beautify: true }); var stream = UglifyJS.OutputStream({ beautify: false });
time_it("scope", function(){ time_it("scope", function(){
ast.figure_out_scope(); ast.figure_out_scope();
}); });
time_it("mangle", function(){ // time_it("mangle", function(){
ast.mangle_names(); // ast.mangle_names();
}); // });
ast.scope_warnings(); //ast.scope_warnings();
time_it("compress", function(){ time_it("compress", function(){
var compressor = new UglifyJS.Compressor({ var compressor = new UglifyJS.Compressor({
}); });
ast = ast.squeeze(compressor); ast = ast.squeeze(compressor);
}); });
time_it("generate", function(){ time_it("generate", function(){
ast.print(stream); ast.print(stream);
}); });
sys.puts(stream.get()); sys.puts(stream.get());
ast.scope_warnings(); //ast.scope_warnings();
function time_it(name, cont) { function time_it(name, cont) {
var t1 = new Date().getTime(); var t1 = new Date().getTime();