This transformer can cause size regressions when it introduces `tslib` imports across independent chunks.
It should be deprecated because tslib adoption has become more ubiquitous.
Should also speed up Build Optimizer processing time because there's one less thing to do.
Closes https://github.com/angular/angular-cli/issues/15401 without adding the warning, because some libraries like zone.js should inline the helpers.
When a `__decorator` expression has no `__metadata` call, example:
```js
__decorate([
ContentChild('heading', { read: ElementRef, static: true })
], FooBarComponent.prototype, "buttons", void 0);
```
A `Cannot read property 'kind' of undefined` error will be thrown.
Closes: #15703
Inlined tslib helpers can be suffixed with `$` and a number when having multiple helpers in the same file.
With this change we will replace all tslib inline helpers to imports from `tslib`
Followup to https://github.com/angular/angular-cli/pull/15239, fixes a 6kb size regression in new apps, potentially more in larger apps.
Local declarations inside `@angular/core` files should also be considered metadata and scrubbed.
We used to keep a specifier list of known specifiers to identify the `@angular/core` FESM. But it doesn't work for non-FESM bundles, and we already pass that information on anyway.
At the moment the `wrap-enums` transfomers is being run prior to `scrub-file` and this is resulting classes which all static properties have been dropped to be wrapped in IIFE.
With this change we stop recursive lookup when the current node is not a BlockLike.
This change should also, improve the BO overall speed as it's reduces a lot of recursive lookups.
Fixes#15145
Most of the logic that can find class statements to wrap can be used to wrap Enums, with the exception of TS 2.3+ enums which is slightly different.
This PR combines the enums and classes lookup logic and also simplifies the TS 2.3+ enum lookup logic
With this change we wrap ClassDeclarations inside an IIFE, also we move some code from the class fold into the wrap-enums.
This changes the below code:
```js
export class Foo {
method() {
}
}
Foo.bar = 'barValue';
__decorate([
methodDecorator
], Foo.prototype, "method", null);
```
to
```js
export const Foo = /*@__PURE__*/ (() => {
class Foo {
method() {
}
}
Foo.bar = 'barValue';
__decorate([
methodDecorator
], Foo.prototype, "method", null);
return Foo;
})();
```
Fixes#14610
ClassExpressions such as the below are not treeshakable unless we wrap them in an IIFE
```js
let AggregateColumnDirective = class AggregateColumnDirective {
constructor(viewContainerRef) { }
};
AggregateColumnDirective = __decorate([
Directive({}),
__metadata("design:paramtypes", [ViewContainerRef])
], AggregateColumnDirective);
```
With this change we wrap the above in an IIFE and mark it as a PURE function.
```js
const AggregateColumnDirective = /*@__PURE__*/ (() => {
let AggregateColumnDirective = class AggregateColumnDirective {
constructor(viewContainerRef) { }
};
AggregateColumnDirective = __decorate([
Directive({}),
__metadata("design:paramtypes", [ViewContainerRef])
], AggregateColumnDirective);
return AggregateColumnDirective;
})();
```
With this pattern if the class is unused it will be dropped.
Note: In future we should rename `wrap-enums` to something more generic, and combine class-fold with this transformer especially considering the future fix that needs to be done for https://github.com/angular/angular-cli/issues/14610Fixes#14577