You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When variables are un-used at the top-level of a module, tree-shaking kicks in unused code is properly dropped from the output. For example, the code below correctly results in empty output (with --tree-shaking) because foo is not referenced. If you uncomment the console.log(foo) at the bottom, or add export {foo} etc, then all of the associated code persists.
Would it be difficult to apply the same analysis to function bodies that applies at the top-level and drop any side-effect-free expressions that are not visible to a return value?
The text was updated successfully, but these errors were encountered:
Would it be difficult to apply the same analysis to function bodies that applies at the top-level and drop any side-effect-free expressions that are not visible to a return value?
Yes. The data structure that esbuild uses for tree-shaking makes a graph of top-level statements and is not recursive. It's designed to run quickly and give good results when bundling from source (since esbuild is primarily a bundler), but that means it's not designed to be optimal for all use cases. There is more discussion in this issue (which is the same request as yours): #639.
When variables are un-used at the top-level of a module, tree-shaking kicks in unused code is properly dropped from the output. For example, the code below correctly results in empty output (with
--tree-shaking
) because foo is not referenced. If you uncomment theconsole.log(foo)
at the bottom, or addexport {foo}
etc, then all of the associated code persists.All of the above works great, but if you take the exact same code and wrap it in a function, no code is eliminated from the body of the function.
Would it be difficult to apply the same analysis to function bodies that applies at the top-level and drop any side-effect-free expressions that are not visible to a return value?
The text was updated successfully, but these errors were encountered: