static-injector 5.0.2 → 6.0.1
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/change_detection/scheduling/zoneless_scheduling.d.ts +37 -0
- package/import/change_detection/scheduling/zoneless_scheduling_impl.d.ts +16 -0
- package/import/core_reactivity_export_internal.d.ts +17 -0
- package/import/di/contextual.d.ts +36 -0
- package/{typings → import}/di/create_injector.d.ts +1 -1
- package/{typings → import}/di/forward_ref.d.ts +2 -2
- package/import/di/index.d.ts +3 -0
- package/{typings → import}/di/initializer_token.d.ts +8 -1
- package/{typings → import}/di/inject_switch.d.ts +2 -2
- package/{typings → import}/di/injectable.d.ts +2 -2
- package/{typings → import}/di/injection_token.d.ts +3 -4
- package/{typings → import}/di/injector.d.ts +1 -1
- package/{typings → import}/di/injector_compatibility.d.ts +1 -1
- package/{typings → import}/di/injector_marker.d.ts +1 -1
- package/{typings → import}/di/injector_token.d.ts +1 -1
- package/{typings → import}/di/interface/defs.d.ts +1 -1
- package/{typings → import}/di/interface/injector.d.ts +1 -1
- package/{typings → import}/di/interface/provider.d.ts +1 -1
- package/{typings → import}/di/internal_tokens.d.ts +1 -1
- package/{typings → import}/di/metadata.d.ts +5 -9
- package/{typings → import}/di/null_injector.d.ts +1 -1
- package/{typings → import}/di/provider_collection.d.ts +31 -3
- package/{typings → import}/di/provider_token.d.ts +1 -1
- package/{typings → import}/di/r3_injector.d.ts +2 -2
- package/{typings → import}/di/scope.d.ts +1 -1
- package/{typings → import}/di.d.ts +1 -1
- package/import/error_handler.d.ts +45 -0
- package/{typings → import}/errors.d.ts +9 -7
- package/import/index.d.ts +37 -0
- package/{typings → import}/interface/lifecycle_hooks.d.ts +1 -1
- package/{typings → import}/interface/type.d.ts +4 -9
- package/import/linker/destroy_ref.d.ts +44 -0
- package/import/pending_tasks.d.ts +78 -0
- package/{typings → import}/render3/definition_factory.d.ts +1 -1
- package/{typings → import}/render3/errors_di.d.ts +1 -1
- package/{typings → import}/render3/fields.d.ts +1 -1
- package/{typings → import}/render3/instructions/di.d.ts +1 -1
- package/import/render3/reactivity/api.d.ts +27 -0
- package/import/render3/reactivity/asserts.d.ts +16 -0
- package/import/render3/reactivity/computed.d.ts +25 -0
- package/import/render3/reactivity/effect.d.ts +121 -0
- package/import/render3/reactivity/linked_signal.d.ts +33 -0
- package/import/render3/reactivity/microtask_effect.d.ts +21 -0
- package/import/render3/reactivity/patch.d.ts +11 -0
- package/import/render3/reactivity/root_effect_scheduler.d.ts +54 -0
- package/import/render3/reactivity/signal.d.ts +61 -0
- package/import/render3/reactivity/untracked.d.ts +12 -0
- package/import/resource/api.d.ts +219 -0
- package/{es2022/di/injectable.js → import/resource/index.d.ts} +3 -2
- package/import/resource/resource.d.ts +89 -0
- package/import/util/callback_scheduler.d.ts +35 -0
- package/{typings → import}/util/closure.d.ts +1 -1
- package/{typings → import}/util/decorators.d.ts +3 -3
- package/{typings → import}/util/empty.d.ts +1 -1
- package/{es2022/di/provider_token.js → import/util/noop.d.ts} +2 -2
- package/{typings → import}/util/property.d.ts +1 -1
- package/{typings → import}/util/stringify.d.ts +1 -1
- package/index.js +2349 -0
- package/index.js.map +7 -0
- package/index.mjs +2258 -0
- package/index.mjs.map +7 -0
- package/package.json +22 -11
- package/primitives/signals/index.d.ts +15 -0
- package/primitives/signals/src/computed.d.ts +55 -0
- package/primitives/signals/src/equality.d.ts +15 -0
- package/primitives/signals/src/errors.d.ts +10 -0
- package/primitives/signals/src/graph.d.ts +182 -0
- package/primitives/signals/src/linked_signal.d.ts +72 -0
- package/primitives/signals/src/signal.d.ts +29 -0
- package/primitives/signals/src/watch.d.ts +43 -0
- package/{es2022/di/injector_marker.js → primitives/signals/src/weak_ref.d.ts} +2 -2
- package/readme.md +19 -15
- package/commonjs/index.js +0 -1586
- package/es2022/di/create_injector.js +0 -32
- package/es2022/di/forward_ref.js +0 -80
- package/es2022/di/index.js +0 -1
- package/es2022/di/initializer_token.js +0 -15
- package/es2022/di/inject_switch.js +0 -51
- package/es2022/di/injection_token.js +0 -93
- package/es2022/di/injector.js +0 -60
- package/es2022/di/injector_compatibility.js +0 -265
- package/es2022/di/injector_token.js +0 -20
- package/es2022/di/interface/defs.js +0 -110
- package/es2022/di/interface/injector.js +0 -26
- package/es2022/di/interface/provider.js +0 -10
- package/es2022/di/internal_tokens.js +0 -9
- package/es2022/di/metadata.js +0 -48
- package/es2022/di/null_injector.js +0 -19
- package/es2022/di/provider_collection.js +0 -104
- package/es2022/di/r3_injector.js +0 -449
- package/es2022/di/scope.js +0 -14
- package/es2022/di.js +0 -24
- package/es2022/errors.js +0 -44
- package/es2022/index.js +0 -19
- package/es2022/interface/lifecycle_hooks.js +0 -8
- package/es2022/interface/type.js +0 -21
- package/es2022/render3/definition_factory.js +0 -10
- package/es2022/render3/errors_di.js +0 -13
- package/es2022/render3/fields.js +0 -22
- package/es2022/render3/instructions/di.js +0 -23
- package/es2022/render3/util/stringify_utils.js +0 -38
- package/es2022/util/closure.js +0 -19
- package/es2022/util/decorators.js +0 -31
- package/es2022/util/empty.js +0 -18
- package/es2022/util/property.js +0 -15
- package/es2022/util/stringify.js +0 -45
- package/fesm2022/index.js +0 -1547
- package/typings/di/index.d.ts +0 -1
- package/typings/index.d.ts +0 -18
- package/typings/render3/util/stringify_utils.d.ts +0 -21
package/es2022/di/r3_injector.js
DELETED
|
@@ -1,449 +0,0 @@
|
|
|
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 { RuntimeError } from '../errors';
|
|
9
|
-
import { getFactoryDef } from '../render3/definition_factory';
|
|
10
|
-
import { NG_ENV_ID } from '../render3/fields';
|
|
11
|
-
import { EMPTY_ARRAY } from '../util/empty';
|
|
12
|
-
import { stringify } from '../util/stringify';
|
|
13
|
-
import { resolveForwardRef } from './forward_ref';
|
|
14
|
-
import { ENVIRONMENT_INITIALIZER } from './initializer_token';
|
|
15
|
-
import { setInjectImplementation } from './inject_switch';
|
|
16
|
-
import { InjectionToken } from './injection_token';
|
|
17
|
-
import { catchInjectorError, convertToBitFlags, injectArgs, NG_TEMP_TOKEN_PATH, setCurrentInjector, THROW_IF_NOT_FOUND, ɵɵinject, } from './injector_compatibility';
|
|
18
|
-
import { INJECTOR } from './injector_token';
|
|
19
|
-
import { getInheritedInjectableDef, getInjectableDef, } from './interface/defs';
|
|
20
|
-
import { InjectFlags } from './interface/injector';
|
|
21
|
-
import { isEnvironmentProviders, } from './interface/provider';
|
|
22
|
-
import { INJECTOR_DEF_TYPES } from './internal_tokens';
|
|
23
|
-
import { NullInjector } from './null_injector';
|
|
24
|
-
import { isExistingProvider, isFactoryProvider, isTypeProvider, isValueProvider, } from './provider_collection';
|
|
25
|
-
import { INJECTOR_SCOPE } from './scope';
|
|
26
|
-
/**
|
|
27
|
-
* Marker which indicates that a value has not yet been created from the factory function.
|
|
28
|
-
*/
|
|
29
|
-
const NOT_YET = {};
|
|
30
|
-
/**
|
|
31
|
-
* Marker which indicates that the factory function for a token is in the process of being called.
|
|
32
|
-
*
|
|
33
|
-
* If the injector is asked to inject a token with its value set to CIRCULAR, that indicates
|
|
34
|
-
* injection of a dependency has recursively attempted to inject the original token, and there is
|
|
35
|
-
* a circular dependency among the providers.
|
|
36
|
-
*/
|
|
37
|
-
const CIRCULAR = {};
|
|
38
|
-
/**
|
|
39
|
-
* A lazily initialized NullInjector.
|
|
40
|
-
*/
|
|
41
|
-
let NULL_INJECTOR = undefined;
|
|
42
|
-
export function getNullInjector() {
|
|
43
|
-
if (NULL_INJECTOR === undefined) {
|
|
44
|
-
NULL_INJECTOR = new NullInjector();
|
|
45
|
-
}
|
|
46
|
-
return NULL_INJECTOR;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* An `Injector` that's part of the environment injector hierarchy, which exists outside of the
|
|
50
|
-
* component tree.
|
|
51
|
-
*/
|
|
52
|
-
export class EnvironmentInjector {
|
|
53
|
-
}
|
|
54
|
-
export class R3Injector extends EnvironmentInjector {
|
|
55
|
-
parent;
|
|
56
|
-
source;
|
|
57
|
-
scopes;
|
|
58
|
-
/**
|
|
59
|
-
* Map of tokens to records which contain the instances of those tokens.
|
|
60
|
-
* - `null` value implies that we don't have the record. Used by tree-shakable injectors
|
|
61
|
-
* to prevent further searches.
|
|
62
|
-
*/
|
|
63
|
-
records = new Map();
|
|
64
|
-
/**
|
|
65
|
-
* Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
|
|
66
|
-
*/
|
|
67
|
-
_ngOnDestroyHooks = new Set();
|
|
68
|
-
_onDestroyHooks = [];
|
|
69
|
-
/**
|
|
70
|
-
* Flag indicating that this injector was previously destroyed.
|
|
71
|
-
*/
|
|
72
|
-
get destroyed() {
|
|
73
|
-
return this._destroyed;
|
|
74
|
-
}
|
|
75
|
-
_destroyed = false;
|
|
76
|
-
injectorDefTypes;
|
|
77
|
-
constructor(providers, parent, source, scopes) {
|
|
78
|
-
super();
|
|
79
|
-
this.parent = parent;
|
|
80
|
-
this.source = source;
|
|
81
|
-
this.scopes = scopes;
|
|
82
|
-
// Start off by creating Records for every provider.
|
|
83
|
-
forEachSingleProvider(providers, (provider) => this.processProvider(provider));
|
|
84
|
-
// Make sure the INJECTOR token provides this injector.
|
|
85
|
-
this.records.set(INJECTOR, makeRecord(undefined, this));
|
|
86
|
-
// And `EnvironmentInjector` if the current injector is supposed to be env-scoped.
|
|
87
|
-
if (scopes.has('environment')) {
|
|
88
|
-
this.records.set(EnvironmentInjector, makeRecord(undefined, this));
|
|
89
|
-
}
|
|
90
|
-
// Detect whether this injector has the APP_ROOT_SCOPE token and thus should provide
|
|
91
|
-
// any injectable scoped to APP_ROOT_SCOPE.
|
|
92
|
-
const record = this.records.get(INJECTOR_SCOPE);
|
|
93
|
-
if (record != null && typeof record.value === 'string') {
|
|
94
|
-
this.scopes.add(record.value);
|
|
95
|
-
}
|
|
96
|
-
this.injectorDefTypes = new Set(this.get(INJECTOR_DEF_TYPES, EMPTY_ARRAY, InjectFlags.Self));
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Destroy the injector and release references to every instance or provider associated with it.
|
|
100
|
-
*
|
|
101
|
-
* Also calls the `OnDestroy` lifecycle hooks of every instance that was created for which a
|
|
102
|
-
* hook was found.
|
|
103
|
-
*/
|
|
104
|
-
destroy() {
|
|
105
|
-
this.assertNotDestroyed();
|
|
106
|
-
// Set destroyed = true first, in case lifecycle hooks re-enter destroy().
|
|
107
|
-
this._destroyed = true;
|
|
108
|
-
try {
|
|
109
|
-
// Call all the lifecycle hooks.
|
|
110
|
-
for (const service of this._ngOnDestroyHooks) {
|
|
111
|
-
service.ngOnDestroy();
|
|
112
|
-
}
|
|
113
|
-
const onDestroyHooks = this._onDestroyHooks;
|
|
114
|
-
// Reset the _onDestroyHooks array before iterating over it to prevent hooks that unregister
|
|
115
|
-
// themselves from mutating the array during iteration.
|
|
116
|
-
this._onDestroyHooks = [];
|
|
117
|
-
for (const hook of onDestroyHooks) {
|
|
118
|
-
hook();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
// Release all references.
|
|
123
|
-
this.records.clear();
|
|
124
|
-
this._ngOnDestroyHooks.clear();
|
|
125
|
-
this.injectorDefTypes.clear();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
onDestroy(callback) {
|
|
129
|
-
this.assertNotDestroyed();
|
|
130
|
-
this._onDestroyHooks.push(callback);
|
|
131
|
-
return () => this.removeOnDestroy(callback);
|
|
132
|
-
}
|
|
133
|
-
runInContext(fn) {
|
|
134
|
-
this.assertNotDestroyed();
|
|
135
|
-
const previousInjector = setCurrentInjector(this);
|
|
136
|
-
const previousInjectImplementation = setInjectImplementation(undefined);
|
|
137
|
-
if (false) {
|
|
138
|
-
}
|
|
139
|
-
try {
|
|
140
|
-
return fn();
|
|
141
|
-
}
|
|
142
|
-
finally {
|
|
143
|
-
setCurrentInjector(previousInjector);
|
|
144
|
-
setInjectImplementation(previousInjectImplementation);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
get(token, notFoundValue = THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
|
|
148
|
-
this.assertNotDestroyed();
|
|
149
|
-
if (token.hasOwnProperty(NG_ENV_ID)) {
|
|
150
|
-
return token[NG_ENV_ID](this);
|
|
151
|
-
}
|
|
152
|
-
flags = convertToBitFlags(flags);
|
|
153
|
-
// Set the injection context.
|
|
154
|
-
if (false) {
|
|
155
|
-
}
|
|
156
|
-
const previousInjector = setCurrentInjector(this);
|
|
157
|
-
const previousInjectImplementation = setInjectImplementation(undefined);
|
|
158
|
-
try {
|
|
159
|
-
// Check for the SkipSelf flag.
|
|
160
|
-
if (!(flags & InjectFlags.SkipSelf)) {
|
|
161
|
-
// SkipSelf isn't set, check if the record belongs to this injector.
|
|
162
|
-
let record = this.records.get(token);
|
|
163
|
-
if (record === undefined) {
|
|
164
|
-
// No record, but maybe the token is scoped to this injector. Look for an injectable
|
|
165
|
-
// def with a scope matching this injector.
|
|
166
|
-
const def = couldBeInjectableType(token) && getInjectableDef(token);
|
|
167
|
-
if (def && this.injectableDefInScope(def)) {
|
|
168
|
-
// Found an injectable def and it's scoped to this injector. Pretend as if it was here
|
|
169
|
-
// all along.
|
|
170
|
-
if (false) {
|
|
171
|
-
}
|
|
172
|
-
record = makeRecord(injectableDefOrInjectorDefFactory(token), NOT_YET);
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
record = null;
|
|
176
|
-
}
|
|
177
|
-
this.records.set(token, record);
|
|
178
|
-
}
|
|
179
|
-
// If a record was found, get the instance for it and return it.
|
|
180
|
-
if (record != null /* NOT null || undefined */) {
|
|
181
|
-
return this.hydrate(token, record);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// Select the next injector based on the Self flag - if self is set, the next injector is
|
|
185
|
-
// the NullInjector, otherwise it's the parent.
|
|
186
|
-
const nextInjector = !(flags & InjectFlags.Self)
|
|
187
|
-
? this.parent
|
|
188
|
-
: getNullInjector();
|
|
189
|
-
// Set the notFoundValue based on the Optional flag - if optional is set and notFoundValue
|
|
190
|
-
// is undefined, the value is null, otherwise it's the notFoundValue.
|
|
191
|
-
notFoundValue =
|
|
192
|
-
flags & InjectFlags.Optional && notFoundValue === THROW_IF_NOT_FOUND
|
|
193
|
-
? null
|
|
194
|
-
: notFoundValue;
|
|
195
|
-
return nextInjector.get(token, notFoundValue);
|
|
196
|
-
}
|
|
197
|
-
catch (e) {
|
|
198
|
-
if (e.name === 'NullInjectorError') {
|
|
199
|
-
const path = (e[NG_TEMP_TOKEN_PATH] =
|
|
200
|
-
e[NG_TEMP_TOKEN_PATH] || []);
|
|
201
|
-
path.unshift(stringify(token));
|
|
202
|
-
if (previousInjector) {
|
|
203
|
-
// We still have a parent injector, keep throwing
|
|
204
|
-
throw e;
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
// Format & throw the final error message when we don't have any previous injector
|
|
208
|
-
return catchInjectorError(e, token, 'R3InjectorError', this.source);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
throw e;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
finally {
|
|
216
|
-
// Lastly, restore the previous injection context.
|
|
217
|
-
setInjectImplementation(previousInjectImplementation);
|
|
218
|
-
setCurrentInjector(previousInjector);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
/** @internal */
|
|
222
|
-
resolveInjectorInitializers() {
|
|
223
|
-
const previousInjector = setCurrentInjector(this);
|
|
224
|
-
const previousInjectImplementation = setInjectImplementation(undefined);
|
|
225
|
-
if (false) {
|
|
226
|
-
}
|
|
227
|
-
try {
|
|
228
|
-
const initializers = this.get(ENVIRONMENT_INITIALIZER, EMPTY_ARRAY, InjectFlags.Self);
|
|
229
|
-
if (false) {
|
|
230
|
-
}
|
|
231
|
-
for (const initializer of initializers) {
|
|
232
|
-
initializer();
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
finally {
|
|
236
|
-
setCurrentInjector(previousInjector);
|
|
237
|
-
setInjectImplementation(previousInjectImplementation);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
toString() {
|
|
241
|
-
const tokens = [];
|
|
242
|
-
const records = this.records;
|
|
243
|
-
for (const token of records.keys()) {
|
|
244
|
-
tokens.push(stringify(token));
|
|
245
|
-
}
|
|
246
|
-
return `R3Injector[${tokens.join(', ')}]`;
|
|
247
|
-
}
|
|
248
|
-
assertNotDestroyed() {
|
|
249
|
-
if (this._destroyed) {
|
|
250
|
-
throw new RuntimeError(205 /* RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED */, null);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Process a `SingleProvider` and add it.
|
|
255
|
-
*/
|
|
256
|
-
processProvider(provider) {
|
|
257
|
-
// Determine the token from the provider. Either it's its own token, or has a {provide: ...}
|
|
258
|
-
// property.
|
|
259
|
-
provider = resolveForwardRef(provider);
|
|
260
|
-
let token = isTypeProvider(provider)
|
|
261
|
-
? provider
|
|
262
|
-
: resolveForwardRef(provider && provider.provide);
|
|
263
|
-
// Construct a `Record` for the provider.
|
|
264
|
-
const record = providerToRecord(provider);
|
|
265
|
-
if (false) {
|
|
266
|
-
}
|
|
267
|
-
if (!isTypeProvider(provider) && provider.multi === true) {
|
|
268
|
-
// If the provider indicates that it's a multi-provider, process it specially.
|
|
269
|
-
// First check whether it's been defined already.
|
|
270
|
-
let multiRecord = this.records.get(token);
|
|
271
|
-
if (multiRecord) {
|
|
272
|
-
// It has. Throw a nice error if
|
|
273
|
-
if (false) {
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
multiRecord = makeRecord(undefined, NOT_YET, true);
|
|
278
|
-
multiRecord.factory = () => injectArgs(multiRecord.multi);
|
|
279
|
-
this.records.set(token, multiRecord);
|
|
280
|
-
}
|
|
281
|
-
token = provider;
|
|
282
|
-
multiRecord.multi.push(provider);
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
if (false) {
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
this.records.set(token, record);
|
|
289
|
-
}
|
|
290
|
-
hydrate(token, record) {
|
|
291
|
-
try {
|
|
292
|
-
if (false) {
|
|
293
|
-
}
|
|
294
|
-
else if (record.value === NOT_YET) {
|
|
295
|
-
record.value = CIRCULAR;
|
|
296
|
-
if (false) {
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
record.value = record.factory();
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
if (typeof record.value === 'object' &&
|
|
303
|
-
record.value &&
|
|
304
|
-
hasOnDestroy(record.value)) {
|
|
305
|
-
this._ngOnDestroyHooks.add(record.value);
|
|
306
|
-
}
|
|
307
|
-
return record.value;
|
|
308
|
-
}
|
|
309
|
-
finally {
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
injectableDefInScope(def) {
|
|
313
|
-
if (!def.providedIn) {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
const providedIn = resolveForwardRef(def.providedIn);
|
|
317
|
-
if (typeof providedIn === 'string') {
|
|
318
|
-
return providedIn === 'any' || this.scopes.has(providedIn);
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
return this.injectorDefTypes.has(providedIn);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
removeOnDestroy(callback) {
|
|
325
|
-
const destroyCBIdx = this._onDestroyHooks.indexOf(callback);
|
|
326
|
-
if (destroyCBIdx !== -1) {
|
|
327
|
-
this._onDestroyHooks.splice(destroyCBIdx, 1);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
function injectableDefOrInjectorDefFactory(token) {
|
|
332
|
-
// Most tokens will have an injectable def directly on them, which specifies a factory directly.
|
|
333
|
-
const injectableDef = getInjectableDef(token);
|
|
334
|
-
const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
|
|
335
|
-
if (factory !== null) {
|
|
336
|
-
return factory;
|
|
337
|
-
}
|
|
338
|
-
// InjectionTokens should have an injectable def (ɵprov) and thus should be handled above.
|
|
339
|
-
// If it's missing that, it's an error.
|
|
340
|
-
if (token instanceof InjectionToken) {
|
|
341
|
-
throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
|
|
342
|
-
}
|
|
343
|
-
// Undecorated types can sometimes be created if they have no constructor arguments.
|
|
344
|
-
if (token instanceof Function) {
|
|
345
|
-
return getUndecoratedInjectableFactory(token);
|
|
346
|
-
}
|
|
347
|
-
// There was no way to resolve a factory for this token.
|
|
348
|
-
throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
|
|
349
|
-
}
|
|
350
|
-
function getUndecoratedInjectableFactory(token) {
|
|
351
|
-
// If the token has parameters then it has dependencies that we cannot resolve implicitly.
|
|
352
|
-
const paramLength = token.length;
|
|
353
|
-
if (paramLength > 0) {
|
|
354
|
-
throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
|
|
355
|
-
}
|
|
356
|
-
// The constructor function appears to have no parameters.
|
|
357
|
-
// This might be because it inherits from a super-class. In which case, use an injectable
|
|
358
|
-
// def from an ancestor if there is one.
|
|
359
|
-
// Otherwise this really is a simple class with no dependencies, so return a factory that
|
|
360
|
-
// just instantiates the zero-arg constructor.
|
|
361
|
-
const inheritedInjectableDef = getInheritedInjectableDef(token);
|
|
362
|
-
if (inheritedInjectableDef !== null) {
|
|
363
|
-
return () => inheritedInjectableDef.factory(token);
|
|
364
|
-
}
|
|
365
|
-
else {
|
|
366
|
-
return () => new token();
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
function providerToRecord(provider) {
|
|
370
|
-
if (isValueProvider(provider)) {
|
|
371
|
-
return makeRecord(undefined, provider.useValue);
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
const factory = providerToFactory(provider);
|
|
375
|
-
return makeRecord(factory, NOT_YET);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Converts a `SingleProvider` into a factory function.
|
|
380
|
-
*
|
|
381
|
-
* @param provider provider to convert to factory
|
|
382
|
-
*/
|
|
383
|
-
export function providerToFactory(provider, ngModuleType, providers) {
|
|
384
|
-
let factory = undefined;
|
|
385
|
-
if (false) {
|
|
386
|
-
}
|
|
387
|
-
if (isTypeProvider(provider)) {
|
|
388
|
-
const unwrappedProvider = resolveForwardRef(provider);
|
|
389
|
-
return (getFactoryDef(unwrappedProvider) ||
|
|
390
|
-
injectableDefOrInjectorDefFactory(unwrappedProvider));
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
if (isValueProvider(provider)) {
|
|
394
|
-
factory = () => resolveForwardRef(provider.useValue);
|
|
395
|
-
}
|
|
396
|
-
else if (isFactoryProvider(provider)) {
|
|
397
|
-
factory = () => provider.useFactory(...injectArgs(provider.deps || []));
|
|
398
|
-
}
|
|
399
|
-
else if (isExistingProvider(provider)) {
|
|
400
|
-
factory = () => ɵɵinject(resolveForwardRef(provider.useExisting));
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
const classRef = resolveForwardRef(provider &&
|
|
404
|
-
(provider.useClass ||
|
|
405
|
-
provider.provide));
|
|
406
|
-
if (false) {
|
|
407
|
-
}
|
|
408
|
-
if (hasDeps(provider)) {
|
|
409
|
-
factory = () => new classRef(...injectArgs(provider.deps));
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
return (getFactoryDef(classRef) || injectableDefOrInjectorDefFactory(classRef));
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
return factory;
|
|
417
|
-
}
|
|
418
|
-
function makeRecord(factory, value, multi = false) {
|
|
419
|
-
return {
|
|
420
|
-
factory: factory,
|
|
421
|
-
value: value,
|
|
422
|
-
multi: multi ? [] : undefined,
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
function hasDeps(value) {
|
|
426
|
-
return !!value.deps;
|
|
427
|
-
}
|
|
428
|
-
function hasOnDestroy(value) {
|
|
429
|
-
return (value !== null &&
|
|
430
|
-
typeof value === 'object' &&
|
|
431
|
-
typeof value.ngOnDestroy === 'function');
|
|
432
|
-
}
|
|
433
|
-
function couldBeInjectableType(value) {
|
|
434
|
-
return (typeof value === 'function' ||
|
|
435
|
-
(typeof value === 'object' && value instanceof InjectionToken));
|
|
436
|
-
}
|
|
437
|
-
function forEachSingleProvider(providers, fn) {
|
|
438
|
-
for (const provider of providers) {
|
|
439
|
-
if (Array.isArray(provider)) {
|
|
440
|
-
forEachSingleProvider(provider, fn);
|
|
441
|
-
}
|
|
442
|
-
else if (provider && isEnvironmentProviders(provider)) {
|
|
443
|
-
forEachSingleProvider(provider.ɵproviders, fn);
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
fn(provider);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
package/es2022/di/scope.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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 { InjectionToken } from './injection_token';
|
|
9
|
-
/**
|
|
10
|
-
* An internal token whose presence in an injector indicates that the injector should treat itself
|
|
11
|
-
* as a root scoped injector when processing requests for unknown tokens which may indicate
|
|
12
|
-
* they are provided in the root scope.
|
|
13
|
-
*/
|
|
14
|
-
export const INJECTOR_SCOPE = new InjectionToken('');
|
package/es2022/di.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
/**
|
|
9
|
-
* This file should not be necessary because node resolution should just default to `./di/index`!
|
|
10
|
-
*
|
|
11
|
-
* However it does not seem to work and it breaks:
|
|
12
|
-
* - //packages/animations/browser/test:test_web_chromium-local
|
|
13
|
-
* - //packages/compiler-cli/test:extract_i18n
|
|
14
|
-
* - //packages/compiler-cli/test:ngc
|
|
15
|
-
* - //packages/compiler-cli/test:perform_watch
|
|
16
|
-
* - //packages/compiler-cli/test/diagnostics:check_types
|
|
17
|
-
* - //packages/compiler-cli/test/transformers:test
|
|
18
|
-
* - //packages/compiler/test:test
|
|
19
|
-
* - //tools/public_api_guard:core_api
|
|
20
|
-
*
|
|
21
|
-
* Remove this file once the above is solved or wait until `ngc` is deleted and then it should be
|
|
22
|
-
* safe to delete this file.
|
|
23
|
-
*/
|
|
24
|
-
export * from './di/index';
|
package/es2022/errors.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
/**
|
|
9
|
-
* Class that represents a runtime error.
|
|
10
|
-
* Formats and outputs the error message in a consistent way.
|
|
11
|
-
*
|
|
12
|
-
* Example:
|
|
13
|
-
* ```
|
|
14
|
-
* throw new RuntimeError(
|
|
15
|
-
* RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
|
|
16
|
-
* ngDevMode && 'Injector has already been destroyed.');
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* Note: the `message` argument contains a descriptive error message as a string in development
|
|
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
|
|
22
|
-
* logic.
|
|
23
|
-
*/
|
|
24
|
-
export class RuntimeError extends Error {
|
|
25
|
-
code;
|
|
26
|
-
constructor(code, message) {
|
|
27
|
-
super(formatRuntimeError(code, message));
|
|
28
|
-
this.code = code;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Called to format a runtime error.
|
|
33
|
-
* See additional info on the `message` argument type in the `RuntimeError` class description.
|
|
34
|
-
*/
|
|
35
|
-
export function formatRuntimeError(code, message) {
|
|
36
|
-
// Error code might be a negative number, which is a special marker that instructs the logic to
|
|
37
|
-
// generate a link to the error details page on angular.io.
|
|
38
|
-
// We also prepend `0` to non-compile-time errors.
|
|
39
|
-
const fullCode = `NG0${Math.abs(code)}`;
|
|
40
|
-
let errorMessage = `${fullCode}${message ? ': ' + message : ''}`;
|
|
41
|
-
if (false) {
|
|
42
|
-
}
|
|
43
|
-
return errorMessage;
|
|
44
|
-
}
|
package/es2022/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from './di/injectable';
|
|
2
|
-
export * from './di/metadata';
|
|
3
|
-
export * from './di/r3_injector';
|
|
4
|
-
export * from './di/interface/defs';
|
|
5
|
-
export * from './di/injector_compatibility';
|
|
6
|
-
export * from './di/injection_token';
|
|
7
|
-
export * from './di/null_injector';
|
|
8
|
-
export * from './di/injector';
|
|
9
|
-
export * from './di/interface/injector';
|
|
10
|
-
export * from './di/scope';
|
|
11
|
-
export * from './render3/instructions/di';
|
|
12
|
-
export class StaticInjectOptions {
|
|
13
|
-
static injectOptions;
|
|
14
|
-
}
|
|
15
|
-
export class RootStaticInjectOptions {
|
|
16
|
-
static injectOptions = {
|
|
17
|
-
providedIn: 'root',
|
|
18
|
-
};
|
|
19
|
-
}
|
package/es2022/interface/type.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
/**
|
|
9
|
-
* @description
|
|
10
|
-
*
|
|
11
|
-
* Represents a type that a Component or other object is instances of.
|
|
12
|
-
*
|
|
13
|
-
* An example of a `Type` is `MyCustomComponent` class, which in JavaScript is represented by
|
|
14
|
-
* the `MyCustomComponent` constructor function.
|
|
15
|
-
*
|
|
16
|
-
* @publicApi
|
|
17
|
-
*/
|
|
18
|
-
export const Type = Function;
|
|
19
|
-
export function isType(v) {
|
|
20
|
-
return typeof v === 'function';
|
|
21
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
export function getFactoryDef(type, throwNotFound) {
|
|
9
|
-
return () => new type();
|
|
10
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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 { RuntimeError } from '../errors';
|
|
9
|
-
/** Throws an error when a token is not found in DI. */
|
|
10
|
-
export function throwProviderNotFoundError(token, injectorName) {
|
|
11
|
-
const errorMessage = null;
|
|
12
|
-
throw new RuntimeError(-201 /* RuntimeErrorCode.PROVIDER_NOT_FOUND */, errorMessage);
|
|
13
|
-
}
|
package/es2022/render3/fields.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
/**
|
|
9
|
-
* Throws an error indicating that a factory function could not be generated by the compiler for a
|
|
10
|
-
* particular class.
|
|
11
|
-
*
|
|
12
|
-
* This instruction allows the actual error message to be optimized away when ngDevMode is turned
|
|
13
|
-
* off, saving bytes of generated code while still providing a good experience in dev mode.
|
|
14
|
-
*
|
|
15
|
-
* The name of the class is not mentioned here, but will be in the generated factory function name
|
|
16
|
-
* and thus in the stack trace.
|
|
17
|
-
*
|
|
18
|
-
* @codeGenApi
|
|
19
|
-
*/
|
|
20
|
-
export function ɵɵinvalidFactory() {
|
|
21
|
-
const msg = 'invalid';
|
|
22
|
-
throw new Error(msg);
|
|
23
|
-
}
|