-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Description
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');
}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.
Reactions are currently unavailable