48 Commits

Author SHA1 Message Date
Charles Lyding
6e33f447a6 refactor(@angular-devkit/build-optimizer): remove casts from tslib helper check 2020-04-06 09:55:58 -07:00
Charles Lyding
4509d3c112 fix(@angular-devkit/build-optimizer): use TypeScript 3.6
Fixes: #17320
2020-04-06 09:55:58 -07:00
Charles Lyding
0db3a699d4 refactor(@angular-devkit/build-optimizer): update to use TypeScript 3.8 2020-03-02 14:05:31 -08:00
Alan Agius
049fc792a5 revert: "fix(@angular-devkit/build-optimizer): wrap classes which contain empty statements (#16538)"
This reverts commit 4cde9228df5118a6c743467c668b6b7c5fe73013.
2020-01-17 08:13:16 -08:00
Alan Agius
4cde9228df fix(@angular-devkit/build-optimizer): wrap classes which contain empty statements (#16538)
NGCC currently produces empty statments which breaks class wrapping.

Closes #16509
2020-01-04 11:15:39 -08:00
Filipe Silva
c3a4c454be fix(@angular-devkit/build-optimizer): update ɵsetClassMetadata call format
It's in a IIFE after https://github.com/angular/angular/pull/33337 lands.
2019-11-20 17:31:19 -08:00
Filipe Silva
7502b73b3c fix(@angular-devkit/build-optimizer): don't remove ɵɵsetNgModuleScope calls
These will be automatically removed after https://github.com/angular/angular/pull/33671 lands because they are in a side-effect free IIFE.
2019-11-20 17:31:19 -08:00
Alan Agius
f943d3a8dc refactor(@angular-devkit/build-angular): rename ngModuleDef to ɵmod 2019-10-16 05:56:23 -07:00
Filipe Silva
07bfd1eeb3 fix(@angular-devkit/build-optimizer): remove deprecated testImportTslib 2019-10-03 14:42:04 -07:00
Filipe Silva
c2b13a7683 feat(@angular-devkit/build-optimizer): don't use getImportTslibTransformer
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.
2019-10-03 14:42:04 -07:00
Alan Agius
ae36fbcd8e fix(@angular-devkit/build-optimizer): fix error when __decorate has no __metadata
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
2019-10-01 11:23:54 -07:00
Filipe Silva
5564ce6ea1 feat(@angular-devkit/build-optimizer): scrub ɵsetClassMetadata and ɵɵsetNgModuleScope calls 2019-09-25 09:43:21 -07:00
Filipe Silva
b1f7537342 refactor(@angular-devkit/build-optimizer): refactor assignment expression identification 2019-09-25 09:43:21 -07:00
Filipe Silva
016977c9ff fix(@angular-devkit/build-optimizer): remove unecessary scrub file checks 2019-09-25 09:43:21 -07:00
Alan Agius
4df025f5f1 fix(@angular-devkit/build-optimizer): don't mark tslib helpers which are suffixed with $ and a number as pure (#15451)
Closes #15392
2019-08-27 10:26:03 -07:00
Alan Agius
59d80f52be fix(@angular-devkit/build-optimizer): replace multiple tslib helpers (#15400)
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`
2019-08-23 11:35:42 -07:00
Alan Agius
e2bb482b44 fix(@angular-devkit/build-optimizer): don't add pure comments to tslib helpers (#15303)
Closes #15301
2019-08-12 11:07:24 -07:00
Filipe Silva
4826378706 fix(@angular-devkit/build-angular): consider local decl in angular core files to be metadata too
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.
2019-08-08 08:28:20 -07:00
Filipe Silva
804c11de8d fix(@angular-devkit/build-optimizer): scrub all metadata form @angular/core
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.
2019-08-02 13:35:39 -07:00
Filipe Silva
fefa2ef15c fix(@angular-devkit/build-optimizer): scrub previously whitelisted angular classes
This whitelist a leftover from older Angular versions and isn't necessary anymore.

Fix #15194
2019-08-02 13:35:39 -07:00
Alan Agius
ab80209c92 fix(@angular-devkit/build-optimizer): don't wrap enum like nodes which are inside of methods.
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
2019-07-29 10:47:28 -07:00
Alan Agius
15ef15e94a style: remove redundant max-line-length disables and fix other lint issues 2019-07-24 19:06:21 -07:00
Alan
2676c2d86a refactor(@angular-devkit/build-optimizer): refactor wrap enums
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
2019-07-11 19:11:51 -07:00
Charles Lyding
8752f21abd fix(@angular-devkit/build-optimizer): wrap classes with a let variable
Classes can technically be re-assigned.  By using a let variable this behavior will be retained and prevent potential runtime errors.

Fixes #14930
2019-07-10 04:14:07 +08:00
Alan
3bb67d81fb fix(@angular-devkit/build-optimizer): incorrectly augmented ES2015 default class exports
Fixes #14769
2019-06-18 18:27:52 -07:00
Alan Agius
c9535a53c2 fix(@angular-devkit/build-optimizer): wrap TypeScript string enums in IIFE
Fixes #14786
2019-06-18 18:27:13 -07:00
Alan Agius
8d479c93d2 test: add test to verify that the new es2015 class wrapping logic handles wrapping of tslib and tsickle classes
Related to https://github.com/ngrx/platform/issues/1905 and https://github.com/ng-packagr/ng-packagr/issues/1307

Fixes #14613
2019-06-06 14:15:30 -07:00
Alan Agius
8104fce690 fix(@angular-devkit/build-optimizer): wrap ClassDeclarations in an IIFE for better treeshaking
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
2019-06-06 14:15:30 -07:00
Alan Agius
f5200775f9 fix(@angular-devkit/build-optimizer): wrap es2015 class expressions for better tree-shaking
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/14610

Fixes #14577
2019-06-06 14:15:30 -07:00
Alan
ccbac7cd21 fix(@angular-devkit/build-optimizer): don't add pure comments in call expressions
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
2019-04-24 07:17:26 -10:00
Alan
b32ad328cf fix(@angular-devkit/build-optimizer): don't add pure comments inside arrow functions
Fixes #13768
2019-03-11 13:45:00 -07:00
Filipe Silva
733efe71e3 fix(@angular-devkit/build-optimizer): prefix renamed extended classes (#13613)
Fix #11796
2019-02-07 08:28:19 -08:00
Alan Agius
e12adf4dcb refactor: create helper functions for pure comments 2019-01-23 10:09:47 -08:00
Alan
7d868947e2 feat(@angular-devkit/build-optimizer): add support for es2015 enums emitted by tsickle
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
2019-01-22 09:39:07 -08:00
Filipe Silva
35b0594f91 feat(@angular-devkit/build-optimizer): also fold ES2015 classes
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
2019-01-22 09:38:48 -08:00
Filipe Silva
6f8c336346 fix(@angular-devkit/build-optimizer): identify relative imports in angular core
Build optimizer was broken for non-FESM files inside @angular/core because it couldn't identify relative imports were still inside core.

This change adds a known list of angular core files as a default, and also allows passing in a override.
2019-01-18 12:01:37 -08:00
Filipe Silva
07ceb05985 fix(@angular-devkit/build-optimizer): prefix renamed classes
Module concatenation may rename classes with the same name. The renaming logic is specific to the bundler so we can't really foresee it.

But the fact remains that the inner function declaration doesn't need to have the same name as the outer one.
2019-01-18 12:01:37 -08:00
Alan Agius
abf99b5b5e fix(@angular-devkit/build-optimizer): add tslib replacement at top of file
Fixes #12568
2018-10-23 11:52:34 -07:00
Charles Lyding
5890759a9f fix(@angular-devkit/build-optimizer): deprecate transform test functions
These were not intended to be part of the public API and will eventually be removed completely.
2018-09-19 11:34:02 -07:00
Charles Lyding
a8a60a7faf refactor(@angular-devkit/build-optimizer): minor type cleanup 2018-09-19 11:34:02 -07:00
Charles Lyding
95f29fbb82 refactor(@angular-devkit/build-optimizer): remove unused import purifier 2018-09-19 11:34:02 -07:00
Filipe Silva
7c5178c698 feat(@angular-devkit/build-optimizer): correctly identify renamed enums 2018-09-06 08:18:41 -07:00
Filipe Silva
6076e16ebc feat(@angular-devkit/build-optimizer): remove constructor __param 2018-09-06 08:18:41 -07:00
Filipe Silva
2962ede3e3 test(@angular-devkit/build-optimizer): also check method metadata 2018-09-06 08:18:41 -07:00
Alan Agius
1a255e6e4e build: bump TypeScript to 2.9 2018-08-04 16:23:37 +01:00
Hans Larsen
483cbe2665 refactor: add tslint-sonarts and a lot of tslint rules
This should clean up the code a bit.

Note: at first I added the no-useless-cast rule, but after getting frustrated
with it (as it has many false positive), I decided to remove the rule but some
useless casts were removed so I let those in the PR.
2018-07-10 15:07:36 -07:00
Charles Lyding
c0bc9bbef4 fix(@angular-devkit/build-optimizer): support object literal methods
Fixes: #11399
2018-07-02 21:30:26 -04:00
Hans Larsen
44086c60ff build: move devkit repo back to angular-cli 2018-06-05 18:50:06 -07:00