Intention

  • Dead-code elimination
  • Bundle code written in ECMAScript dialects

Rationale

  • For dynamic languages, all possible execution flows of a program can be represented as a tree of function calls.
  • The popularity of tree shaking in JavaScript is based on the fact that in distinction from CommonJS modules, ECMAScript 6 module loading is static and thus the whole dependency tree can be deduced by statically parsing the syntax tree.

In JavaScript, you have to add an entire library even if you only need it for one function, but thanks to tree shaking the Dart-derived JavaScript only includes the individual functions that you need from a library. – Chris Buckett