Ah, yes, minifiers do some analysis to detect constants and remove dead branches from if
and switch
(and more). That’s true!
But sticking that into a function is enough to fool Terser:
function toDayString(int) {
switch (int) {
case 0:
return "Sunday";
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
return "Saturday";
}
}
toDayString(0);
So it’s not safe to assume that unused branches are removed always/in general/most of the time?