Skip to content

minify cannot remove unused branch #4148

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

Open
ocavue opened this issue Apr 17, 2025 · 2 comments
Open

minify cannot remove unused branch #4148

ocavue opened this issue Apr 17, 2025 · 2 comments

Comments

@ocavue
Copy link

ocavue commented Apr 17, 2025

Reproduction link:

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

Expected output:

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

Actual output:

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.

@evanw
Copy link
Owner

evanw commented Apr 17, 2025

As a special case, esbuild supports some limited inlining of constants if they are declared at the top of the file. It doesn't contain a more advanced symbolic evaluator though and doesn't attempt to evaluate code once non-constants are involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants