Skip to content

Unreachable switch cases are not removed when switch value is known #4028

@TheHolyWaffle

Description

@TheHolyWaffle

When the value of a switch case is hardcoded, either literally in code or through define option, esbuild does not treeshake the unreachable switch cases.

Reproduction 0.24.2: https://esbuild.github.io/try/#dAAwLjI0LjIALS1taW5pZnkgAHN3aXRjaCAoImEiKSB7CiAgICBjYXNlICJhIjogewogICAgICBjb25zb2xlLmxvZygiYSIpOwogICAgfQogICAgY2FzZSAiYiI6IHsKICAgICAgY29uc29sZS5sb2coImIiKTsKICAgIH0KICB9

Expected output after minification:

console.log("a")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions