react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / handlebars / node_modules / uglify-js / test / compress / switch.js
80728 viewsconstant_switch_1: {1options = { dead_code: true, evaluate: true };2input: {3switch (1+1) {4case 1: foo(); break;5case 1+1: bar(); break;6case 1+1+1: baz(); break;7}8}9expect: {10bar();11}12}1314constant_switch_2: {15options = { dead_code: true, evaluate: true };16input: {17switch (1) {18case 1: foo();19case 1+1: bar(); break;20case 1+1+1: baz();21}22}23expect: {24foo();25bar();26}27}2829constant_switch_3: {30options = { dead_code: true, evaluate: true };31input: {32switch (10) {33case 1: foo();34case 1+1: bar(); break;35case 1+1+1: baz();36default:37def();38}39}40expect: {41def();42}43}4445constant_switch_4: {46options = { dead_code: true, evaluate: true };47input: {48switch (2) {49case 1:50x();51if (foo) break;52y();53break;54case 1+1:55bar();56default:57def();58}59}60expect: {61bar();62def();63}64}6566constant_switch_5: {67options = { dead_code: true, evaluate: true };68input: {69switch (1) {70case 1:71x();72if (foo) break;73y();74break;75case 1+1:76bar();77default:78def();79}80}81expect: {82// the break inside the if ruins our job83// we can still get rid of irrelevant cases.84switch (1) {85case 1:86x();87if (foo) break;88y();89}90// XXX: we could optimize this better by inventing an outer91// labeled block, but that's kinda tricky.92}93}9495constant_switch_6: {96options = { dead_code: true, evaluate: true };97input: {98OUT: {99foo();100switch (1) {101case 1:102x();103if (foo) break OUT;104y();105case 1+1:106bar();107break;108default:109def();110}111}112}113expect: {114OUT: {115foo();116x();117if (foo) break OUT;118y();119bar();120}121}122}123124constant_switch_7: {125options = { dead_code: true, evaluate: true };126input: {127OUT: {128foo();129switch (1) {130case 1:131x();132if (foo) break OUT;133for (var x = 0; x < 10; x++) {134if (x > 5) break; // this break refers to the for, not to the switch; thus it135// shouldn't ruin our optimization136console.log(x);137}138y();139case 1+1:140bar();141break;142default:143def();144}145}146}147expect: {148OUT: {149foo();150x();151if (foo) break OUT;152for (var x = 0; x < 10; x++) {153if (x > 5) break;154console.log(x);155}156y();157bar();158}159}160}161162constant_switch_8: {163options = { dead_code: true, evaluate: true };164input: {165OUT: switch (1) {166case 1:167x();168for (;;) break OUT;169y();170break;171case 1+1:172bar();173default:174def();175}176}177expect: {178OUT: {179x();180for (;;) break OUT;181y();182}183}184}185186constant_switch_9: {187options = { dead_code: true, evaluate: true };188input: {189OUT: switch (1) {190case 1:191x();192for (;;) if (foo) break OUT;193y();194case 1+1:195bar();196default:197def();198}199}200expect: {201OUT: {202x();203for (;;) if (foo) break OUT;204y();205bar();206def();207}208}209}210211drop_default_1: {212options = { dead_code: true };213input: {214switch (foo) {215case 'bar': baz();216default:217}218}219expect: {220switch (foo) {221case 'bar': baz();222}223}224}225226drop_default_2: {227options = { dead_code: true };228input: {229switch (foo) {230case 'bar': baz(); break;231default:232break;233}234}235expect: {236switch (foo) {237case 'bar': baz();238}239}240}241242keep_default: {243options = { dead_code: true };244input: {245switch (foo) {246case 'bar': baz();247default:248something();249break;250}251}252expect: {253switch (foo) {254case 'bar': baz();255default:256something();257}258}259}260261262