aboutsummaryrefslogtreecommitdiff
path: root/test/compress/switch.js
blob: 62e39cf7bcecb16f4cdbe213617df8dd6bdfedfa (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
constant_switch_1: {
    options = { dead_code: true, evaluate: true };
    input: {
        switch (1+1) {
          case 1: foo(); break;
          case 1+1: bar(); break;
          case 1+1+1: baz(); break;
        }
    }
    expect: {
        bar();
    }
}

constant_switch_2: {
    options = { dead_code: true, evaluate: true };
    input: {
        switch (1) {
          case 1: foo();
          case 1+1: bar(); break;
          case 1+1+1: baz();
        }
    }
    expect: {
        foo();
        bar();
    }
}

constant_switch_3: {
    options = { dead_code: true, evaluate: true };
    input: {
        switch (10) {
          case 1: foo();
          case 1+1: bar(); break;
          case 1+1+1: baz();
          default:
            def();
        }
    }
    expect: {
        def();
    }
}

constant_switch_4: {
    options = { dead_code: true, evaluate: true };
    input: {
        switch (2) {
          case 1:
            x();
            if (foo) break;
            y();
            break;
          case 1+1:
            bar();
          default:
            def();
        }
    }
    expect: {
        bar();
        def();
    }
}

constant_switch_5: {
    options = { dead_code: true, evaluate: true };
    input: {
        switch (1) {
          case 1:
            x();
            if (foo) break;
            y();
            break;
          case 1+1:
            bar();
          default:
            def();
        }
    }
    expect: {
        // the break inside the if ruins our job
        // we can still get rid of irrelevant cases.
        switch (1) {
          case 1:
            x();
            if (foo) break;
            y();
        }
        // XXX: we could optimize this better by inventing an outer
        // labeled block, but that's kinda tricky.
    }
}

constant_switch_6: {
    options = { dead_code: true, evaluate: true };
    input: {
        OUT: {
            foo();
            switch (1) {
              case 1:
                x();
                if (foo) break OUT;
                y();
              case 1+1:
                bar();
                break;
              default:
                def();
            }
        }
    }
    expect: {
        OUT: {
            foo();
            x();
            if (foo) break OUT;
            y();
            bar();
        }
    }
}

constant_switch_7: {
    options = { dead_code: true, evaluate: true };
    input: {
        OUT: {
            foo();
            switch (1) {
              case 1:
                x();
                if (foo) break OUT;
                for (var x = 0; x < 10; x++) {
                    if (x > 5) break; // this break refers to the for, not to the switch; thus it
                                      // shouldn't ruin our optimization
                    console.log(x);
                }
                y();
              case 1+1:
                bar();
                break;
              default:
                def();
            }
        }
    }
    expect: {
        OUT: {
            foo();
            x();
            if (foo) break OUT;
            for (var x = 0; x < 10; x++) {
                if (x > 5) break;
                console.log(x);
            }
            y();
            bar();
        }
    }
}

constant_switch_8: {
    options = { dead_code: true, evaluate: true };
    input: {
        OUT: switch (1) {
          case 1:
            x();
            for (;;) break OUT;
            y();
            break;
          case 1+1:
            bar();
          default:
            def();
        }
    }
    expect: {
        OUT: {
            x();
            for (;;) break OUT;
            y();
        }
    }
}

constant_switch_9: {
    options = { dead_code: true, evaluate: true };
    input: {
        OUT: switch (1) {
          case 1:
            x();
            for (;;) if (foo) break OUT;
            y();
          case 1+1:
            bar();
          default:
            def();
        }
    }
    expect: {
        OUT: {
            x();
            for (;;) if (foo) break OUT;
            y();
            bar();
            def();
        }
    }
}

drop_default_1: {
    options = { dead_code: true };
    input: {
        switch (foo) {
          case 'bar': baz();
          default:
        }
    }
    expect: {
        switch (foo) {
          case 'bar': baz();
        }
    }
}

drop_default_2: {
    options = { dead_code: true };
    input: {
        switch (foo) {
          case 'bar': baz(); break;
          default:
            break;
        }
    }
    expect: {
        switch (foo) {
          case 'bar': baz();
        }
    }
}

keep_default: {
    options = { dead_code: true };
    input: {
        switch (foo) {
          case 'bar': baz();
          default:
            something();
            break;
        }
    }
    expect: {
        switch (foo) {
          case 'bar': baz();
          default:
            something();
        }
    }
}
s]: Likewise. * gnu/packages/qt.scm (qtbase, qtwebkit)[inputs]: Likewise. * gnu/packages/rdesktop.scm (freerdp)[inputs]: Likewise. * gnu/packages/scanner.scm (sane-backends, xsane)[inputs]: Likewise. * gnu/packages/scheme.scm (racket)[inputs]: Likewise. * gnu/packages/scribus.scm (scribus)[inputs]: Likewise. * gnu/packages/sdl.scm (sdl-image)[propagated-inputs]: Likewise. (guile-sdl)[native-inputs]: Likewise. * gnu/packages/spice.scm (spice-gtk)[inputs]: Likewise. * gnu/packages/statistics.scm (r-with-tests)[inputs]: Likewise. * gnu/packages/tcl.scm (perl-tk)[inputs]: Likewise. * gnu/packages/upnp.scm (readymedia)[inputs]: Likewise. * gnu/packages/video.scm (mplayer, mpv, v4l-utils, motion)[inputs]: Likewise. * gnu/packages/web-browsers.scm (dillo, links)[inputs]: Likewise. * gnu/packages/web.scm (netsurf)[inputs]: Likewise. * gnu/packages/webkit.scm (webkitgtk)[inputs]: Likewise. * gnu/packages/wine.scm (wine)[inputs]: Likewise. * gnu/packages/wv.scm (wv)[inputs]: Likewise. * gnu/packages/wxwidgets.scm (wxwidgets, wxwidgets-2)[inputs]: Likewise. * gnu/packages/xdisorg.scm (xscreensaver)[inputs]: Likewise. * gnu/packages/xfce.scm (tumbler)[inputs]: Likewise. * gnu/packages/xfig.scm (xfig, transfig)[inputs]: Likewise. * gnu/packages/xorg.scm (xpra)[inputs]: Likewise. Marius Bakke 2019-11-22gnu: xsane: Fix snprintf buffer length....* gnu/packages/scanner.scm (xsane)[source]: Add patch. * gnu/packages/patches/xsane-fix-snprintf-buffer-length.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it. Tobias Geerinckx-Rice 2019-11-22gnu: Add xsane....* gnu/packages/scanner.scm (xsane): New public variable. Tobias Geerinckx-Rice 2019-08-01gnu: sane-backends: Build back ends that need JPEG support....* gnu/packages/scanner.scm (sane-backends)[inputs]: Add libjpeg. Tobias Geerinckx-Rice 2019-08-01gnu: sane-backends-minimal: Update to 1.0.28....* gnu/packages/scanner.scm (sane-backends-minimal): Update to 1.0.28. [arguments]: Disable back end tests. Tobias Geerinckx-Rice 2019-03-18Order (gnu packages scanner) module imports alphabetically....* gnu/packages/scanner.scm (define-module): Order module imports alphabetically. Tobias Geerinckx-Rice 2019-03-10gnu: Import (gnu packages image) in (gnu packages scanner)....This is a follow-up to commit 10bd2889d267df479f79f43471d3c2dd17da345a. * gnu/packages/scanner.scm: #:use-module (gnu packages image). Tobias Geerinckx-Rice 2019-03-10gnu: sane-backends: Support PNG scanimage output....* gnu/packages/scanner.scm (sane-backends)[inputs]: Add libpng. Tobias Geerinckx-Rice 2019-03-07gnu: sane-backends-minimal: Fix USB support....* gnu/packages/scanner.scm (sane-backends-minimal)[inputs]: Replace libusb-compat with libusb. [arguments]: Disable tests that require USB access. Tobias Geerinckx-Rice 2018-07-25gnu: Add hplip-minimal....* gnu/packages/cups.scm (hplip-minimal): New variable. * gnu/packages/scanner.scm (sane-backends)[inputs]: Replace hplip with hplip-minimal. * doc/guix.texi (Printing Services): Change example code to use hplip-minimal in place of hplip. Add note explaining when use hplip. Efraim Flashner 2018-04-12gnu: sane-backends-minimal: Return #t from all phases....* gnu/packages/scanner.scm (sane-backends-minimal)[arguments]: Return #t from the 'install-udev-rules' phase. Mark H Weaver 2018-03-16gnu: All snippets report errors using exceptions, else return #t....* gnu/packages/admin.scm, gnu/packages/algebra.scm, gnu/packages/audio.scm, gnu/packages/backup.scm, gnu/packages/base.scm, gnu/packages/bioinformatics.scm, gnu/packages/cdrom.scm, gnu/packages/chez.scm, gnu/packages/code.scm, gnu/packages/compression.scm, gnu/packages/cross-base.scm, gnu/packages/crypto.scm, gnu/packages/cups.scm, gnu/packages/databases.scm, gnu/packages/dns.scm, gnu/packages/emacs.scm, gnu/packages/emulators.scm, gnu/packages/engineering.scm, gnu/packages/enlightenment.scm, gnu/packages/fpga.scm, gnu/packages/freedesktop.scm, gnu/packages/ftp.scm, gnu/packages/games.scm, gnu/packages/gcc.scm, gnu/packages/geo.scm, gnu/packages/ghostscript.scm, gnu/packages/gl.scm, gnu/packages/glib.scm, gnu/packages/gnome.scm, gnu/packages/gnuzilla.scm, gnu/packages/graphics.scm, gnu/packages/gtk.scm, gnu/packages/guile.scm, gnu/packages/irc.scm, gnu/packages/java.scm, gnu/packages/kerberos.scm, gnu/packages/linux.scm, gnu/packages/lisp.scm, gnu/packages/lxde.scm, gnu/packages/machine-learning.scm, gnu/packages/mail.scm, gnu/packages/maths.scm, gnu/packages/messaging.scm, gnu/packages/monitoring.scm, gnu/packages/mp3.scm, gnu/packages/music.scm, gnu/packages/netpbm.scm, gnu/packages/networking.scm, gnu/packages/node.scm, gnu/packages/nvi.scm, gnu/packages/ocaml.scm, gnu/packages/pdf.scm, gnu/packages/perl.scm, gnu/packages/php.scm, gnu/packages/plotutils.scm, gnu/packages/pretty-print.scm, gnu/packages/profiling.scm, gnu/packages/pulseaudio.scm, gnu/packages/python-crypto.scm, gnu/packages/python.scm, gnu/packages/qt.scm, gnu/packages/robotics.scm, gnu/packages/sawfish.scm, gnu/packages/scanner.scm, gnu/packages/scheme.scm, gnu/packages/scribus.scm, gnu/packages/sdl.scm, gnu/packages/serialization.scm, gnu/packages/shells.scm, gnu/packages/slang.scm, gnu/packages/smalltalk.scm, gnu/packages/ssh.scm, gnu/packages/sync.scm, gnu/packages/syncthing.scm, gnu/packages/tbb.scm, gnu/packages/terminals.scm, gnu/packages/texinfo.scm, gnu/packages/text-editors.scm, gnu/packages/textutils.scm, gnu/packages/tls.scm, gnu/packages/unrtf.scm, gnu/packages/version-control.scm, gnu/packages/video.scm, gnu/packages/vpn.scm, gnu/packages/web.scm, gnu/packages/wm.scm, gnu/packages/wxwidgets.scm, gnu/packages/xdisorg.scm, gnu/packages/xorg.scm: In all snippets, report errors using exceptions, or else return #t. Mark H Weaver