- Make let, const, and class symbols be declared in a block scope. - Piggy back on existing catch symbol implementation to get block-aware mangling working - Make sure unused block-scoped declarations can be dropped - Don't eliminate a block if it has a block-scoped declaration - Remove silly empty anonymous blocks left over from drop_unused - AST_Toplevel now gets to call drop_unused too, since block-scoped variables aren't global! - Don't consider block declarations global
112 lines
2.4 KiB
JavaScript
112 lines
2.4 KiB
JavaScript
dead_code_1: {
|
|
options = {
|
|
dead_code: true
|
|
};
|
|
input: {
|
|
function f() {
|
|
a();
|
|
b();
|
|
x = 10;
|
|
return;
|
|
if (x) {
|
|
y();
|
|
}
|
|
}
|
|
}
|
|
expect: {
|
|
function f() {
|
|
a();
|
|
b();
|
|
x = 10;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
dead_code_2_should_warn: {
|
|
options = {
|
|
dead_code: true
|
|
};
|
|
input: {
|
|
function f() {
|
|
g();
|
|
x = 10;
|
|
throw "foo";
|
|
// completely discarding the `if` would introduce some
|
|
// bugs. UglifyJS v1 doesn't deal with this issue; in v2
|
|
// we copy any declarations to the upper scope.
|
|
if (x) {
|
|
y();
|
|
var x;
|
|
function g(){};
|
|
// but nested declarations should not be kept.
|
|
(function(){
|
|
var q;
|
|
function y(){};
|
|
})();
|
|
}
|
|
}
|
|
}
|
|
expect: {
|
|
function f() {
|
|
g();
|
|
x = 10;
|
|
throw "foo";
|
|
var x;
|
|
function g(){};
|
|
}
|
|
}
|
|
}
|
|
|
|
dead_code_constant_boolean_should_warn_more: {
|
|
options = {
|
|
dead_code : true,
|
|
loops : true,
|
|
booleans : true,
|
|
conditionals : true,
|
|
evaluate : true
|
|
};
|
|
input: {
|
|
while (!((foo && bar) || (x + "0"))) {
|
|
console.log("unreachable");
|
|
var foo;
|
|
function bar() {}
|
|
}
|
|
for (var x = 10, y; x && (y || x) && (!typeof x); ++x) {
|
|
asdf();
|
|
foo();
|
|
var moo;
|
|
}
|
|
}
|
|
expect: {
|
|
var foo;
|
|
function bar() {}
|
|
// nothing for the while
|
|
// as for the for, it should keep:
|
|
var x = 10, y;
|
|
var moo;
|
|
}
|
|
}
|
|
|
|
dead_code_block_decls_die: {
|
|
options = {
|
|
dead_code : true,
|
|
conditionals : true,
|
|
booleans : true,
|
|
evaluate : true
|
|
};
|
|
input: {
|
|
if (0) {
|
|
let foo = 6;
|
|
const bar = 12;
|
|
class Baz {};
|
|
var qux;
|
|
}
|
|
console.log(foo, bar, Baz);
|
|
}
|
|
expect: {
|
|
var qux;
|
|
console.log(foo, bar, Baz);
|
|
}
|
|
}
|