Skip to content

Comment on Tiny Treeshaker: JavaScript tree shaking in 200 lines of code

Comments

I suspect (although I haven't checked the code) that this is actually a "dead code elimination" algorithm which is easier to write than a tree shaking algorithm.

Tree-shaking is actually "live code inclusion", the opposite side of dead code elimination.

https://en.m.wikipedia.org/wiki/Tree_shaking

"opposite" is not the right term... tree-shaking appears to be a particular technique for dead code elimination.

I.e., there are many algorithms you could use to eliminate dead code, and tree-shaking seems to just be a simple one that works well for JS.

Might be worth checking the code but

tree shaking eliminates unused functions from across the bundle by starting at the entry point and only including functions that may be executed

Is what this code (tries to!) do

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.