From the looks of it, CC's side-effect detection doesn't correctly understand the IIFE and CC decides the enclosing scope is impure. This in turn means that CC won't remove the unused code paths.
We ran into this because this is the code that swc generates for static class members. I'm trying to migrate our codebase from tsc to swc for transpilation and we noticed a bundle size increase. A lot of investigation later we eventually narrowed it down to this problem.
Input
Expected output
Actual output
[closure compiler playground](https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%2540formatting%2520pretty_print%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F%252F%2520ADD%2520YOUR%2520CODE%2520HERE%250Afunction%2520getFoo()%2520%257B%250A%2520%2520class%2520Foo%2520%257B%250A%2520%2520%257D%250A%2520%2520(()%2520%253D%253E%2520%257B%250A%2520%2520%2520%2520Foo.x%2520%253D%25201%253B%250A%2520%2520%257D)()%253B%250A%2520%2520return%2520Foo%253B%250A%257D%250Aconst%2520Foo1%2520%253D%2520getFoo()%253B%250A%250Aclass%2520Bar%2520%257B%250A%2520%2520constructor(num)%2520%257B%250A%2520%2520%2520%2520this.num%2520%253D%2520num%253B%250A%2520%2520%257D%250A%250A%2520%2520n()%2520%257B%250A%2520%2520%2520%2520console.log(this.num)%253B%250A%2520%2520%257D%250A%250A%2520%2520neverCalled()%2520%257B%250A%2520%2520%2520%2520console.log(Foo1)%253B%250A%2520%2520%257D%250A%257D%250A%250Anew%2520Bar(5).n()%253B)
From the looks of it, CC's side-effect detection doesn't correctly understand the IIFE and CC decides the enclosing scope is impure. This in turn means that CC won't remove the unused code paths.
We ran into this because this is the code that swc generates for static class members. I'm trying to migrate our codebase from
tsc
toswc
for transpilation and we noticed a bundle size increase. A lot of investigation later we eventually narrowed it down to this problem.cc @WearyMonkey