Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80728 views
1
dead_code_1: {
2
options = {
3
dead_code: true
4
};
5
input: {
6
function f() {
7
a();
8
b();
9
x = 10;
10
return;
11
if (x) {
12
y();
13
}
14
}
15
}
16
expect: {
17
function f() {
18
a();
19
b();
20
x = 10;
21
return;
22
}
23
}
24
}
25
26
dead_code_2_should_warn: {
27
options = {
28
dead_code: true
29
};
30
input: {
31
function f() {
32
g();
33
x = 10;
34
throw "foo";
35
// completely discarding the `if` would introduce some
36
// bugs. UglifyJS v1 doesn't deal with this issue; in v2
37
// we copy any declarations to the upper scope.
38
if (x) {
39
y();
40
var x;
41
function g(){};
42
// but nested declarations should not be kept.
43
(function(){
44
var q;
45
function y(){};
46
})();
47
}
48
}
49
}
50
expect: {
51
function f() {
52
g();
53
x = 10;
54
throw "foo";
55
var x;
56
function g(){};
57
}
58
}
59
}
60
61
dead_code_constant_boolean_should_warn_more: {
62
options = {
63
dead_code : true,
64
loops : true,
65
booleans : true,
66
conditionals : true,
67
evaluate : true
68
};
69
input: {
70
while (!((foo && bar) || (x + "0"))) {
71
console.log("unreachable");
72
var foo;
73
function bar() {}
74
}
75
for (var x = 10; x && (y || x) && (!typeof x); ++x) {
76
asdf();
77
foo();
78
var moo;
79
}
80
}
81
expect: {
82
var foo;
83
function bar() {}
84
// nothing for the while
85
// as for the for, it should keep:
86
var x = 10;
87
var moo;
88
}
89
}
90
91