I think there's an opportunity to further optimize switch statements by removing empty case blocks before a default.
Input:
switch (globalThis.foo) {
case 'first': {
console.log('first');
}
case 'second':
default: {
console.log('default');
}
}
Expected output:
switch (globalThis.foo) {
case 'first': console.log('first');
default: console.log('default');
}
Actual output (0.27.1):
switch (globalThis.foo) {
case 'first': console.log('first');
case 'second': // Unnecessary!
default: console.log('default');
}
Playground link
I think you do need to keep case statements which contain expressions (case getSecond(): ...) as that's probably important for execution order and potential side effects. But I think any literal values should be safe to remove, and that's likely the most common case with switch statements.
I think there's an opportunity to further optimize
switchstatements by removing emptycaseblocks before adefault.Input:
Expected output:
Actual output (0.27.1):
Playground link
I think you do need to keep
casestatements which contain expressions (case getSecond(): ...) as that's probably important for execution order and potential side effects. But I think any literal values should be safe to remove, and that's likely the most common case withswitchstatements.