aboutsummaryrefslogtreecommitdiff
path: root/test/compress/issue-1034.js
blob: 039af2ed5b3e19d422596f1e2698d0e0ad97e42d (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
non_hoisted_function_after_return: {
    options = {
        hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
        evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
        if_return: true, join_vars: true, cascade: true, side_effects: true
    }
    input: {
        function foo(x) {
            if (x) {
                return bar();
                not_called1();
            } else {
                return baz();
                not_called2();
            }
            function bar() { return 7; }
            return not_reached;
            function UnusedFunction() {}
            function baz() { return 8; }
        }
    }
    expect: {
        function foo(x) {
            return x ? bar() : baz();
            function bar() { return 7 }
            function baz() { return 8 }
        }
    }
    expect_warnings: [
        'WARN: Dropping unreachable code [test/compress/issue-1034.js:11,16]',
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:14,16]",
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:17,12]",
        "WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:18,21]"
    ]
}

non_hoisted_function_after_return_2a: {
    options = {
        hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
        evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
        if_return: true, join_vars: true, cascade: true, side_effects: true,
        collapse_vars: false
    }
    input: {
        function foo(x) {
            if (x) {
                return bar(1);
                var a = not_called(1);
            } else {
                return bar(2);
                var b = not_called(2);
            }
            var c = bar(3);
            function bar(x) { return 7 - x; }
            function nope() {}
            return b || c;
        }
    }
    expect: {
        // NOTE: Output is correct, but suboptimal. Not a regression. Can be improved in future.
        //       This output is run through non_hoisted_function_after_return_2b with same flags.
        function foo(x) {
            if (x) {
                return bar(1);
            } else {
                return bar(2);
                var b;
            }
            var c = bar(3);
            function bar(x) {
                return 7 - x;
            }
            return b || c;
        }
    }
    expect_warnings: [
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:48,16]",
        "WARN: Declarations in unreachable code! [test/compress/issue-1034.js:48,16]",
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:51,16]",
        "WARN: Declarations in unreachable code! [test/compress/issue-1034.js:51,16]",
        "WARN: Dropping unused variable a [test/compress/issue-1034.js:48,20]",
        "WARN: Dropping unused function nope [test/compress/issue-1034.js:55,21]"
    ]
}

non_hoisted_function_after_return_2b: {
    options = {
        hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
        evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
        if_return: true, join_vars: true, cascade: true, side_effects: true,
        collapse_vars: false
    }
    input: {
        // Note: output of test non_hoisted_function_after_return_2a run through compress again
        function foo(x) {
            if (x) {
                return bar(1);
            } else {
                return bar(2);
                var b;
            }
            var c = bar(3);
            function bar(x) {
                return 7 - x;
            }
            return b || c;
        }
    }
    expect: {
        // the output we would have liked to see from non_hoisted_function_after_return_2a
        function foo(x) {
            return bar(x ? 1 : 2);
            function bar(x) { return 7 - x; }
        }
    }
    expect_warnings: [
        // Notice that some warnings are repeated by multiple compress passes.
        // Not a regression. There is room for improvement here.
        // Warnings should be cached and only output if unique.
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:100,16]",
        "WARN: Declarations in unreachable code! [test/compress/issue-1034.js:100,16]",
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:100,16]",
        "WARN: Declarations in unreachable code! [test/compress/issue-1034.js:100,16]",
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:100,16]",
        "WARN: Declarations in unreachable code! [test/compress/issue-1034.js:100,16]",
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:100,16]",
        "WARN: Declarations in unreachable code! [test/compress/issue-1034.js:100,16]",
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:102,12]",
        "WARN: Declarations in unreachable code! [test/compress/issue-1034.js:102,12]",
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:106,12]",
        "WARN: Dropping unreachable code [test/compress/issue-1034.js:100,16]",
        "WARN: Declarations in unreachable code! [test/compress/issue-1034.js:100,16]",
        "WARN: Dropping unused variable b [test/compress/issue-1034.js:100,20]",
        "WARN: Dropping unused variable c [test/compress/issue-1034.js:102,16]"
    ]
}