evanw / evanw/esbuild

`minify` cannot remove unused branch

Open
#4,148 2 comments 0 reactions 0 assignees View on GitHub
suboptimal-output
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Reproduction link:

https://esbuild.github.io/try/#YgAwLjI1LjIAeyAgICAKICAgIGZvcm1hdDogImVzbSIsCiAgICBtaW5pZnk6IHRydWUsCiAgICB0cmVlU2hha2luZzogdHJ1ZSwKfQBlAGVudHJ5LmpzAHZhciBmb28gPSAxOwpjb25zdCBmYWxzZV9kZWZhdWx0ID0gZmFsc2U7CgpleHBvcnQgZnVuY3Rpb24gZm4oKSB7CiAgaWYgKGZhbHNlX2RlZmF1bHQpIHsKICAgIGNvbnNvbGUud2FybigiSSBleHBlY3QgdGhpcyBzdHJpbmcgdG8gYmUgcmVtb3ZlZCIpCiAgfQoKICBjb25zb2xlLmxvZyhmb28pCn0

Expected output:

```js
var e=1;function o(){console.log(e)}export{o as fn};
```

Actual output:

```js
var o=1;const e=!1;function n(){e&&console.warn("I expect this string to be removed"),console.log(o)}export{n as fn};
```

For unknown reason, if I move `var foo = 1;` below `const false_default = false;`, I can get the expected output.

Contributor guide

No contributing guide indexed for this repository

Research direction

Use the linked esbuild playground reproduction with minification and tree shaking enabled, then compare the expected and actual bundles shown in the issue. There are no source files or tests named; done means the unused warning branch is removed while the shown exported function output remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, javascript
Domain
compilers, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.