Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreachable switch statements become 'skeletons' when minified instead of being removed #3659

Closed
simeyla opened this issue Feb 21, 2024 · 0 comments

Comments

@simeyla
Copy link

simeyla commented Feb 21, 2024

The statements inside this if block are unreachable:

if (false) {
   console.log('unreachable');
   switch (1) {
      case 1: console.log('1'); break;      
      case 2: console.log('2'); break;
   }
}

However it is minified to a useless skeleton still containing the original case statements (Repro on 0.20.1):

if(0)switch(1){case 1:case 2:}

This is particularly problematic if the switch is contained in a function, since I want the function call to be stripped out.

const enabled = false;

function funcWithSwitch() {
   if (enabled) {
     switch (1) {
        case 1: console.log('1'); break;
        case 2: console.log('1'); break;
     }
   }
}

funcWithSwitch();  // not stripped out, due entirely to the switch statement

Reproduction

Note: in my use-case this is a logging function and I want to set the enabled variable with --define:enabled=false

@evanw evanw closed this as completed in cc74e60 Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant