aboutsummaryrefslogtreecommitdiff
path: root/test/compress/issue-976.js
blob: 435335018a9868fbcdfdcc39b4b03c352bd3748d (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
138
139
140
141
142
143
eval_collapse_vars: {
    options = {
        booleans: true,
        collapse_vars: true,
        comparisons: true,
        conditionals: true,
        dead_code: true,
        evaluate: true,
        hoist_funs: true,
        if_return: true,
        join_vars: true,
        keep_fargs: true,
        loops: true,
        properties: true,
        sequences: false,
        side_effects: true,
        unused: true,
    }
    input: {
        function f1() {
            var e = 7;
            var s = "abcdef";
            var i = 2;
            var eval = console.log.bind(console);
            var x = s.charAt(i++);
            var y = s.charAt(i++);
            var z = s.charAt(i++);
            eval(x, y, z, e);
        }
        function p1() { var a = foo(), b = bar(), eval = baz(); return a + b + eval; }
        function p2() { var a = foo(), b = bar(), eval = baz; return a + b + eval(); }
        (function f2(eval) {
            var a = 2;
            console.log(a - 5);
            eval("console.log(a);");
        })(eval);
    }
    expect: {
        function f1() {
            var e = 7,
                s = "abcdef",
                i = 2,
                eval = console.log.bind(console),
                x = s.charAt(i++),
                y = s.charAt(i++),
                z = s.charAt(i++);
            eval(x, y, z, e);
        }
        function p1() { return foo() + bar() + baz(); }
        function p2() { var a = foo(), b = bar(), eval = baz; return a + b + eval(); }
        (function f2(eval) {
            var a = 2;
            console.log(a - 5);
            eval("console.log(a);");
        })(eval);
    }
    expect_stdout: true
}

eval_unused: {
    options = {
        keep_fargs: false,
        unused: true,
    }
    input: {
        function o(k) {
            return { c: 14 }[k];
        }
        console.log(function f1(a, eval, c, d, e) {
            return a("c") + eval;
        }(o, 28, true));
        console.log(function f2(a, b, c, d, e) {
            return a + eval("c");
        }(14, true, 28));
        console.log(function f3(a, eval, c, d, e) {
            return a + eval("c");
        }(28, o, true));
    }
    expect: {
        function o(k) {
            return { c: 14 }[k];
        }
        console.log(function(a, eval) {
            return a("c") + eval;
        }(o, 28));
        console.log(function f2(a, b, c, d, e) {
            return a + eval("c");
        }(14, true, 28));
        console.log(function f3(a, eval, c, d, e) {
            return a + eval("c");
        }(28, o, true));
    }
    expect_stdout: [
        "42",
        "42",
        "42",
    ]
}

eval_mangle: {
    mangle = {}
    beautify = {
        beautify: true,
    }
    input: {
        function o(k) {
            return { cc: 14 }[k + "c"];
        }
        console.log(function f1(a, eval, c, d, e) {
            return a("c") + eval;
        }(o, 28, true));
        console.log(function f2(a, b, c, d, e) {
            return a + eval("c");
        }(14, true, 28));
        console.log(function f3(a, eval, c, d, e) {
            return a + eval("c");
        }(28, o, true));
    }
    expect_exact: [
        "function o(o) {",
        "    return {",
        "        cc: 14",
        '    }[o + "c"];',
        "}",
        "",
        "console.log(function o(c, e, n, r, t) {",
        '    return c("c") + e;',
        "}(o, 28, true));",
        "",
        "console.log(function f2(a, b, c, d, e) {",
        '    return a + eval("c");',
        "}(14, true, 28));",
        "",
        "console.log(function f3(a, eval, c, d, e) {",
        '    return a + eval("c");',
        "}(28, o, true));",
    ]
    expect_stdout: [
        "42",
        "42",
        "42",
    ]
}