-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Closed as not planned
Description
Command
build
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
A library component with a (non-Angular) decorator will not be tree-shaken. The same component, if inside an app, will be properly tree-shaken.
There is a history of issues related to this topic:
- ES2015 Class with decorators are not being treeshaken away #14610
This matches the topic exactly. According to the issue and the linked PR this might be a regression - Custom decorators not working using AoT #20714 (comment) (links to a comment)
This seems to say that all decorators are always assumed to be side-effect free, but it looks like this is not the case anymore - unused classes got added in build, tree-shaking not working propely #15396 (comment) (links to a comment)
There seemed to be a problem with custom libraries, but in my repro everything comes straight from the angular-cli - File / class deleted during tree shake despite the fact it's being used #16246 (comment) (links to a comment)
This also sounds like this was fixed in the past, hinting yet again that this might be a regression
Minimal Reproduction
Reproduction repository: https://github.com/fischeversenker/ng-decorator-tree-shaking/tree/274524fde27002e87f1535ef6bbef2cf8088ec8d
The essence:
This library code:
import { Component } from '@angular/core';
/*@__PURE__*/
function noopDecoratorFactory() {
return /*@__PURE__*/ (target: any) => target;
}
@noopDecoratorFactory()
@Component({
selector: 'lib-my-library',
template: `my-library works!`
})
export class MyLibraryComponent {}
turns into this:
let MyLibraryComponent = class MyLibraryComponent {
};
// ...
MyLibraryComponent = __decorate([
noopDecoratorFactory()
], MyLibraryComponent);
which seems to not be tree-shakeable.
Exception or Error
No response
Your Environment
Angular CLI: 14.2.6
Node: 16.16.0
Package Manager: yarn 1.22.19
OS: linux x64
Angular: 14.2.7
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1402.6
@angular-devkit/build-angular 14.2.6
@angular-devkit/core 14.2.6
@angular-devkit/schematics 14.2.6
@angular/cli 14.2.6
@schematics/angular 14.2.6
ng-packagr 14.2.2
rxjs 7.5.7
typescript 4.7.4
Anything else relevant?
The real-life use case where this adds huge amounts of unused code to our bundles is when using https://github.com/ngneat/until-destroy#use-with-ivy in library components.
neen-psk and jesusreal
Metadata
Metadata
Assignees
Labels
No labels