aboutsummaryrefs
aboutsummaryrefslogtreecommitdiff
path: root/test/compress/issue-1261.js
blob: 284cc28687d0e1975727b75cbc687ac873e56fd1 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
pure_function_calls: {
    options = {
        booleans: true,
        comparisons: true,
        conditionals: true,
        evaluate: true,
        if_return: true,
        join_vars: true,
        negate_iife: true,
        side_effects: true,
        unused: true,
    }
    input: {
        // pure top-level IIFE will be dropped
        // @__PURE__ - comment
        (function() {
            console.log("iife0");
        })();

        // pure top-level IIFE assigned to unreferenced var will not be dropped
        var iife1 = /*@__PURE__*/(function() {
            console.log("iife1");
            function iife1() {}
            return iife1;
        })();

        (function(){
            // pure IIFE in function scope assigned to unreferenced var will be dropped
            var iife2 = /*#__PURE__*/(function() {
                console.log("iife2");
                function iife2() {}
                return iife2;
            })();
        })();

        // comment #__PURE__ comment
        bar(), baz(), quux();
        a.b(), /* @__PURE__ */ c.d.e(), f.g();
    }
    expect: {
        var iife1 = function() {
            console.log("iife1");
            function iife1() {}
            return iife1;
        }();

        baz(), quux();
        a.b(), f.g();
    }
    expect_warnings: [
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
        "WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
        "WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
        "WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,8]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:25,31]",
    ]
}

pure_function_calls_toplevel: {
    options = {
        booleans: true,
        comparisons: true,
        conditionals: true,
        evaluate: true,
        if_return: true,
        join_vars: true,
        negate_iife: true,
        side_effects: true,
        toplevel: true,
        unused: true,
    }
    input: {
        // pure top-level IIFE will be dropped
        // @__PURE__ - comment
        (function() {
            console.log("iife0");
        })();

        // pure top-level IIFE assigned to unreferenced var will be dropped
        var iife1 = /*@__PURE__*/(function() {
            console.log("iife1");
            function iife1() {}
            return iife1;
        })();

        (function(){
            // pure IIFE in function scope assigned to unreferenced var will be dropped
            var iife2 = /*#__PURE__*/(function() {
                console.log("iife2");
                function iife2() {}
                return iife2;
            })();
        })();

        // pure top-level calls will be dropped regardless of the leading comments position
        var MyClass = /*#__PURE__*//*@class*/(function(){
            function MyClass() {}
            MyClass.prototype.method = function() {};
            return MyClass;
        })();

        // comment #__PURE__ comment
        bar(), baz(), quux();
        a.b(), /* @__PURE__ */ c.d.e(), f.g();
    }
    expect: {
        baz(), quux();
        a.b(), f.g();
    }
    expect_warnings: [
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
        "WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
        "WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
        "WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:31,8]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:32,31]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,33]",
        "WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:8,12]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,45]",
        "WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:24,12]",
    ]
}

should_warn: {
    options = {
        booleans: true,
        conditionals: true,
        evaluate: true,
        side_effects: true,
    }
    input: {
        /* @__PURE__ */(function(){x})(), void/* @__PURE__ */(function(){y})();
        /* @__PURE__ */(function(){x})() || true ? foo() : bar();
        true || /* @__PURE__ */(function(){y})() ? foo() : bar();
        /* @__PURE__ */(function(){x})() && false ? foo() : bar();
        false && /* @__PURE__ */(function(){y})() ? foo() : bar();
        /* @__PURE__ */(function(){x})() + "foo" ? bar() : baz();
        "foo" + /* @__PURE__ */(function(){y})() ? bar() : baz();
        /* @__PURE__ */(function(){x})() ? foo() : foo();
        [/* @__PURE__ */(function(){x})()] ? foo() : bar();
        !{ foo: /* @__PURE__ */(function(){x})() } ? bar() : baz();
    }
    expect: {
        foo();
        foo();
        bar();
        bar();
        bar();
        bar();
        foo();
        foo();
        baz();
    }
    expect_warnings: [
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,61]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,23]",
        "WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:1,23]",
        "WARN: Boolean || always true [test/compress/issue-1261.js:2,23]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:2,23]",
        "WARN: Condition always true [test/compress/issue-1261.js:2,23]",
        "WARN: Condition left of || always true [test/compress/issue-1261.js:3,8]",
        "WARN: Condition always true [test/compress/issue-1261.js:3,8]",
        "WARN: Boolean && always false [test/compress/issue-1261.js:4,23]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:4,23]",
        "WARN: Condition always false [test/compress/issue-1261.js:4,23]",
        "WARN: Condition left of && always false [test/compress/issue-1261.js:5,8]",
        "WARN: Condition always false [test/compress/issue-1261.js:5,8]",
        "WARN: + in boolean context always true [test/compress/issue-1261.js:6,23]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:6,23]",
        "WARN: Condition always true [test/compress/issue-1261.js:6,23]",
        "WARN: + in boolean context always true [test/compress/issue-1261.js:7,8]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:7,31]",
        "WARN: Condition always true [test/compress/issue-1261.js:7,8]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,23]",
        "WARN: Condition always true [test/compress/issue-1261.js:9,8]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:9,24]",
        "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:10,31]",
        "WARN: Condition always false [test/compress/issue-1261.js:10,8]",
    ]
}
eq? (commit-difference commit4 commit1 (list commit2)) (list commit3 commit4)) (lset= eq? (commit-difference commit4 commit1 (list commit3)) (list commit4)) (null? (commit-difference commit4 commit1 (list commit5)))))))) (unless (which (git-command)) (test-skip 1)) (test-equal "commit-relation" '(self ;master3 master3 ancestor ;master1 master3 descendant ;master3 master1 unrelated ;master2 branch1 unrelated ;branch1 master2 ancestor ;branch1 merge descendant ;merge branch1 ancestor ;master1 merge descendant) ;merge master1 (with-temporary-git-repository directory '((add "a.txt" "A") (commit "first commit") (branch "hack") (checkout "hack") (add "1.txt" "1") (commit "branch commit") (checkout "master") (add "b.txt" "B") (commit "second commit") (add "c.txt" "C") (commit "third commit") (merge "hack" "merge")) (with-repository directory repository (let ((master1 (find-commit repository "first")) (master2 (find-commit repository "second")) (master3 (find-commit repository "third")) (branch1 (find-commit repository "branch")) (merge (find-commit repository "merge"))) (list (commit-relation master3 master3) (commit-relation master1 master3) (commit-relation master3 master1) (commit-relation master2 branch1) (commit-relation branch1 master2) (commit-relation branch1 merge) (commit-relation merge branch1) (commit-relation master1 merge) (commit-relation merge master1)))))) (unless (which (git-command)) (test-skip 1)) (test-equal "commit-descendant?" '((master3 master3 => #t) (master1 master3 => #f) (master3 master1 => #t) (master2 branch1 => #f) (master2 branch1 master1 => #t) (branch1 master2 => #f) (branch1 merge => #f) (merge branch1 => #t) (master1 merge => #f) (merge master1 => #t)) (with-temporary-git-repository directory '((add "a.txt" "A") (commit "first commit") (branch "hack") (checkout "hack") (add "1.txt" "1") (commit "branch commit") (checkout "master") (add "b.txt" "B") (commit "second commit") (add "c.txt" "C") (commit "third commit") (merge "hack" "merge")) (with-repository directory repository (let ((master1 (find-commit repository "first")) (master2 (find-commit repository "second")) (master3 (find-commit repository "third")) (branch1 (find-commit repository "branch")) (merge (find-commit repository "merge"))) (letrec-syntax ((verify (syntax-rules () ((_) '()) ((_ (new old ...) rest ...) (cons `(new old ... => ,(commit-descendant? new (list old ...))) (verify rest ...)))))) (verify (master3 master3) (master1 master3) (master3 master1) (master2 branch1) (master2 branch1 master1) (branch1 master2) (branch1 merge) (merge branch1) (master1 merge) (merge master1))))))) (unless (which (git-command)) (test-skip 1)) (test-equal "remote-refs" '("refs/heads/develop" "refs/heads/master" "refs/tags/v1.0" "refs/tags/v1.1") (with-temporary-git-repository directory '((add "a.txt" "A") (commit "First commit") (tag "v1.0" "release-1.0") (branch "develop") (checkout "develop") (add "b.txt" "B") (commit "Second commit") (tag "v1.1" "release-1.1")) (remote-refs directory))) (unless (which (git-command)) (test-skip 1)) (test-equal "remote-refs: only tags" '("refs/tags/v1.0" "refs/tags/v1.1") (with-temporary-git-repository directory '((add "a.txt" "A") (commit "First commit") (tag "v1.0" "Release 1.0") (add "b.txt" "B") (commit "Second commit") (tag "v1.1" "Release 1.1")) (remote-refs directory #:tags? #t))) (unless (which (git-command)) (test-skip 1)) (test-assert "update-cached-checkout, tag" (call-with-temporary-directory (lambda (cache) (with-temporary-git-repository directory '((add "a.txt" "A") (commit "First commit") (tag "v1.0" "release-1.0") (branch "develop") (checkout "develop") (add "b.txt" "B") (commit "Second commit") (tag "v1.1" "release-1.1")) (let ((directory commit relation (update-cached-checkout directory #:ref '(tag . "v1.1") #:cache-directory cache)) (head (let* ((pipe (open-pipe* OPEN_READ (git-command) "-C" directory "rev-parse" "HEAD")) (str (get-string-all pipe))) (close-pipe pipe) (string-trim-right str)))) ;; COMMIT should be the ID of the commit object, not that of the tag. (string=? commit head)))))) (test-end "git")