Skip to content

Commit

Permalink
perf(core): make Compiler, ApplicationRef and `ApplicationInitSta…
Browse files Browse the repository at this point in the history
…tus` tree-shakable (angular#45102)

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 angular#45102
  • Loading branch information
AndrewKushnir committed Mar 1, 2022
1 parent d309c43 commit 56e4e26
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 44 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/application_init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const APP_INITIALIZER =
*
* @publicApi
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class ApplicationInitStatus {
private resolve = noop;
private reject = noop;
Expand Down
18 changes: 1 addition & 17 deletions packages/core/src/application_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/

import {APP_INITIALIZER, ApplicationInitStatus} from './application_init';
import {ApplicationRef} from './application_ref';
import {APP_ID_RANDOM_PROVIDER} from './application_tokens';
import {Injector, StaticProvider} from './di';
import {StaticProvider} from './di';
import {Inject, Optional, SkipSelf} from './di/metadata';
import {ErrorHandler} from './error_handler';
import {DEFAULT_LOCALE_ID, USD_CURRENCY_CODE} from './i18n/localization';
import {DEFAULT_CURRENCY_CODE, LOCALE_ID} from './i18n/tokens';
import {ComponentFactoryResolver} from './linker';
import {Compiler} from './linker/compiler';
import {NgModule} from './metadata';
import {NgZone} from './zone';

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

Expand Down Expand Up @@ -56,17 +51,6 @@ export function getGlobalLocale(): string {
* that is used to configure the root injector for bootstrapping.
*/
export const APPLICATION_MODULE_PROVIDERS: StaticProvider[] = [
{
provide: ApplicationRef,
useClass: ApplicationRef,
deps: [NgZone, Injector, ErrorHandler, ComponentFactoryResolver, ApplicationInitStatus]
},
{
provide: ApplicationInitStatus,
useClass: ApplicationInitStatus,
deps: [[new Optional(), APP_INITIALIZER]]
},
{provide: Compiler, useClass: Compiler, deps: []},
APP_ID_RANDOM_PROVIDER,
{
provide: LOCALE_ID,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/application_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ function optionsReducer<T extends Object>(dst: any, objs: T|T[]): T {
*
* @publicApi
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class ApplicationRef {
/** @internal */
private _bootstrapListeners: ((compRef: ComponentRef<any>) => void)[] = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/linker/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ModuleWithComponentFactories<T> {
* See [JIT API changes due to ViewEngine deprecation](guide/deprecations#jit-api-changes) for
* additional context.
*/
@Injectable()
@Injectable({providedIn: 'root'})
export class Compiler {
/**
* Compiles the given NgModule and all of its components. All templates of the components listed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@
{
"name": "CommonModule"
},
{
"name": "Compiler"
},
{
"name": "ComponentFactory"
},
Expand Down Expand Up @@ -347,9 +344,6 @@
{
"name": "NgLocalization"
},
{
"name": "NgModuleFactory2"
},
{
"name": "NgModuleRef"
},
Expand Down Expand Up @@ -422,9 +416,6 @@
{
"name": "RuntimeError"
},
{
"name": "SCHEDULER"
},
{
"name": "SELF_TOKEN_REGEX"
},
Expand Down Expand Up @@ -677,6 +668,9 @@
{
"name": "collectNativeNodes"
},
{
"name": "compileNgModuleFactory"
},
{
"name": "computeStaticStyling"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@
{
"name": "CommonModule"
},
{
"name": "Compiler"
},
{
"name": "ComponentFactory"
},
Expand Down Expand Up @@ -437,9 +434,6 @@
{
"name": "RuntimeError"
},
{
"name": "SCHEDULER"
},
{
"name": "SERVER_TRANSITION_PROVIDERS"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@
{
"name": "CommonModule"
},
{
"name": "Compiler"
},
{
"name": "ComponentFactory"
},
Expand Down Expand Up @@ -431,9 +428,6 @@
{
"name": "RuntimeError"
},
{
"name": "SCHEDULER"
},
{
"name": "SERVER_TRANSITION_PROVIDERS"
},
Expand Down
3 changes: 0 additions & 3 deletions packages/core/test/bundling/router/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,6 @@
{
"name": "SAFE_URL_PATTERN"
},
{
"name": "SCHEDULER"
},
{
"name": "SEGMENT_RE"
},
Expand Down

0 comments on commit 56e4e26

Please sign in to comment.