static-injector 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/import/commonjs/index.js +127 -197
- package/import/{es2015 → es2022}/di/create_injector.js +0 -2
- package/import/{es2015 → es2022}/di/forward_ref.js +29 -2
- package/import/{es2015 → es2022}/di/injection_token.js +5 -3
- package/import/{es2015 → es2022}/di/injector.js +15 -16
- package/import/{es2015 → es2022}/di/injector_compatibility.js +8 -3
- package/import/{es2015 → es2022}/di/interface/defs.js +2 -16
- package/import/{es2015 → es2022}/di/interface/injector.js +1 -1
- package/import/es2022/di/provider_collection.js +104 -0
- package/import/{es2015 → es2022}/di/r3_injector.js +46 -15
- package/import/{es2015 → es2022}/errors.js +4 -2
- package/import/{es2015 → es2022}/render3/error_code.js +1 -0
- package/import/es2022/render3/fields.js +22 -0
- package/import/{fesm2015 → fesm2022}/index.js +127 -198
- package/import/typings/di/create_injector.d.ts +3 -5
- package/import/typings/di/forward_ref.d.ts +29 -2
- package/import/typings/di/inject_switch.d.ts +1 -1
- package/import/typings/di/injection_token.d.ts +1 -1
- package/import/typings/di/injector.d.ts +3 -3
- package/import/typings/di/injector_compatibility.d.ts +1 -0
- package/import/typings/di/interface/defs.d.ts +2 -1
- package/import/typings/di/interface/injector.d.ts +2 -2
- package/import/typings/di/interface/provider.d.ts +7 -7
- package/import/typings/di/metadata.d.ts +4 -4
- package/import/typings/di/provider_collection.d.ts +1 -12
- package/import/typings/di/r3_injector.d.ts +8 -6
- package/import/typings/di/scope.d.ts +1 -1
- package/import/typings/errors.d.ts +28 -3
- package/import/typings/render3/fields.d.ts +9 -0
- package/import/typings/util/decorators.d.ts +1 -0
- package/package.json +7 -7
- package/readme.md +4 -1
- package/transform/compiler/src/injectable_compiler_2.d.ts +0 -1
- package/transform/compiler/src/injectable_compiler_2.js +31 -16
- package/transform/compiler/src/output/output_ast.d.ts +53 -10
- package/transform/compiler/src/output/output_ast.js +211 -12
- package/transform/compiler/src/parse_util.js +10 -0
- package/transform/compiler/src/render3/partial/api.js +1 -1
- package/transform/compiler/src/render3/r3_factory.d.ts +0 -8
- package/transform/compiler/src/render3/r3_factory.js +5 -4
- package/transform/compiler/src/render3/r3_identifiers.js +37 -37
- package/transform/compiler/src/render3/view/util.js +1 -3
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +2 -4
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +1 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +5 -9
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +2 -1
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +12 -8
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +8 -4
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +1 -1
- package/transform/compiler-cli/src/ngtsc/imports/src/default.js +1 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +24 -173
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +2 -51
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +5 -3
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +5 -10
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +5 -23
- package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -21
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +1 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +7 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/context.js +1 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +1 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +10 -4
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +2 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +20 -16
- package/transform/injectable-transform.d.ts +2 -2
- package/transform/injectable-transform.js +32 -6
- package/import/es2015/di/provider_collection.js +0 -244
- package/import/es2015/render3/fields.js +0 -11
- /package/import/{es2015 → es2022}/di/initializer_token.js +0 -0
- /package/import/{es2015 → es2022}/di/inject_switch.js +0 -0
- /package/import/{es2015 → es2022}/di/injectable.js +0 -0
- /package/import/{es2015 → es2022}/di/injector_marker.js +0 -0
- /package/import/{es2015 → es2022}/di/injector_token.js +0 -0
- /package/import/{es2015 → es2022}/di/interface/provider.js +0 -0
- /package/import/{es2015 → es2022}/di/internal_tokens.js +0 -0
- /package/import/{es2015 → es2022}/di/metadata.js +0 -0
- /package/import/{es2015 → es2022}/di/null_injector.js +0 -0
- /package/import/{es2015 → es2022}/di/provider_token.js +0 -0
- /package/import/{es2015 → es2022}/di/scope.js +0 -0
- /package/import/{es2015 → es2022}/error_details_base_url.js +0 -0
- /package/import/{es2015 → es2022}/index.js +0 -0
- /package/import/{es2015 → es2022}/interface/lifecycle_hooks.js +0 -0
- /package/import/{es2015 → es2022}/interface/type.js +0 -0
- /package/import/{es2015 → es2022}/render3/definition_factory.js +0 -0
- /package/import/{es2015 → es2022}/render3/di.js +0 -0
- /package/import/{es2015 → es2022}/render3/errors_di.js +0 -0
- /package/import/{es2015 → es2022}/render3/instructions/di.js +0 -0
- /package/import/{es2015 → es2022}/render3/util/stringify_utils.js +0 -0
- /package/import/{es2015 → es2022}/util/array_utils.js +0 -0
- /package/import/{es2015 → es2022}/util/closure.js +0 -0
- /package/import/{es2015 → es2022}/util/decorators.js +0 -0
- /package/import/{es2015 → es2022}/util/empty.js +0 -0
- /package/import/{es2015 → es2022}/util/property.js +0 -0
- /package/import/{es2015 → es2022}/util/stringify.js +0 -0
|
@@ -16,7 +16,7 @@ import { NullInjector } from './null_injector';
|
|
|
16
16
|
* dependencies of various types with [injection tokens](guide/glossary#di-token).
|
|
17
17
|
*
|
|
18
18
|
* @see ["DI Providers"](guide/dependency-injection-providers).
|
|
19
|
-
* @see
|
|
19
|
+
* @see {@link StaticProvider}
|
|
20
20
|
*
|
|
21
21
|
* @usageNotes
|
|
22
22
|
*
|
|
@@ -35,27 +35,26 @@ import { NullInjector } from './null_injector';
|
|
|
35
35
|
* @publicApi
|
|
36
36
|
*/
|
|
37
37
|
export class Injector {
|
|
38
|
+
static THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
|
|
39
|
+
static NULL = new NullInjector();
|
|
38
40
|
static create(options, parent) {
|
|
39
|
-
var _a;
|
|
40
41
|
if (Array.isArray(options)) {
|
|
41
42
|
return createInjector({ name: '' }, parent, options, '');
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
44
|
-
const name =
|
|
45
|
+
const name = options.name ?? '';
|
|
45
46
|
return createInjector({ name }, options.parent, options.providers, name);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
49
|
+
/** @nocollapse */
|
|
50
|
+
static ɵprov = /** @pureOrBreakMyCode */ ɵɵdefineInjectable({
|
|
51
|
+
token: Injector,
|
|
52
|
+
providedIn: 'any',
|
|
53
|
+
factory: () => ɵɵinject(INJECTOR),
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* @internal
|
|
57
|
+
* @nocollapse
|
|
58
|
+
*/
|
|
59
|
+
static __NG_ELEMENT_ID__ = -1 /* InjectorMarkers.Injector */;
|
|
48
60
|
}
|
|
49
|
-
Injector.THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
|
|
50
|
-
Injector.NULL = new NullInjector();
|
|
51
|
-
/** @nocollapse */
|
|
52
|
-
Injector.ɵprov = ɵɵdefineInjectable({
|
|
53
|
-
token: Injector,
|
|
54
|
-
providedIn: 'any',
|
|
55
|
-
factory: () => ɵɵinject(INJECTOR),
|
|
56
|
-
});
|
|
57
|
-
/**
|
|
58
|
-
* @internal
|
|
59
|
-
* @nocollapse
|
|
60
|
-
*/
|
|
61
|
-
Injector.__NG_ELEMENT_ID__ = -1 /* InjectorMarkers.Injector */;
|
|
@@ -30,6 +30,9 @@ export const SOURCE = '__source';
|
|
|
30
30
|
* - Injector instance: Use the injector for resolution.
|
|
31
31
|
*/
|
|
32
32
|
let _currentInjector = undefined;
|
|
33
|
+
export function getCurrentInjector() {
|
|
34
|
+
return _currentInjector;
|
|
35
|
+
}
|
|
33
36
|
export function setCurrentInjector(injector) {
|
|
34
37
|
const former = _currentInjector;
|
|
35
38
|
_currentInjector = injector;
|
|
@@ -43,7 +46,8 @@ export function injectInjectorOnly(token, flags = InjectFlags.Default) {
|
|
|
43
46
|
return injectRootLimpMode(token, undefined, flags);
|
|
44
47
|
}
|
|
45
48
|
else {
|
|
46
|
-
|
|
49
|
+
const value = _currentInjector.get(token, flags & InjectFlags.Optional ? null : undefined, flags);
|
|
50
|
+
return value;
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
53
|
export function ɵɵinject(token, flags = InjectFlags.Default) {
|
|
@@ -63,13 +67,14 @@ export function ɵɵinvalidFactoryDep(index) {
|
|
|
63
67
|
}
|
|
64
68
|
/**
|
|
65
69
|
* Injects a token from the currently active injector.
|
|
66
|
-
* `inject` is only supported
|
|
67
|
-
* during:
|
|
70
|
+
* `inject` is only supported in an [injection context](/guide/dependency-injection-context). It can
|
|
71
|
+
* be used during:
|
|
68
72
|
* - Construction (via the `constructor`) of a class being instantiated by the DI system, such
|
|
69
73
|
* as an `@Injectable` or `@Component`.
|
|
70
74
|
* - In the initializer for fields of such classes.
|
|
71
75
|
* - In the factory function specified for `useFactory` of a `Provider` or an `@Injectable`.
|
|
72
76
|
* - In the `factory` function specified for an `InjectionToken`.
|
|
77
|
+
* - In a stackframe of a function call in a DI context
|
|
73
78
|
*
|
|
74
79
|
* @param token A token that represents a dependency that should be injected.
|
|
75
80
|
* @param flags Optional flags that control how injection is executed.
|
|
@@ -18,7 +18,8 @@ import { getClosureSafeProperty } from '../../util/property';
|
|
|
18
18
|
* with an `@NgModule` or other `InjectorType`, or by specifying that this injectable should be
|
|
19
19
|
* provided in the `'root'` injector, which will be the application-level injector in most apps.
|
|
20
20
|
* * `factory` gives the zero argument function which will create an instance of the injectable.
|
|
21
|
-
* The factory can call `inject` to access the `Injector` and request injection
|
|
21
|
+
* The factory can call [`inject`](api/core/inject) to access the `Injector` and request injection
|
|
22
|
+
* of dependencies.
|
|
22
23
|
*
|
|
23
24
|
* @codeGenApi
|
|
24
25
|
* @publicApi This instruction has been emitted by ViewEngine for some time and is deployed to npm.
|
|
@@ -81,27 +82,12 @@ function getOwnDefinition(type, field) {
|
|
|
81
82
|
export function getInheritedInjectableDef(type) {
|
|
82
83
|
const def = type && (type[NG_PROV_DEF] || null);
|
|
83
84
|
if (def) {
|
|
84
|
-
const typeName = getTypeName(type);
|
|
85
85
|
return def;
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
88
88
|
return null;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
/** Gets the name of a type, accounting for some cross-browser differences. */
|
|
92
|
-
function getTypeName(type) {
|
|
93
|
-
// `Function.prototype.name` behaves differently between IE and other browsers. In most browsers
|
|
94
|
-
// it'll always return the name of the function itself, no matter how many other functions it
|
|
95
|
-
// inherits from. On IE the function doesn't have its own `name` property, but it takes it from
|
|
96
|
-
// the lowest level in the prototype chain. E.g. if we have `class Foo extends Parent` most
|
|
97
|
-
// browsers will evaluate `Foo.name` to `Foo` while IE will return `Parent`. We work around
|
|
98
|
-
// the issue by converting the function to a string and parsing its name out that way via a regex.
|
|
99
|
-
if (type.hasOwnProperty('name')) {
|
|
100
|
-
return type.name;
|
|
101
|
-
}
|
|
102
|
-
const match = ('' + type).match(/^function\s*([^\s(]+)/);
|
|
103
|
-
return match === null ? '' : match[1];
|
|
104
|
-
}
|
|
105
91
|
/**
|
|
106
92
|
* Read the injector def type in a way which is immune to accidentally reading inherited value.
|
|
107
93
|
*
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { getClosureSafeProperty } from '../util/property';
|
|
9
|
+
/**
|
|
10
|
+
* Wrap an array of `Provider`s into `EnvironmentProviders`, preventing them from being accidentally
|
|
11
|
+
* referenced in `@Component` in a component injector.
|
|
12
|
+
*/
|
|
13
|
+
export function makeEnvironmentProviders(providers) {
|
|
14
|
+
return {
|
|
15
|
+
ɵproviders: providers,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Collects providers from all NgModules and standalone components, including transitively imported
|
|
20
|
+
* ones.
|
|
21
|
+
*
|
|
22
|
+
* Providers extracted via `importProvidersFrom` are only usable in an application injector or
|
|
23
|
+
* another environment injector (such as a route injector). They should not be used in component
|
|
24
|
+
* providers.
|
|
25
|
+
*
|
|
26
|
+
* More information about standalone components can be found in [this
|
|
27
|
+
* guide](guide/standalone-components).
|
|
28
|
+
*
|
|
29
|
+
* @usageNotes
|
|
30
|
+
* The results of the `importProvidersFrom` call can be used in the `bootstrapApplication` call:
|
|
31
|
+
*
|
|
32
|
+
* ```typescript
|
|
33
|
+
* await bootstrapApplication(RootComponent, {
|
|
34
|
+
* providers: [
|
|
35
|
+
* importProvidersFrom(NgModuleOne, NgModuleTwo)
|
|
36
|
+
* ]
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* You can also use the `importProvidersFrom` results in the `providers` field of a route, when a
|
|
41
|
+
* standalone component is used:
|
|
42
|
+
*
|
|
43
|
+
* ```typescript
|
|
44
|
+
* export const ROUTES: Route[] = [
|
|
45
|
+
* {
|
|
46
|
+
* path: 'foo',
|
|
47
|
+
* providers: [
|
|
48
|
+
* importProvidersFrom(NgModuleOne, NgModuleTwo)
|
|
49
|
+
* ],
|
|
50
|
+
* component: YourStandaloneComponent
|
|
51
|
+
* }
|
|
52
|
+
* ];
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @returns Collected providers from the specified list of types.
|
|
56
|
+
* @publicApi
|
|
57
|
+
*/
|
|
58
|
+
export function importProvidersFrom(...sources) {
|
|
59
|
+
return {
|
|
60
|
+
ɵproviders: internalImportProvidersFrom(true, sources),
|
|
61
|
+
ɵfromNgModule: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function internalImportProvidersFrom(checkForStandaloneCmp, ...sources) {
|
|
65
|
+
const providersOut = [];
|
|
66
|
+
const dedup = new Set(); // already seen types
|
|
67
|
+
let injectorTypesWithProviders;
|
|
68
|
+
const collectProviders = (provider) => {
|
|
69
|
+
providersOut.push(provider);
|
|
70
|
+
};
|
|
71
|
+
// Collect all providers from `ModuleWithProviders` types.
|
|
72
|
+
if (injectorTypesWithProviders !== undefined) {
|
|
73
|
+
processInjectorTypesWithProviders(injectorTypesWithProviders, collectProviders);
|
|
74
|
+
}
|
|
75
|
+
return providersOut;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Collects all providers from the list of `ModuleWithProviders` and appends them to the provided
|
|
79
|
+
* array.
|
|
80
|
+
*/
|
|
81
|
+
function processInjectorTypesWithProviders(typesWithProviders, visitor) {
|
|
82
|
+
for (let i = 0; i < typesWithProviders.length; i++) {
|
|
83
|
+
const { ngModule, providers } = typesWithProviders[i];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export const USE_VALUE = getClosureSafeProperty({
|
|
87
|
+
provide: String,
|
|
88
|
+
useValue: getClosureSafeProperty,
|
|
89
|
+
});
|
|
90
|
+
export function isValueProvider(value) {
|
|
91
|
+
return value !== null && typeof value == 'object' && USE_VALUE in value;
|
|
92
|
+
}
|
|
93
|
+
export function isExistingProvider(value) {
|
|
94
|
+
return !!(value && value.useExisting);
|
|
95
|
+
}
|
|
96
|
+
export function isFactoryProvider(value) {
|
|
97
|
+
return !!(value && value.useFactory);
|
|
98
|
+
}
|
|
99
|
+
export function isTypeProvider(value) {
|
|
100
|
+
return typeof value === 'function';
|
|
101
|
+
}
|
|
102
|
+
export function isClassProvider(value) {
|
|
103
|
+
return !!value.useClass;
|
|
104
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { RuntimeError } from '../errors';
|
|
9
9
|
import { getFactoryDef } from '../render3/definition_factory';
|
|
10
|
+
import { NG_ENV_ID } from '../render3/fields';
|
|
10
11
|
import { newArray } from '../util/array_utils';
|
|
11
12
|
import { EMPTY_ARRAY } from '../util/empty';
|
|
12
13
|
import { stringify } from '../util/stringify';
|
|
@@ -52,29 +53,33 @@ export function getNullInjector() {
|
|
|
52
53
|
export class EnvironmentInjector {
|
|
53
54
|
}
|
|
54
55
|
export class R3Injector extends EnvironmentInjector {
|
|
56
|
+
parent;
|
|
57
|
+
source;
|
|
58
|
+
scopes;
|
|
59
|
+
/**
|
|
60
|
+
* Map of tokens to records which contain the instances of those tokens.
|
|
61
|
+
* - `null` value implies that we don't have the record. Used by tree-shakable injectors
|
|
62
|
+
* to prevent further searches.
|
|
63
|
+
*/
|
|
64
|
+
records = new Map();
|
|
65
|
+
/**
|
|
66
|
+
* Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
|
|
67
|
+
*/
|
|
68
|
+
_ngOnDestroyHooks = new Set();
|
|
69
|
+
_onDestroyHooks = [];
|
|
55
70
|
/**
|
|
56
71
|
* Flag indicating that this injector was previously destroyed.
|
|
57
72
|
*/
|
|
58
73
|
get destroyed() {
|
|
59
74
|
return this._destroyed;
|
|
60
75
|
}
|
|
76
|
+
_destroyed = false;
|
|
77
|
+
injectorDefTypes;
|
|
61
78
|
constructor(providers, parent, source, scopes) {
|
|
62
79
|
super();
|
|
63
80
|
this.parent = parent;
|
|
64
81
|
this.source = source;
|
|
65
82
|
this.scopes = scopes;
|
|
66
|
-
/**
|
|
67
|
-
* Map of tokens to records which contain the instances of those tokens.
|
|
68
|
-
* - `null` value implies that we don't have the record. Used by tree-shakable injectors
|
|
69
|
-
* to prevent further searches.
|
|
70
|
-
*/
|
|
71
|
-
this.records = new Map();
|
|
72
|
-
/**
|
|
73
|
-
* Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
|
|
74
|
-
*/
|
|
75
|
-
this._ngOnDestroyHooks = new Set();
|
|
76
|
-
this._onDestroyHooks = [];
|
|
77
|
-
this._destroyed = false;
|
|
78
83
|
// Start off by creating Records for every provider.
|
|
79
84
|
forEachSingleProvider(providers, (provider) => this.processProvider(provider));
|
|
80
85
|
// Make sure the INJECTOR token provides this injector.
|
|
@@ -106,7 +111,11 @@ export class R3Injector extends EnvironmentInjector {
|
|
|
106
111
|
for (const service of this._ngOnDestroyHooks) {
|
|
107
112
|
service.ngOnDestroy();
|
|
108
113
|
}
|
|
109
|
-
|
|
114
|
+
const onDestroyHooks = this._onDestroyHooks;
|
|
115
|
+
// Reset the _onDestroyHooks array before iterating over it to prevent hooks that unregister
|
|
116
|
+
// themselves from mutating the array during iteration.
|
|
117
|
+
this._onDestroyHooks = [];
|
|
118
|
+
for (const hook of onDestroyHooks) {
|
|
110
119
|
hook();
|
|
111
120
|
}
|
|
112
121
|
}
|
|
@@ -115,16 +124,19 @@ export class R3Injector extends EnvironmentInjector {
|
|
|
115
124
|
this.records.clear();
|
|
116
125
|
this._ngOnDestroyHooks.clear();
|
|
117
126
|
this.injectorDefTypes.clear();
|
|
118
|
-
this._onDestroyHooks.length = 0;
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
129
|
onDestroy(callback) {
|
|
130
|
+
this.assertNotDestroyed();
|
|
122
131
|
this._onDestroyHooks.push(callback);
|
|
132
|
+
return () => this.removeOnDestroy(callback);
|
|
123
133
|
}
|
|
124
134
|
runInContext(fn) {
|
|
125
135
|
this.assertNotDestroyed();
|
|
126
136
|
const previousInjector = setCurrentInjector(this);
|
|
127
137
|
const previousInjectImplementation = setInjectImplementation(undefined);
|
|
138
|
+
if (false) {
|
|
139
|
+
}
|
|
128
140
|
try {
|
|
129
141
|
return fn();
|
|
130
142
|
}
|
|
@@ -135,8 +147,13 @@ export class R3Injector extends EnvironmentInjector {
|
|
|
135
147
|
}
|
|
136
148
|
get(token, notFoundValue = THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
|
|
137
149
|
this.assertNotDestroyed();
|
|
150
|
+
if (token.hasOwnProperty(NG_ENV_ID)) {
|
|
151
|
+
return token[NG_ENV_ID](this);
|
|
152
|
+
}
|
|
138
153
|
flags = convertToBitFlags(flags);
|
|
139
154
|
// Set the injection context.
|
|
155
|
+
if (false) {
|
|
156
|
+
}
|
|
140
157
|
const previousInjector = setCurrentInjector(this);
|
|
141
158
|
const previousInjectImplementation = setInjectImplementation(undefined);
|
|
142
159
|
try {
|
|
@@ -204,6 +221,8 @@ export class R3Injector extends EnvironmentInjector {
|
|
|
204
221
|
resolveInjectorInitializers() {
|
|
205
222
|
const previousInjector = setCurrentInjector(this);
|
|
206
223
|
const previousInjectImplementation = setInjectImplementation(undefined);
|
|
224
|
+
if (false) {
|
|
225
|
+
}
|
|
207
226
|
try {
|
|
208
227
|
const initializers = this.get(ENVIRONMENT_INITIALIZER.multi, EMPTY_ARRAY, InjectFlags.Self);
|
|
209
228
|
if (false) {
|
|
@@ -242,6 +261,8 @@ export class R3Injector extends EnvironmentInjector {
|
|
|
242
261
|
: resolveForwardRef(provider && provider.provide);
|
|
243
262
|
// Construct a `Record` for the provider.
|
|
244
263
|
const record = providerToRecord(provider);
|
|
264
|
+
if (false) {
|
|
265
|
+
}
|
|
245
266
|
if (!isTypeProvider(provider) && provider.multi === true) {
|
|
246
267
|
// If the provider indicates that it's a multi-provider, process it specially.
|
|
247
268
|
// First check whether it's been defined already.
|
|
@@ -271,7 +292,11 @@ export class R3Injector extends EnvironmentInjector {
|
|
|
271
292
|
}
|
|
272
293
|
else if (record.value === NOT_YET) {
|
|
273
294
|
record.value = CIRCULAR;
|
|
274
|
-
|
|
295
|
+
if (false) {
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
record.value = record.factory();
|
|
299
|
+
}
|
|
275
300
|
}
|
|
276
301
|
if (typeof record.value === 'object' &&
|
|
277
302
|
record.value &&
|
|
@@ -292,6 +317,12 @@ export class R3Injector extends EnvironmentInjector {
|
|
|
292
317
|
return this.injectorDefTypes.has(providedIn);
|
|
293
318
|
}
|
|
294
319
|
}
|
|
320
|
+
removeOnDestroy(callback) {
|
|
321
|
+
const destroyCBIdx = this._onDestroyHooks.indexOf(callback);
|
|
322
|
+
if (destroyCBIdx !== -1) {
|
|
323
|
+
this._onDestroyHooks.splice(destroyCBIdx, 1);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
295
326
|
}
|
|
296
327
|
function injectableDefOrInjectorDefFactory(token) {
|
|
297
328
|
// Most tokens will have an injectable def directly on them, which specifies a factory directly.
|
|
@@ -18,9 +18,11 @@
|
|
|
18
18
|
*
|
|
19
19
|
* Note: the `message` argument contains a descriptive error message as a string in development
|
|
20
20
|
* mode (when the `ngDevMode` is defined). In production mode (after tree-shaking pass), the
|
|
21
|
-
* `message` argument becomes `false`, thus we account for it in the typings and the runtime
|
|
21
|
+
* `message` argument becomes `false`, thus we account for it in the typings and the runtime
|
|
22
|
+
* logic.
|
|
22
23
|
*/
|
|
23
24
|
export class RuntimeError extends Error {
|
|
25
|
+
code;
|
|
24
26
|
constructor(code, message) {
|
|
25
27
|
super(formatRuntimeError(code, message));
|
|
26
28
|
this.code = code;
|
|
@@ -35,7 +37,7 @@ export function formatRuntimeError(code, message) {
|
|
|
35
37
|
// generate a link to the error details page on angular.io.
|
|
36
38
|
// We also prepend `0` to non-compile-time errors.
|
|
37
39
|
const fullCode = `NG0${Math.abs(code)}`;
|
|
38
|
-
let errorMessage = `${fullCode}${message ? ': ' + message
|
|
40
|
+
let errorMessage = `${fullCode}${message ? ': ' + message : ''}`;
|
|
39
41
|
if (false) {
|
|
40
42
|
}
|
|
41
43
|
return errorMessage;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { getClosureSafeProperty } from '../util/property';
|
|
9
|
+
export const NG_FACTORY_DEF = getClosureSafeProperty({
|
|
10
|
+
ɵfac: getClosureSafeProperty,
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* The `NG_ENV_ID` field on a DI token indicates special processing in the `EnvironmentInjector`:
|
|
14
|
+
* getting such tokens from the `EnvironmentInjector` will bypass the standard DI resolution
|
|
15
|
+
* strategy and instead will return implementation produced by the `NG_ENV_ID` factory function.
|
|
16
|
+
*
|
|
17
|
+
* This particular retrieval of DI tokens is mostly done to eliminate circular dependencies and
|
|
18
|
+
* improve tree-shaking.
|
|
19
|
+
*/
|
|
20
|
+
export const NG_ENV_ID = getClosureSafeProperty({
|
|
21
|
+
__NG_ENV_ID__: getClosureSafeProperty,
|
|
22
|
+
});
|