Skip to content

Commit 82d7728

Browse files
AndrewKushnirthePunderWoman
authored andcommitted
perf(core): make Compiler, ApplicationRef and ApplicationInitStatus tree-shakable (#45102) (#45222)
The `Compiler`, `ApplicationRef` and `ApplicationInitStatus` classes are registered as non-tree-shakable providers in the `ApplicationModule`. This commit converts them to the tree-shakable providers instead. PR Close #45102 PR Close #45222
1 parent 2bebaa9 commit 82d7728

8 files changed

Lines changed: 7 additions & 44 deletions

File tree

packages/core/src/application_init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const APP_INITIALIZER =
9191
*
9292
* @publicApi
9393
*/
94-
@Injectable()
94+
@Injectable({providedIn: 'root'})
9595
export class ApplicationInitStatus {
9696
private resolve = noop;
9797
private reject = noop;

packages/core/src/application_module.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {APP_INITIALIZER, ApplicationInitStatus} from './application_init';
109
import {ApplicationRef} from './application_ref';
1110
import {APP_ID_RANDOM_PROVIDER} from './application_tokens';
12-
import {Injector, StaticProvider} from './di';
11+
import {StaticProvider} from './di';
1312
import {Inject, Optional, SkipSelf} from './di/metadata';
14-
import {ErrorHandler} from './error_handler';
1513
import {DEFAULT_LOCALE_ID, USD_CURRENCY_CODE} from './i18n/localization';
1614
import {DEFAULT_CURRENCY_CODE, LOCALE_ID} from './i18n/tokens';
17-
import {ComponentFactoryResolver} from './linker';
18-
import {Compiler} from './linker/compiler';
1915
import {NgModule} from './metadata';
20-
import {NgZone} from './zone';
2116

2217
declare const $localize: {locale?: string};
2318

@@ -56,17 +51,6 @@ export function getGlobalLocale(): string {
5651
* that is used to configure the root injector for bootstrapping.
5752
*/
5853
export const APPLICATION_MODULE_PROVIDERS: StaticProvider[] = [
59-
{
60-
provide: ApplicationRef,
61-
useClass: ApplicationRef,
62-
deps: [NgZone, Injector, ErrorHandler, ComponentFactoryResolver, ApplicationInitStatus]
63-
},
64-
{
65-
provide: ApplicationInitStatus,
66-
useClass: ApplicationInitStatus,
67-
deps: [[new Optional(), APP_INITIALIZER]]
68-
},
69-
{provide: Compiler, useClass: Compiler, deps: []},
7054
APP_ID_RANDOM_PROVIDER,
7155
{
7256
provide: LOCALE_ID,

packages/core/src/application_ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ function optionsReducer<T extends Object>(dst: any, objs: T|T[]): T {
564564
*
565565
* @publicApi
566566
*/
567-
@Injectable()
567+
@Injectable({providedIn: 'root'})
568568
export class ApplicationRef {
569569
/** @internal */
570570
private _bootstrapListeners: ((compRef: ComponentRef<any>) => void)[] = [];

packages/core/src/linker/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class ModuleWithComponentFactories<T> {
5252
* See [JIT API changes due to ViewEngine deprecation](guide/deprecations#jit-api-changes) for
5353
* additional context.
5454
*/
55-
@Injectable()
55+
@Injectable({providedIn: 'root'})
5656
export class Compiler {
5757
/**
5858
* Compiles the given NgModule and all of its components. All templates of the components listed

packages/core/test/bundling/animations/bundle.golden_symbols.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@
122122
{
123123
"name": "CommonModule"
124124
},
125-
{
126-
"name": "Compiler"
127-
},
128125
{
129126
"name": "ComponentFactory"
130127
},
@@ -347,9 +344,6 @@
347344
{
348345
"name": "NgLocalization"
349346
},
350-
{
351-
"name": "NgModuleFactory2"
352-
},
353347
{
354348
"name": "NgModuleRef"
355349
},
@@ -422,9 +416,6 @@
422416
{
423417
"name": "RuntimeError"
424418
},
425-
{
426-
"name": "SCHEDULER"
427-
},
428419
{
429420
"name": "SELF_TOKEN_REGEX"
430421
},
@@ -677,6 +668,9 @@
677668
{
678669
"name": "collectNativeNodes"
679670
},
671+
{
672+
"name": "compileNgModuleFactory"
673+
},
680674
{
681675
"name": "computeStaticStyling"
682676
},

packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@
8686
{
8787
"name": "CommonModule"
8888
},
89-
{
90-
"name": "Compiler"
91-
},
9289
{
9390
"name": "ComponentFactory"
9491
},
@@ -437,9 +434,6 @@
437434
{
438435
"name": "RuntimeError"
439436
},
440-
{
441-
"name": "SCHEDULER"
442-
},
443437
{
444438
"name": "SERVER_TRANSITION_PROVIDERS"
445439
},

packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@
9292
{
9393
"name": "CommonModule"
9494
},
95-
{
96-
"name": "Compiler"
97-
},
9895
{
9996
"name": "ComponentFactory"
10097
},
@@ -431,9 +428,6 @@
431428
{
432429
"name": "RuntimeError"
433430
},
434-
{
435-
"name": "SCHEDULER"
436-
},
437431
{
438432
"name": "SERVER_TRANSITION_PROVIDERS"
439433
},

packages/core/test/bundling/router/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,6 @@
578578
{
579579
"name": "SAFE_URL_PATTERN"
580580
},
581-
{
582-
"name": "SCHEDULER"
583-
},
584581
{
585582
"name": "SEGMENT_RE"
586583
},

0 commit comments

Comments
 (0)