Replies: 3 comments 28 replies
-
Here is an example of what kind of optimizations the Closure Compiler will do if you let it. class Example {
constructor(foo, bar) {
this.foo = foo;
this.bar = bar;
}
getFoo() {
return this.foo;
}
getBar() {
return this.bar;
}
doSomething() {
return this.foo + 1;
}
}
console.log(new Example(1, 2).doSomething()); Running this through class Example{constructor(o,t){this.foo=o,this.bar=t}getFoo(){return this.foo}getBar(){return this.bar}doSomething(){return this.foo+1}}console.log(new Example().doSomething()); Which is exactly what it says on the box. Minified. Nothing more. Maybe there are options to make it do more but I haven't found them. The Closure Compiler in console.log(2); I actually had to add the I'm not even saying this to defend the Closure Compiler in any way. There are big huge trade-offs you have to make to get all of this. The other authors are correct when making different decisions. Sometimes these optimizations are not worth doing. I'm just trying to emphasize this since this is something you need to be aware of when talking about Back to the subject of Tree Shaking and cherry. The Closure Compiler is actually capable of outputting ESM code on its own nowadays. See
However, so far this isn't capable of creating named exports (AFAICT). It just uses import/export to remove the need for the |
Beta Was this translation helpful? Give feedback.
-
FWIW I got curious to see how
does indeed shake the
but
produces
So, the I guess that confirms that changing the output may indeed help tree-shaking. I'm unsure why they don't support this pattern in the first place, but I guess they are being very conservative and a late-assignment is enough to bail. I can maybe address this by creating different output, so rewriting after the fact isn't needed. |
Beta Was this translation helpful? Give feedback.
-
I’ll be back in an hour. Meanwhile you can try the nbb repo with the
shadow-esm branch if you wish.
On Sun, 7 Aug 2022 at 15:45, Thomas Heller ***@***.***> wrote:
Can you test with pseudo-names? Otherwise its very hard to figure out what
h_ might be.
—
Reply to this email directly, view it on GitHub
<#36 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACFSBUBO6LQUYQLMBXUPGLVX64ZHANCNFSM55PWJAXA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Continuation of treeshaking discussion: #24 (comment)
Beta Was this translation helpful? Give feedback.
All reactions