-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Cross-module dead code elimination of constant doesn't work with defines #2061
Comments
General function inlining like this is not an optimization that esbuild does. This is documented here: https://esbuild.github.io/api/#minify-considerations. You are welcome to use another tool instead if you need this optimization. |
Fine, but it's still not inlining the constant as intended right?.
becomes
rather than
It's failing to recognize that |
FWIW this behaves as intended:
so this does seem to be a constant inlining problem. |
This is also in the documentation. What you are referring to is the "Cross-statement constant propagation" bullet point. You can read more about why this limitation exists here: #2006 (comment). |
This is a known design limitation. The best way to do this is to avoid indirection through another variable, as described above. Closing as "won't fix." |
Hmm.... I think I must be doing something wrong. I'm trying to take advantage of #1981 in 0.14.19. have a
constants.ts
file like this:In build.mjs I have:
I've used
isProductionBuild
in my code like so:I would expect that the conditional
if (isDateInstance(value))
gets minified toif(value instanceof Date)
in a production build. Instead I see:and later
The text was updated successfully, but these errors were encountered: