There is a module that is used as a namespace (for testability reasons or else):
export function bar() {}
export function baz() {
this.bar();
}
export function qux() {}
This can be considered a bad practice because baz
depends on the context and cannot be imported alone as named export:
import * as Foo from './foo';
Foo.baz();
Is it safe to assume that this.bar
doesn't affect tree shaking mechanism, and bar
and qux
will be tree-shaken?
Is it possible to make a bundler to be aware of a relation between bar
and baz
, so if Foo.baz
is in use, only qux
is tree-shaken?
The question primarily addresses Webpack tree shaking, but an explanation for other bundlers (Rollup) is also welcome.