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
When we removed tsickle from the library compilation pipeline the emitted JS changes for Classes.
With tsc a class can be of kind CallExpression because of this syntax
```
let Foo = class Foo {
constructor() {
this.isExpandedChange = new EventEmitter();
}
set isExpanded(value) {
this.isExpandedChange.emit(value);
}
};
```
In such case we shall not add `/*@__PURE__*/` inside this class
Fixes#14084
This should make it easier to manage and diff. This takes 2 things into account:
1. we have either stable or experimental versions and each are kept in monorepo.
2. we dont keep hash and update only changed packages.
This commit also removed the hash to make sure this does not happen.
tsickle emits es2015 enums with an object literal followed by an export declaration
Example:
```
const RendererStyleFlags3 = {
Important: 1,
DashCase: 2,
};
export { RendererStyleFlags3 };
RendererStyleFlags3[RendererStyleFlags3.Important] = 'Important';
RendererStyleFlags3[RendererStyleFlags3.DashCase] = 'DashCase';
```
This PR adds support for the enums to be optimized by wrapping them in an iife and marks them as pure.
Fixes#13488
Although ES5 classes had their static properties folded in, ES2015 ones did not.
This PR adds that new functionality.
It should also make this particular transform a bit faster since it will stop early.
Fix https://github.com/angular/angular-cli/issues/13487