Is there a way to tree shake out a function called in a class method?

104 Views Asked by At

Let's consider this code :

class Foo {
   type;
   constructor(type) {
      this.type = type;
   }

   foo() {
     this.type === 'animation' ? create() : createNoop();
   }
}


new Foo('animation') 

function create() {
   console.log('create');
}
function createNoop() { 
   console.log('create Noop')
}

It there a way to refactor this, in order to get createNoop() tree shaken.

The key here is that type is meant to be readonly once it has been set by the constructor.

Esbuild demo / Terser REPL.

0

There are 0 best solutions below