Skip to content

Commit e47bb52

Browse files
committed
Revert "refactor(core): tree-shake application_module providers (angular#23477)"
This reverts commit ac2b530. The change is breaking targets in g3 see cl/194336387.
1 parent ac2b530 commit e47bb52

File tree

7 files changed

+20
-58
lines changed

7 files changed

+20
-58
lines changed

packages/core/src/application_init.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
import {isPromise} from '../src/util/lang';
1010

11-
import {Inject, Injectable, InjectionToken, Optional, inject} from './di';
12-
import {defineInjectable} from './di/defs';
13-
11+
import {Inject, Injectable, InjectionToken, Optional} from './di';
1412

1513

1614
/**
@@ -24,22 +22,8 @@ export const APP_INITIALIZER = new InjectionToken<Array<() => void>>('Applicatio
2422
*
2523
* @experimental
2624
*/
25+
@Injectable()
2726
export class ApplicationInitStatus {
28-
// `ngInjectableDef` is required in core-level code because it sits behind
29-
// the injector and any code the loads it inside may run into a dependency
30-
// loop (because Injectable is also in core. Do not use the code below
31-
// (use @Injectable({ providedIn, factory })) instead...
32-
/**
33-
* @internal
34-
* @nocollapse
35-
*/
36-
static ngInjectableDef = defineInjectable({
37-
providedIn: 'root',
38-
factory: function ApplicationInitStatus_Factory() {
39-
return new ApplicationInitStatus(inject(APP_INITIALIZER));
40-
}
41-
});
42-
4327
private resolve: Function;
4428
private reject: Function;
4529
private initialized = false;

packages/core/src/application_module.ts

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

9+
import {ApplicationInitStatus} from './application_init';
10+
import {ApplicationRef} from './application_ref';
911
import {APP_ID_RANDOM_PROVIDER} from './application_tokens';
1012
import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection';
1113
import {Inject, Optional, SkipSelf} from './di/metadata';
12-
import {APP_ROOT} from './di/scope';
1314
import {LOCALE_ID} from './i18n/tokens';
15+
import {Compiler} from './linker/compiler';
1416
import {NgModule} from './metadata';
1517

1618
export function _iterableDiffersFactory() {
@@ -26,14 +28,17 @@ export function _localeFactory(locale?: string): string {
2628
}
2729

2830
/**
31+
* This module includes the providers of @angular/core that are needed
32+
* to bootstrap components via `ApplicationRef`.
33+
*
2934
* @experimental
3035
*/
3136
@NgModule({
3237
providers: [
38+
ApplicationRef,
39+
ApplicationInitStatus,
40+
Compiler,
3341
APP_ID_RANDOM_PROVIDER,
34-
// wen-workers need this value to be here since WorkerApp is defined
35-
// ontop of this application
36-
{provide: APP_ROOT, useValue: true},
3742
{provide: IterableDiffers, useFactory: _iterableDiffersFactory},
3843
{provide: KeyValueDiffers, useFactory: _keyValueDiffersFactory},
3944
{
@@ -44,4 +49,6 @@ export function _localeFactory(locale?: string): string {
4449
]
4550
})
4651
export class ApplicationModule {
52+
// Inject ApplicationRef to make it eager...
53+
constructor(appRef: ApplicationRef) {}
4754
}

packages/core/src/application_ref.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import {isPromise} from '../src/util/lang';
1616
import {ApplicationInitStatus} from './application_init';
1717
import {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens';
1818
import {Console} from './console';
19-
import {Injectable, InjectionToken, Injector, StaticProvider, inject} from './di';
20-
import {defineInjectable} from './di/defs';
19+
import {Injectable, InjectionToken, Injector, StaticProvider} from './di';
2120
import {CompilerFactory, CompilerOptions} from './linker/compiler';
2221
import {ComponentFactory, ComponentRef} from './linker/component_factory';
2322
import {ComponentFactoryBoundToModule, ComponentFactoryResolver} from './linker/component_factory_resolver';
@@ -362,26 +361,8 @@ function optionsReducer<T extends Object>(dst: any, objs: T | T[]): T {
362361
*
363362
*
364363
*/
364+
@Injectable()
365365
export class ApplicationRef {
366-
// `ngInjectableDef` is required in core-level code because it sits behind
367-
// the injector and any code the loads it inside may run into a dependency
368-
// loop (because Injectable is also in core. Do not use the code below
369-
// (use @Injectable({ providedIn, factory })) instead...
370-
/**
371-
* @internal
372-
* @nocollapse
373-
*/
374-
static ngInjectableDef = defineInjectable({
375-
providedIn: 'root',
376-
factory: function ApplicationRef_Factory() {
377-
// Type as any is used here due to a type-related bug in injector with abstract classes
378-
// (#23528)
379-
return new ApplicationRef(
380-
inject(NgZone), inject(Console), inject(Injector as any), inject(ErrorHandler),
381-
inject(ComponentFactoryResolver as any), inject(ApplicationInitStatus));
382-
}
383-
});
384-
385366
/** @internal */
386367
static _tickScope: WtfScopeFn = wtfCreateScope('ApplicationRef#tick()');
387368
private _bootstrapListeners: ((compRef: ComponentRef<any>) => void)[] = [];

packages/core/src/linker/compiler.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Injectable, InjectionToken, StaticProvider, inject} from '../di';
10-
import {defineInjectable} from '../di/defs';
9+
import {Injectable, InjectionToken, StaticProvider} from '../di';
1110
import {MissingTranslationStrategy} from '../i18n/tokens';
1211
import {ViewEncapsulation} from '../metadata';
1312
import {Type} from '../type';
@@ -16,7 +15,6 @@ import {ComponentFactory} from './component_factory';
1615
import {NgModuleFactory} from './ng_module_factory';
1716

1817

19-
2018
/**
2119
* Combination of NgModuleFactory and ComponentFactorys.
2220
*
@@ -43,17 +41,8 @@ function _throwError() {
4341
* of components.
4442
*
4543
*/
44+
@Injectable()
4645
export class Compiler {
47-
// `ngInjectableDef` is required in core-level code because it sits behind
48-
// the injector and any code the loads it inside may run into a dependency
49-
// loop (because Injectable is also in core. Do not use the code below
50-
// (use @Injectable({ providedIn, factory })) instead...
51-
/**
52-
* @internal
53-
* @nocollapse
54-
*/
55-
static ngInjectableDef = defineInjectable({providedIn: 'root', factory: () => new Compiler()});
56-
5746
/**
5847
* Compiles the given NgModule and all of its components. All templates of the components listed
5948
* in `entryComponents` have to be inlined.

packages/platform-server/src/styles_host.ts

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

9-
import {Inject, Injectable, Optional} from '@angular/core';
9+
import {ApplicationRef, Inject, Injectable, Optional} from '@angular/core';
1010
import {DOCUMENT, ɵDomAdapter as DomAdapter, ɵSharedStylesHost as SharedStylesHost, ɵTRANSITION_ID, ɵgetDOM as getDOM} from '@angular/platform-browser';
1111

1212
@Injectable()

packages/upgrade/test/common/downgrade_component_adapter_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {Compiler, Component, ComponentFactory, ComponentRef, Injector, NgModule, Testability, TestabilityRegistry} from '@angular/core';
8+
import {ApplicationRef, Compiler, Component, ComponentFactory, ComponentRef, Injector, NgModule, Testability, TestabilityRegistry} from '@angular/core';
99
import {TestBed, getTestBed, inject} from '@angular/core/testing';
1010
import * as angular from '@angular/upgrade/src/common/angular1';
1111
import {DowngradeComponentAdapter, groupNodesBySelector} from '@angular/upgrade/src/common/downgrade_component_adapter';

tools/public_api_guard/core/core.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export declare class ApplicationInitStatus {
3535

3636
/** @experimental */
3737
export declare class ApplicationModule {
38+
constructor(appRef: ApplicationRef);
3839
}
3940

4041
export declare class ApplicationRef {

0 commit comments

Comments
 (0)