Skip to content

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

@simeyla

Description

@simeyla

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions