Description
openedon Jan 27, 2017
Minifiers like Uglify try to remove dead code from minified builds.
To completely remove a declaration, they have to prove that it is side-effect free.
Unfortunately in JS this is often not possible as pretty much anything can have arbitrary effects.
An important issue is that ES5 emit for class
can't easily be determined to be side-effect free.
As a result, tree-shaking is ineffective. In simple words: no class is removed from the output, even if it is never used.
A very simple solution could be to have a hint for the minifier, inside a special comment.
If the emit added a /** #pure */
comment at the beginning of ES5 classes it could easily be detected and removed by Uglify.
var V6Engine = /** #pure */(function () {
function V6Engine() {
}
V6Engine.prototype.toString = function () {
return 'V6';
};
return V6Engine;
}());
This is an important enhancement that can dramatically reduce the size of unused code, especially in large libraries like Angular or Aurelia.
Is this something the TS team would consider?
Original discussion in Uglify: mishoo/UglifyJS#1261
I am aware of #3882 and #7770 and this is not the same.
Those issues are about extending the language to include some "pure" annotations.
This issue is just about adding a hint (comment) inside the emit template.