Emit /*@__PURE__*/ before class declaration #452
Description
Based on this research, I believe that if we were able to emit a newly supported /*@__PURE__*/
annotation in front of class declaration and ensure that it gets preserved in the final down-leveled output, @angular/cli
and any other Uglify-based build tool chains would be able to use dead-code elimination tricks to remove all unused classes (pipes, directives and components) with the exception of unused services.
There is a feature request microsoft/TypeScript#13721 to add this functionality to tsc
, but it's unclear when/if it's going to be implemented, so I wonder how easy it would be to implement this kind of feature in tsickle so that we can experiment.
What I'd like is given the following input:
export class SomeClass {}
I'd like tsc + tscikle to output downleveled es5 code that looks like this:
var SomeClass = /*@__PURE__*/(function () {
function SomeClass() {}
return SomeClass;
}());
If for some reason we have a concern that /*@__PURE__*/
could cause headaches for Closure, we can also use /*#__PURE__*/
, which is equally supported by Uglify.
More info:
- research doc: https://goo.gl/ZVdWlt
- Uglify's commit introducing inline annotations for pure functions: mishoo/UglifyJS@1e51586
- TypeScript issue Pure annotation in downlevel emits microsoft/TypeScript#13721