News for hackers. Stuff that matters.
Re:Mako – fast, production-grade web bundler based on Rust by flohofwoe on Tuesday July 02, 2024 @08:11AM (#40855842)
In my book that's all covered by the term 'dead code elimination', e.g. removing (or not including in the first place) any code that can be statically proven to be unreachable at runtime. Some JS minifiers (like Google's Closure) can do the same thing in Javascript on the AST level (AFAIK Closure essentially breaks the input code down into an AST, then does static control flow analysis on the AST, removes any unreachable parts, and finally compiles the AST back into minified Javascript). Tree-shaking without this static control flow analysis doesn't make much sense IMHO since it wouldn't be able to remove things like a dynamic import inside an if that always resolves to true or false.
Re:Mako – fast, production-grade web bundler based on Rust by throwAGIway on Tuesday July 02, 2024 @08:49AM (#40856118)
Yep, that's how it works - you first perform dead code elimination and then tree shaking exactly because it wouldn't remove everything otherwise. Agreed that you need both done one after another in most cases; however you can usually disable either one in bundler configuration and it's a separate step.
Re:Mako – fast, production-grade web bundler based on Rust by pshu on Tuesday July 02, 2024 @11:26AM (#40857586)
https://makojs.dev/blog/mako-tree-shaking explains how mako do the tree shaking stuff, but in Chinese.

In my two cents, the tree shaking is more focus on removing unused exports in ES module at top level. it's a mixing with Dead code elimination and link time optimization.