static-injector 5.0.1 → 6.0.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.
Files changed (110) hide show
  1. package/import/change_detection/scheduling/zoneless_scheduling.d.ts +37 -0
  2. package/import/change_detection/scheduling/zoneless_scheduling_impl.d.ts +16 -0
  3. package/import/core_reactivity_export_internal.d.ts +17 -0
  4. package/import/di/contextual.d.ts +36 -0
  5. package/{typings → import}/di/create_injector.d.ts +1 -1
  6. package/{typings → import}/di/forward_ref.d.ts +2 -2
  7. package/import/di/index.d.ts +3 -0
  8. package/{typings → import}/di/initializer_token.d.ts +8 -1
  9. package/{typings → import}/di/inject_switch.d.ts +2 -2
  10. package/{typings → import}/di/injectable.d.ts +4 -4
  11. package/{typings → import}/di/injection_token.d.ts +3 -4
  12. package/{typings → import}/di/injector.d.ts +4 -4
  13. package/{typings → import}/di/injector_compatibility.d.ts +1 -1
  14. package/{typings → import}/di/injector_marker.d.ts +1 -1
  15. package/{typings → import}/di/injector_token.d.ts +1 -1
  16. package/{typings → import}/di/interface/defs.d.ts +1 -1
  17. package/{typings → import}/di/interface/injector.d.ts +1 -1
  18. package/{typings → import}/di/interface/provider.d.ts +16 -18
  19. package/{typings → import}/di/internal_tokens.d.ts +1 -1
  20. package/{typings → import}/di/metadata.d.ts +9 -13
  21. package/{typings → import}/di/null_injector.d.ts +1 -1
  22. package/{typings → import}/di/provider_collection.d.ts +32 -4
  23. package/{typings → import}/di/provider_token.d.ts +1 -1
  24. package/{typings → import}/di/r3_injector.d.ts +2 -2
  25. package/{typings → import}/di/scope.d.ts +1 -1
  26. package/{typings → import}/di.d.ts +1 -1
  27. package/import/error_handler.d.ts +45 -0
  28. package/{typings → import}/errors.d.ts +13 -7
  29. package/import/index.d.ts +37 -0
  30. package/{typings → import}/interface/lifecycle_hooks.d.ts +2 -2
  31. package/{typings → import}/interface/type.d.ts +4 -9
  32. package/import/linker/destroy_ref.d.ts +44 -0
  33. package/import/pending_tasks.d.ts +78 -0
  34. package/{typings → import}/render3/definition_factory.d.ts +1 -1
  35. package/{typings → import}/render3/errors_di.d.ts +1 -1
  36. package/{typings → import}/render3/fields.d.ts +1 -1
  37. package/{typings → import}/render3/instructions/di.d.ts +1 -1
  38. package/import/render3/reactivity/api.d.ts +27 -0
  39. package/import/render3/reactivity/asserts.d.ts +16 -0
  40. package/import/render3/reactivity/computed.d.ts +25 -0
  41. package/import/render3/reactivity/effect.d.ts +121 -0
  42. package/import/render3/reactivity/linked_signal.d.ts +33 -0
  43. package/import/render3/reactivity/microtask_effect.d.ts +21 -0
  44. package/import/render3/reactivity/patch.d.ts +11 -0
  45. package/import/render3/reactivity/root_effect_scheduler.d.ts +54 -0
  46. package/import/render3/reactivity/signal.d.ts +61 -0
  47. package/import/render3/reactivity/untracked.d.ts +12 -0
  48. package/import/resource/api.d.ts +219 -0
  49. package/{es2022/di/injectable.js → import/resource/index.d.ts} +3 -2
  50. package/import/resource/resource.d.ts +89 -0
  51. package/import/util/callback_scheduler.d.ts +35 -0
  52. package/{typings → import}/util/closure.d.ts +1 -1
  53. package/{typings → import}/util/decorators.d.ts +3 -3
  54. package/{typings → import}/util/empty.d.ts +1 -1
  55. package/{es2022/di/provider_token.js → import/util/noop.d.ts} +2 -2
  56. package/{typings → import}/util/property.d.ts +1 -1
  57. package/{typings → import}/util/stringify.d.ts +1 -1
  58. package/index.js +2349 -0
  59. package/index.js.map +7 -0
  60. package/index.mjs +2258 -0
  61. package/index.mjs.map +7 -0
  62. package/package.json +19 -10
  63. package/primitives/signals/index.d.ts +15 -0
  64. package/primitives/signals/src/computed.d.ts +55 -0
  65. package/primitives/signals/src/equality.d.ts +15 -0
  66. package/primitives/signals/src/errors.d.ts +10 -0
  67. package/primitives/signals/src/graph.d.ts +182 -0
  68. package/primitives/signals/src/linked_signal.d.ts +72 -0
  69. package/primitives/signals/src/signal.d.ts +29 -0
  70. package/primitives/signals/src/watch.d.ts +43 -0
  71. package/{es2022/di/injector_marker.js → primitives/signals/src/weak_ref.d.ts} +2 -2
  72. package/readme.md +18 -14
  73. package/commonjs/index.js +0 -1576
  74. package/es2022/di/create_injector.js +0 -32
  75. package/es2022/di/forward_ref.js +0 -80
  76. package/es2022/di/index.js +0 -1
  77. package/es2022/di/initializer_token.js +0 -15
  78. package/es2022/di/inject_switch.js +0 -51
  79. package/es2022/di/injection_token.js +0 -93
  80. package/es2022/di/injector.js +0 -60
  81. package/es2022/di/injector_compatibility.js +0 -265
  82. package/es2022/di/injector_token.js +0 -20
  83. package/es2022/di/interface/defs.js +0 -110
  84. package/es2022/di/interface/injector.js +0 -26
  85. package/es2022/di/interface/provider.js +0 -10
  86. package/es2022/di/internal_tokens.js +0 -9
  87. package/es2022/di/metadata.js +0 -49
  88. package/es2022/di/null_injector.js +0 -19
  89. package/es2022/di/provider_collection.js +0 -104
  90. package/es2022/di/r3_injector.js +0 -449
  91. package/es2022/di/scope.js +0 -14
  92. package/es2022/di.js +0 -24
  93. package/es2022/errors.js +0 -44
  94. package/es2022/index.js +0 -11
  95. package/es2022/interface/lifecycle_hooks.js +0 -8
  96. package/es2022/interface/type.js +0 -21
  97. package/es2022/render3/definition_factory.js +0 -10
  98. package/es2022/render3/errors_di.js +0 -13
  99. package/es2022/render3/fields.js +0 -22
  100. package/es2022/render3/instructions/di.js +0 -23
  101. package/es2022/render3/util/stringify_utils.js +0 -38
  102. package/es2022/util/closure.js +0 -19
  103. package/es2022/util/decorators.js +0 -31
  104. package/es2022/util/empty.js +0 -18
  105. package/es2022/util/property.js +0 -15
  106. package/es2022/util/stringify.js +0 -45
  107. package/fesm2022/index.js +0 -1539
  108. package/typings/di/index.d.ts +0 -1
  109. package/typings/index.d.ts +0 -11
  110. package/typings/render3/util/stringify_utils.d.ts +0 -21
package/commonjs/index.js DELETED
@@ -1,1576 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * @license
5
- * Copyright Google LLC All Rights Reserved.
6
- *
7
- * Use of this source code is governed by an MIT-style license that can be
8
- * found in the LICENSE file at https://angular.io/license
9
- */
10
- /**
11
- * Convince closure compiler that the wrapped function has no side-effects.
12
- *
13
- * Closure compiler always assumes that `toString` has no side-effects. We use this quirk to
14
- * allow us to execute a function but have closure compiler mark the call as no-side-effects.
15
- * It is important that the return value for the `noSideEffects` function be assigned
16
- * to something which is retained otherwise the call to `noSideEffects` will be removed by closure
17
- * compiler.
18
- */
19
- function noSideEffects(fn) {
20
- return { toString: fn }.toString();
21
- }
22
-
23
- /**
24
- * @license
25
- * Copyright Google LLC All Rights Reserved.
26
- *
27
- * Use of this source code is governed by an MIT-style license that can be
28
- * found in the LICENSE file at https://angular.io/license
29
- */
30
- function makeMetadataCtor(props) {
31
- return function ctor(...args) {
32
- if (props) {
33
- const values = props(...args);
34
- for (const propName in values) {
35
- this[propName] = values[propName];
36
- }
37
- }
38
- };
39
- }
40
- function makeParamDecorator(name, props, parentClass) {
41
- return noSideEffects(() => {
42
- const metaCtor = makeMetadataCtor(props);
43
- function ParamDecoratorFactory(...args) {
44
- metaCtor.apply(this, args);
45
- return this;
46
- }
47
- return ParamDecoratorFactory;
48
- });
49
- }
50
-
51
- /**
52
- * @license
53
- * Copyright Google LLC All Rights Reserved.
54
- *
55
- * Use of this source code is governed by an MIT-style license that can be
56
- * found in the LICENSE file at https://angular.io/license
57
- */
58
- /**
59
- * Class that represents a runtime error.
60
- * Formats and outputs the error message in a consistent way.
61
- *
62
- * Example:
63
- * ```
64
- * throw new RuntimeError(
65
- * RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
66
- * ngDevMode && 'Injector has already been destroyed.');
67
- * ```
68
- *
69
- * Note: the `message` argument contains a descriptive error message as a string in development
70
- * mode (when the `ngDevMode` is defined). In production mode (after tree-shaking pass), the
71
- * `message` argument becomes `false`, thus we account for it in the typings and the runtime
72
- * logic.
73
- */
74
- class RuntimeError extends Error {
75
- code;
76
- constructor(code, message) {
77
- super(formatRuntimeError(code, message));
78
- this.code = code;
79
- }
80
- }
81
- /**
82
- * Called to format a runtime error.
83
- * See additional info on the `message` argument type in the `RuntimeError` class description.
84
- */
85
- function formatRuntimeError(code, message) {
86
- // Error code might be a negative number, which is a special marker that instructs the logic to
87
- // generate a link to the error details page on angular.io.
88
- // We also prepend `0` to non-compile-time errors.
89
- const fullCode = `NG0${Math.abs(code)}`;
90
- let errorMessage = `${fullCode}${message ? ': ' + message : ''}`;
91
- return errorMessage;
92
- }
93
-
94
- /**
95
- * @license
96
- * Copyright Google LLC All Rights Reserved.
97
- *
98
- * Use of this source code is governed by an MIT-style license that can be
99
- * found in the LICENSE file at https://angular.io/license
100
- */
101
- function stringify(token) {
102
- if (typeof token === 'string') {
103
- return token;
104
- }
105
- if (Array.isArray(token)) {
106
- return '[' + token.map(stringify).join(', ') + ']';
107
- }
108
- if (token == null) {
109
- return '' + token;
110
- }
111
- if (token.overriddenName) {
112
- return `${token.overriddenName}`;
113
- }
114
- if (token.name) {
115
- return `${token.name}`;
116
- }
117
- const res = token.toString();
118
- if (res == null) {
119
- return '' + res;
120
- }
121
- const newLineIndex = res.indexOf('\n');
122
- return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
123
- }
124
-
125
- /**
126
- * @license
127
- * Copyright Google LLC All Rights Reserved.
128
- *
129
- * Use of this source code is governed by an MIT-style license that can be
130
- * found in the LICENSE file at https://angular.io/license
131
- */
132
- function getClosureSafeProperty(objWithPropertyToExtract) {
133
- for (let key in objWithPropertyToExtract) {
134
- if (objWithPropertyToExtract[key] === getClosureSafeProperty) {
135
- return key;
136
- }
137
- }
138
- throw Error('Could not find renamed property on target object.');
139
- }
140
-
141
- /**
142
- * @license
143
- * Copyright Google LLC All Rights Reserved.
144
- *
145
- * Use of this source code is governed by an MIT-style license that can be
146
- * found in the LICENSE file at https://angular.io/license
147
- */
148
- const __forward_ref__ = getClosureSafeProperty({
149
- __forward_ref__: getClosureSafeProperty,
150
- });
151
- /**
152
- * Allows to refer to references which are not yet defined.
153
- *
154
- * For instance, `forwardRef` is used when the `token` which we need to refer to for the purposes of
155
- * DI is declared, but not yet defined. It is also used when the `token` which we use when creating
156
- * a query is not yet defined.
157
- *
158
- * `forwardRef` is also used to break circularities in standalone components imports.
159
- *
160
- * @usageNotes
161
- * ### Circular dependency example
162
- * {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref'}
163
- *
164
- * ### Circular standalone reference import example
165
- * ```ts
166
- * @Component({
167
- * standalone: true,
168
- * imports: [ChildComponent],
169
- * selector: 'app-parent',
170
- * template: `<app-child [hideParent]="hideParent"></app-child>`,
171
- * })
172
- * export class ParentComponent {
173
- * @Input() hideParent: boolean;
174
- * }
175
- *
176
- *
177
- * @Component({
178
- * standalone: true,
179
- * imports: [CommonModule, forwardRef(() => ParentComponent)],
180
- * selector: 'app-child',
181
- * template: `<app-parent *ngIf="!hideParent"></app-parent>`,
182
- * })
183
- * export class ChildComponent {
184
- * @Input() hideParent: boolean;
185
- * }
186
- * ```
187
- *
188
- * @publicApi
189
- */
190
- function forwardRef(forwardRefFn) {
191
- forwardRefFn.__forward_ref__ = forwardRef;
192
- forwardRefFn.toString = function () {
193
- return stringify(this());
194
- };
195
- return forwardRefFn;
196
- }
197
- /**
198
- * Lazily retrieves the reference value from a forwardRef.
199
- *
200
- * Acts as the identity function when given a non-forward-ref value.
201
- *
202
- * @usageNotes
203
- * ### Example
204
- *
205
- * {@example core/di/ts/forward_ref/forward_ref_spec.ts region='resolve_forward_ref'}
206
- *
207
- * @see {@link forwardRef}
208
- * @publicApi
209
- */
210
- function resolveForwardRef(type) {
211
- return isForwardRef(type) ? type() : type;
212
- }
213
- /** Checks whether a function is wrapped by a `forwardRef`. */
214
- function isForwardRef(fn) {
215
- return (typeof fn === 'function' &&
216
- fn.hasOwnProperty(__forward_ref__) &&
217
- fn.__forward_ref__ === forwardRef);
218
- }
219
-
220
- /**
221
- * @license
222
- * Copyright Google LLC All Rights Reserved.
223
- *
224
- * Use of this source code is governed by an MIT-style license that can be
225
- * found in the LICENSE file at https://angular.io/license
226
- */
227
- /** Throws an error when a token is not found in DI. */
228
- function throwProviderNotFoundError(token, injectorName) {
229
- const errorMessage = null;
230
- throw new RuntimeError(-201 /* RuntimeErrorCode.PROVIDER_NOT_FOUND */, errorMessage);
231
- }
232
-
233
- /**
234
- * @license
235
- * Copyright Google LLC All Rights Reserved.
236
- *
237
- * Use of this source code is governed by an MIT-style license that can be
238
- * found in the LICENSE file at https://angular.io/license
239
- */
240
- /**
241
- * Construct an injectable definition which defines how a token will be constructed by the DI
242
- * system, and in which injectors (if any) it will be available.
243
- *
244
- * This should be assigned to a static `ɵprov` field on a type, which will then be an
245
- * `InjectableType`.
246
- *
247
- * Options:
248
- * * `providedIn` determines which injectors will include the injectable, by either associating it
249
- * with an `@NgModule` or other `InjectorType`, or by specifying that this injectable should be
250
- * provided in the `'root'` injector, which will be the application-level injector in most apps.
251
- * * `factory` gives the zero argument function which will create an instance of the injectable.
252
- * The factory can call [`inject`](api/core/inject) to access the `Injector` and request injection
253
- * of dependencies.
254
- *
255
- * @codeGenApi
256
- * @publicApi This instruction has been emitted by ViewEngine for some time and is deployed to npm.
257
- */
258
- function ɵɵdefineInjectable(opts) {
259
- return {
260
- token: opts.token,
261
- providedIn: opts.providedIn || null,
262
- factory: opts.factory,
263
- value: undefined,
264
- };
265
- }
266
- /**
267
- * Construct an `InjectorDef` which configures an injector.
268
- *
269
- * This should be assigned to a static injector def (`ɵinj`) field on a type, which will then be an
270
- * `InjectorType`.
271
- *
272
- * Options:
273
- *
274
- * * `providers`: an optional array of providers to add to the injector. Each provider must
275
- * either have a factory or point to a type which has a `ɵprov` static property (the
276
- * type must be an `InjectableType`).
277
- * * `imports`: an optional array of imports of other `InjectorType`s or `InjectorTypeWithModule`s
278
- * whose providers will also be added to the injector. Locally provided types will override
279
- * providers from imports.
280
- *
281
- * @codeGenApi
282
- */
283
- function ɵɵdefineInjector(options) {
284
- return { providers: options.providers || [], imports: options.imports || [] };
285
- }
286
- /**
287
- * Read the injectable def (`ɵprov`) for `type` in a way which is immune to accidentally reading
288
- * inherited value.
289
- *
290
- * @param type A type which may have its own (non-inherited) `ɵprov`.
291
- */
292
- function getInjectableDef(type) {
293
- return (getOwnDefinition(type, NG_PROV_DEF) || {
294
- token: type,
295
- factory: () => new type(),
296
- ...type.injectOptions,
297
- });
298
- }
299
- function isInjectable(type) {
300
- return getInjectableDef(type) !== null;
301
- }
302
- /**
303
- * Return definition only if it is defined directly on `type` and is not inherited from a base
304
- * class of `type`.
305
- */
306
- function getOwnDefinition(type, field) {
307
- return type.hasOwnProperty(field) ? type[field] : null;
308
- }
309
- /**
310
- * Read the injectable def (`ɵprov`) for `type` or read the `ɵprov` from one of its ancestors.
311
- *
312
- * @param type A type which may have `ɵprov`, via inheritance.
313
- *
314
- * @deprecated Will be removed in a future version of Angular, where an error will occur in the
315
- * scenario if we find the `ɵprov` on an ancestor only.
316
- */
317
- function getInheritedInjectableDef(type) {
318
- const def = type && (type[NG_PROV_DEF] || null);
319
- if (def) {
320
- return def;
321
- }
322
- else {
323
- return null;
324
- }
325
- }
326
- /**
327
- * Read the injector def type in a way which is immune to accidentally reading inherited value.
328
- *
329
- * @param type type which may have an injector def (`ɵinj`)
330
- */
331
- function getInjectorDef(type) {
332
- return type && (type.hasOwnProperty(NG_INJ_DEF) || false)
333
- ? type[NG_INJ_DEF]
334
- : null;
335
- }
336
- const NG_PROV_DEF = getClosureSafeProperty({
337
- ɵprov: getClosureSafeProperty,
338
- });
339
- const NG_INJ_DEF = getClosureSafeProperty({
340
- ɵinj: getClosureSafeProperty,
341
- });
342
-
343
- /**
344
- * @license
345
- * Copyright Google LLC All Rights Reserved.
346
- *
347
- * Use of this source code is governed by an MIT-style license that can be
348
- * found in the LICENSE file at https://angular.io/license
349
- */
350
- /**
351
- * Injection flags for DI.
352
- *
353
- * @publicApi
354
- * @deprecated use an options object for [`inject`](api/core/inject) instead.
355
- */
356
- exports.InjectFlags = void 0;
357
- (function (InjectFlags) {
358
- // TODO(alxhub): make this 'const' (and remove `InternalInjectFlags` enum) when ngc no longer
359
- // writes exports of it into ngfactory files.
360
- /** Check self and check parent injector if needed */
361
- InjectFlags[InjectFlags["Default"] = 0] = "Default";
362
- /** Don't ascend to ancestors of the node requesting injection. */
363
- InjectFlags[InjectFlags["Self"] = 2] = "Self";
364
- /** Skip the node that is requesting injection. */
365
- InjectFlags[InjectFlags["SkipSelf"] = 4] = "SkipSelf";
366
- /** Inject `defaultValue` instead if token not found. */
367
- InjectFlags[InjectFlags["Optional"] = 8] = "Optional";
368
- })(exports.InjectFlags || (exports.InjectFlags = {}));
369
-
370
- /**
371
- * @license
372
- * Copyright Google LLC All Rights Reserved.
373
- *
374
- * Use of this source code is governed by an MIT-style license that can be
375
- * found in the LICENSE file at https://angular.io/license
376
- */
377
- /**
378
- * Current implementation of inject.
379
- *
380
- * By default, it is `injectInjectorOnly`, which makes it `Injector`-only aware. It can be changed
381
- * to `directiveInject`, which brings in the `NodeInjector` system of ivy. It is designed this
382
- * way for two reasons:
383
- * 1. `Injector` should not depend on ivy logic.
384
- * 2. To maintain tree shake-ability we don't want to bring in unnecessary code.
385
- */
386
- let _injectImplementation;
387
- function getInjectImplementation() {
388
- return _injectImplementation;
389
- }
390
- /**
391
- * Sets the current inject implementation.
392
- */
393
- function setInjectImplementation(impl) {
394
- const previous = _injectImplementation;
395
- _injectImplementation = impl;
396
- return previous;
397
- }
398
- /**
399
- * Injects `root` tokens in limp mode.
400
- *
401
- * If no injector exists, we can still inject tree-shakable providers which have `providedIn` set to
402
- * `"root"`. This is known as the limp mode injection. In such case the value is stored in the
403
- * injectable definition.
404
- */
405
- function injectRootLimpMode(token, notFoundValue, flags) {
406
- const injectableDef = getInjectableDef(token);
407
- if (injectableDef && injectableDef.providedIn == 'root') {
408
- return injectableDef.value === undefined
409
- ? (injectableDef.value = injectableDef.factory())
410
- : injectableDef.value;
411
- }
412
- if (flags & exports.InjectFlags.Optional)
413
- return null;
414
- throwProviderNotFoundError();
415
- }
416
-
417
- /**
418
- * @license
419
- * Copyright Google LLC All Rights Reserved.
420
- *
421
- * Use of this source code is governed by an MIT-style license that can be
422
- * found in the LICENSE file at https://angular.io/license
423
- */
424
- const _THROW_IF_NOT_FOUND = {};
425
- const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
426
- /*
427
- * Name of a property (that we patch onto DI decorator), which is used as an annotation of which
428
- * InjectFlag this decorator represents. This allows to avoid direct references to the DI decorators
429
- * in the code, thus making them tree-shakable.
430
- */
431
- const DI_DECORATOR_FLAG = '__NG_DI_FLAG__';
432
- const NG_TEMP_TOKEN_PATH = 'ngTempTokenPath';
433
- const NG_TOKEN_PATH = 'ngTokenPath';
434
- const NEW_LINE = /\n/gm;
435
- const NO_NEW_LINE = 'ɵ';
436
- const SOURCE = '__source';
437
- /**
438
- * Current injector value used by `inject`.
439
- * - `undefined`: it is an error to call `inject`
440
- * - `null`: `inject` can be called but there is no injector (limp-mode).
441
- * - Injector instance: Use the injector for resolution.
442
- */
443
- let _currentInjector = undefined;
444
- function getCurrentInjector() {
445
- return _currentInjector;
446
- }
447
- function setCurrentInjector(injector) {
448
- const former = _currentInjector;
449
- _currentInjector = injector;
450
- return former;
451
- }
452
- function injectInjectorOnly(token, flags = exports.InjectFlags.Default) {
453
- if (_currentInjector === undefined) {
454
- throw new RuntimeError(-203 /* RuntimeErrorCode.MISSING_INJECTION_CONTEXT */, null);
455
- }
456
- else if (_currentInjector === null) {
457
- return injectRootLimpMode(token, undefined, flags);
458
- }
459
- else {
460
- const value = _currentInjector.get(token, flags & exports.InjectFlags.Optional ? null : undefined, flags);
461
- return value;
462
- }
463
- }
464
- function ɵɵinject(token, flags = exports.InjectFlags.Default) {
465
- return (getInjectImplementation() || injectInjectorOnly)(resolveForwardRef(token), flags);
466
- }
467
- /**
468
- * Throws an error indicating that a factory function could not be generated by the compiler for a
469
- * particular class.
470
- *
471
- * The name of the class is not mentioned here, but will be in the generated factory function name
472
- * and thus in the stack trace.
473
- *
474
- * @codeGenApi
475
- */
476
- function ɵɵinvalidFactoryDep(index) {
477
- throw new RuntimeError(202 /* RuntimeErrorCode.INVALID_FACTORY_DEPENDENCY */, null);
478
- }
479
- /**
480
- * @param token A token that represents a static attribute on the host node that should be injected.
481
- * @returns Value of the attribute if it exists.
482
- * @throws If called outside of a supported context or the attribute does not exist.
483
- *
484
- * @publicApi
485
- */
486
- /**
487
- * @param token A token that represents a static attribute on the host node that should be injected.
488
- * @returns Value of the attribute if it exists, otherwise `null`.
489
- * @throws If called outside of a supported context.
490
- *
491
- * @publicApi
492
- */
493
- /**
494
- * @param token A token that represents a static attribute on the host node that should be injected.
495
- * @returns Value of the attribute if it exists.
496
- * @throws If called outside of a supported context or the attribute does not exist.
497
- *
498
- * @publicApi
499
- */
500
- /**
501
- * Injects a token from the currently active injector.
502
- * `inject` is only supported in an [injection context](/guide/dependency-injection-context). It can
503
- * be used during:
504
- * - Construction (via the `constructor`) of a class being instantiated by the DI system, such
505
- * as an `@Injectable` or `@Component`.
506
- * - In the initializer for fields of such classes.
507
- * - In the factory function specified for `useFactory` of a `Provider` or an `@Injectable`.
508
- * - In the `factory` function specified for an `InjectionToken`.
509
- * - In a stackframe of a function call in a DI context
510
- *
511
- * @param token A token that represents a dependency that should be injected.
512
- * @param flags Optional flags that control how injection is executed.
513
- * The flags correspond to injection strategies that can be specified with
514
- * parameter decorators `@Host`, `@Self`, `@SkipSelf`, and `@Optional`.
515
- * @returns the injected value if operation is successful, `null` otherwise.
516
- * @throws if called outside of a supported context.
517
- *
518
- * @usageNotes
519
- * In practice the `inject()` calls are allowed in a constructor, a constructor parameter and a
520
- * field initializer:
521
- *
522
- * ```typescript
523
- * @Injectable({providedIn: 'root'})
524
- * export class Car {
525
- * radio: Radio|undefined;
526
- * // OK: field initializer
527
- * spareTyre = inject(Tyre);
528
- *
529
- * constructor() {
530
- * // OK: constructor body
531
- * this.radio = inject(Radio);
532
- * }
533
- * }
534
- * ```
535
- *
536
- * It is also legal to call `inject` from a provider's factory:
537
- *
538
- * ```typescript
539
- * providers: [
540
- * {provide: Car, useFactory: () => {
541
- * // OK: a class factory
542
- * const engine = inject(Engine);
543
- * return new Car(engine);
544
- * }}
545
- * ]
546
- * ```
547
- *
548
- * Calls to the `inject()` function outside of the class creation context will result in error. Most
549
- * notably, calls to `inject()` are disallowed after a class instance was created, in methods
550
- * (including lifecycle hooks):
551
- *
552
- * ```typescript
553
- * @Component({ ... })
554
- * export class CarComponent {
555
- * ngOnInit() {
556
- * // ERROR: too late, the component instance was already created
557
- * const engine = inject(Engine);
558
- * engine.start();
559
- * }
560
- * }
561
- * ```
562
- *
563
- * @publicApi
564
- */
565
- function inject(token, flags = exports.InjectFlags.Default) {
566
- // The `as any` here _shouldn't_ be necessary, but without it JSCompiler
567
- // throws a disambiguation error due to the multiple signatures.
568
- return ɵɵinject(token, convertToBitFlags(flags));
569
- }
570
- // Converts object-based DI flags (`InjectOptions`) to bit flags (`InjectFlags`).
571
- function convertToBitFlags(flags) {
572
- if (typeof flags === 'undefined' || typeof flags === 'number') {
573
- return flags;
574
- }
575
- // While TypeScript doesn't accept it without a cast, bitwise OR with false-y values in
576
- // JavaScript is a no-op. We can use that for a very codesize-efficient conversion from
577
- // `InjectOptions` to `InjectFlags`.
578
- return (0 /* InternalInjectFlags.Default */ | // comment to force a line break in the formatter
579
- (flags.optional && 8 /* InternalInjectFlags.Optional */) |
580
- 0 |
581
- (flags.self && 2 /* InternalInjectFlags.Self */) |
582
- (flags.skipSelf &&
583
- 4 /* InternalInjectFlags.SkipSelf */));
584
- }
585
- function injectArgs(types) {
586
- const args = [];
587
- for (let i = 0; i < types.length; i++) {
588
- const arg = resolveForwardRef(types[i]);
589
- if (Array.isArray(arg)) {
590
- if (arg.length === 0) {
591
- throw new RuntimeError(900 /* RuntimeErrorCode.INVALID_DIFFER_INPUT */, null);
592
- }
593
- let type = undefined;
594
- let flags = exports.InjectFlags.Default;
595
- for (let j = 0; j < arg.length; j++) {
596
- const meta = arg[j];
597
- const flag = getInjectFlag(meta);
598
- if (typeof flag === 'number') {
599
- // Special case when we handle @Inject decorator.
600
- if (flag === -1 /* DecoratorFlags.Inject */) {
601
- type = meta.token;
602
- }
603
- else {
604
- flags |= flag;
605
- }
606
- }
607
- else {
608
- type = meta;
609
- }
610
- }
611
- args.push(ɵɵinject(type, flags));
612
- }
613
- else {
614
- args.push(ɵɵinject(arg));
615
- }
616
- }
617
- return args;
618
- }
619
- /**
620
- * Attaches a given InjectFlag to a given decorator using monkey-patching.
621
- * Since DI decorators can be used in providers `deps` array (when provider is configured using
622
- * `useFactory`) without initialization (e.g. `Host`) and as an instance (e.g. `new Host()`), we
623
- * attach the flag to make it available both as a static property and as a field on decorator
624
- * instance.
625
- *
626
- * @param decorator Provided DI decorator.
627
- * @param flag InjectFlag that should be applied.
628
- */
629
- function attachInjectFlag(decorator, flag) {
630
- decorator[DI_DECORATOR_FLAG] = flag;
631
- decorator.prototype[DI_DECORATOR_FLAG] = flag;
632
- return decorator;
633
- }
634
- /**
635
- * Reads monkey-patched property that contains InjectFlag attached to a decorator.
636
- *
637
- * @param token Token that may contain monkey-patched DI flags property.
638
- */
639
- function getInjectFlag(token) {
640
- return token[DI_DECORATOR_FLAG];
641
- }
642
- function catchInjectorError(e, token, injectorErrorName, source) {
643
- const tokenPath = e[NG_TEMP_TOKEN_PATH];
644
- if (token[SOURCE]) {
645
- tokenPath.unshift(token[SOURCE]);
646
- }
647
- e.message = formatError('\n' + e.message, tokenPath, injectorErrorName, source);
648
- e[NG_TOKEN_PATH] = tokenPath;
649
- e[NG_TEMP_TOKEN_PATH] = null;
650
- throw e;
651
- }
652
- function formatError(text, obj, injectorErrorName, source = null) {
653
- text =
654
- text && text.charAt(0) === '\n' && text.charAt(1) == NO_NEW_LINE
655
- ? text.slice(2)
656
- : text;
657
- let context = stringify(obj);
658
- if (Array.isArray(obj)) {
659
- context = obj.map(stringify).join(' -> ');
660
- }
661
- else if (typeof obj === 'object') {
662
- let parts = [];
663
- for (let key in obj) {
664
- if (obj.hasOwnProperty(key)) {
665
- let value = obj[key];
666
- parts.push(key +
667
- ':' +
668
- (typeof value === 'string'
669
- ? JSON.stringify(value)
670
- : stringify(value)));
671
- }
672
- }
673
- context = `{${parts.join(', ')}}`;
674
- }
675
- return `${injectorErrorName}${source ? '(' + source + ')' : ''}[${context}]: ${text.replace(NEW_LINE, '\n ')}`;
676
- }
677
-
678
- /**
679
- * @license
680
- * Copyright Google LLC All Rights Reserved.
681
- *
682
- * Use of this source code is governed by an MIT-style license that can be
683
- * found in the LICENSE file at https://angular.io/license
684
- */
685
- /**
686
- * Inject decorator and metadata.
687
- *
688
- * @Annotation
689
- * @publicApi
690
- */
691
- const Inject = attachInjectFlag(
692
- // Disable tslint because `DecoratorFlags` is a const enum which gets inlined.
693
- // tslint:disable-next-line: no-toplevel-property-access
694
- makeParamDecorator('Inject', (token) => ({ token })), -1 /* DecoratorFlags.Inject */);
695
- /**
696
- * Optional decorator and metadata.
697
- *
698
- * @Annotation
699
- * @publicApi
700
- */
701
- const Optional =
702
- // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
703
- // tslint:disable-next-line: no-toplevel-property-access
704
- attachInjectFlag(makeParamDecorator(), 8 /* InternalInjectFlags.Optional */);
705
- /**
706
- * Self decorator and metadata.
707
- *
708
- * @Annotation
709
- * @publicApi
710
- */
711
- const Self =
712
- // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
713
- // tslint:disable-next-line: no-toplevel-property-access
714
- attachInjectFlag(makeParamDecorator(), 2 /* InternalInjectFlags.Self */);
715
- /**
716
- * `SkipSelf` decorator and metadata.
717
- *
718
- * @Annotation
719
- * @publicApi
720
- */
721
- const SkipSelf =
722
- // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
723
- // tslint:disable-next-line: no-toplevel-property-access
724
- attachInjectFlag(makeParamDecorator(), 4 /* InternalInjectFlags.SkipSelf */);
725
-
726
- /**
727
- * @license
728
- * Copyright Google LLC All Rights Reserved.
729
- *
730
- * Use of this source code is governed by an MIT-style license that can be
731
- * found in the LICENSE file at https://angular.io/license
732
- */
733
- function getFactoryDef(type, throwNotFound) {
734
- return () => new type();
735
- }
736
-
737
- /**
738
- * @license
739
- * Copyright Google LLC All Rights Reserved.
740
- *
741
- * Use of this source code is governed by an MIT-style license that can be
742
- * found in the LICENSE file at https://angular.io/license
743
- */
744
- getClosureSafeProperty({
745
- ɵfac: getClosureSafeProperty,
746
- });
747
- /**
748
- * The `NG_ENV_ID` field on a DI token indicates special processing in the `EnvironmentInjector`:
749
- * getting such tokens from the `EnvironmentInjector` will bypass the standard DI resolution
750
- * strategy and instead will return implementation produced by the `NG_ENV_ID` factory function.
751
- *
752
- * This particular retrieval of DI tokens is mostly done to eliminate circular dependencies and
753
- * improve tree-shaking.
754
- */
755
- const NG_ENV_ID = getClosureSafeProperty({
756
- __NG_ENV_ID__: getClosureSafeProperty,
757
- });
758
-
759
- /**
760
- * @license
761
- * Copyright Google LLC All Rights Reserved.
762
- *
763
- * Use of this source code is governed by an MIT-style license that can be
764
- * found in the LICENSE file at https://angular.io/license
765
- */
766
- /**
767
- * This file contains reuseable "empty" symbols that can be used as default return values
768
- * in different parts of the rendering code. Because the same symbols are returned, this
769
- * allows for identity checks against these values to be consistently used by the framework
770
- * code.
771
- */
772
- const EMPTY_ARRAY = [];
773
-
774
- /**
775
- * @license
776
- * Copyright Google LLC All Rights Reserved.
777
- *
778
- * Use of this source code is governed by an MIT-style license that can be
779
- * found in the LICENSE file at https://angular.io/license
780
- */
781
- /**
782
- * Creates a token that can be used in a DI Provider.
783
- *
784
- * Use an `InjectionToken` whenever the type you are injecting is not reified (does not have a
785
- * runtime representation) such as when injecting an interface, callable type, array or
786
- * parameterized type.
787
- *
788
- * `InjectionToken` is parameterized on `T` which is the type of object which will be returned by
789
- * the `Injector`. This provides an additional level of type safety.
790
- *
791
- * <div class="alert is-helpful">
792
- *
793
- * **Important Note**: Ensure that you use the same instance of the `InjectionToken` in both the
794
- * provider and the injection call. Creating a new instance of `InjectionToken` in different places,
795
- * even with the same description, will be treated as different tokens by Angular's DI system,
796
- * leading to a `NullInjectorError`.
797
- *
798
- * </div>
799
- *
800
- * <code-example format="typescript" language="typescript" path="injection-token/src/main.ts"
801
- * region="InjectionToken"></code-example>
802
- *
803
- * When creating an `InjectionToken`, you can optionally specify a factory function which returns
804
- * (possibly by creating) a default value of the parameterized type `T`. This sets up the
805
- * `InjectionToken` using this factory as a provider as if it was defined explicitly in the
806
- * application's root injector. If the factory function, which takes zero arguments, needs to inject
807
- * dependencies, it can do so using the [`inject`](api/core/inject) function.
808
- * As you can see in the Tree-shakable InjectionToken example below.
809
- *
810
- * Additionally, if a `factory` is specified you can also specify the `providedIn` option, which
811
- * overrides the above behavior and marks the token as belonging to a particular `@NgModule` (note:
812
- * this option is now deprecated). As mentioned above, `'root'` is the default value for
813
- * `providedIn`.
814
- *
815
- * The `providedIn: NgModule` and `providedIn: 'any'` options are deprecated.
816
- *
817
- * @usageNotes
818
- * ### Basic Examples
819
- *
820
- * ### Plain InjectionToken
821
- *
822
- * {@example core/di/ts/injector_spec.ts region='InjectionToken'}
823
- *
824
- * ### Tree-shakable InjectionToken
825
- *
826
- * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
827
- *
828
- * @publicApi
829
- */
830
- class InjectionToken {
831
- _desc;
832
- /** @internal */
833
- ngMetadataName = 'InjectionToken';
834
- ɵprov;
835
- /**
836
- * @param _desc Description for the token,
837
- * used only for debugging purposes,
838
- * it should but does not need to be unique
839
- * @param options Options for the token's usage, as described above
840
- */
841
- constructor(_desc, options) {
842
- this._desc = _desc;
843
- this.ɵprov = undefined;
844
- if (typeof options == 'number') ;
845
- else if (options !== undefined) {
846
- this.ɵprov = ɵɵdefineInjectable({
847
- token: this,
848
- providedIn: options.providedIn || 'root',
849
- factory: options.factory,
850
- });
851
- }
852
- }
853
- /**
854
- * @internal
855
- */
856
- get multi() {
857
- return this;
858
- }
859
- toString() {
860
- return `InjectionToken ${this._desc}`;
861
- }
862
- }
863
-
864
- /**
865
- * @license
866
- * Copyright Google LLC All Rights Reserved.
867
- *
868
- * Use of this source code is governed by an MIT-style license that can be
869
- * found in the LICENSE file at https://angular.io/license
870
- */
871
- /**
872
- * A multi-provider token for initialization functions that will run upon construction of an
873
- * environment injector.
874
- *
875
- * @publicApi
876
- */
877
- const ENVIRONMENT_INITIALIZER = new InjectionToken('');
878
-
879
- /**
880
- * @license
881
- * Copyright Google LLC All Rights Reserved.
882
- *
883
- * Use of this source code is governed by an MIT-style license that can be
884
- * found in the LICENSE file at https://angular.io/license
885
- */
886
- /**
887
- * An InjectionToken that gets the current `Injector` for `createInjector()`-style injectors.
888
- *
889
- * Requesting this token instead of `Injector` allows `StaticInjector` to be tree-shaken from a
890
- * project.
891
- *
892
- * @publicApi
893
- */
894
- const INJECTOR = new InjectionToken('',
895
- // Disable tslint because this is const enum which gets inlined not top level prop access.
896
- // tslint:disable-next-line: no-toplevel-property-access
897
- -1 /* InjectorMarkers.Injector */);
898
-
899
- /**
900
- * @license
901
- * Copyright Google LLC All Rights Reserved.
902
- *
903
- * Use of this source code is governed by an MIT-style license that can be
904
- * found in the LICENSE file at https://angular.io/license
905
- */
906
- function isEnvironmentProviders(value) {
907
- return value && !!value.ɵproviders;
908
- }
909
-
910
- /**
911
- * @license
912
- * Copyright Google LLC All Rights Reserved.
913
- *
914
- * Use of this source code is governed by an MIT-style license that can be
915
- * found in the LICENSE file at https://angular.io/license
916
- */
917
- const INJECTOR_DEF_TYPES = new InjectionToken('');
918
-
919
- /**
920
- * @license
921
- * Copyright Google LLC All Rights Reserved.
922
- *
923
- * Use of this source code is governed by an MIT-style license that can be
924
- * found in the LICENSE file at https://angular.io/license
925
- */
926
- class NullInjector {
927
- get(token, notFoundValue = THROW_IF_NOT_FOUND) {
928
- if (notFoundValue === THROW_IF_NOT_FOUND) {
929
- const error = new Error(`NullInjectorError: No provider for ${stringify(token)}!`);
930
- error.name = 'NullInjectorError';
931
- throw error;
932
- }
933
- return notFoundValue;
934
- }
935
- }
936
-
937
- /**
938
- * @license
939
- * Copyright Google LLC All Rights Reserved.
940
- *
941
- * Use of this source code is governed by an MIT-style license that can be
942
- * found in the LICENSE file at https://angular.io/license
943
- */
944
- /**
945
- * Collects providers from all NgModules and standalone components, including transitively imported
946
- * ones.
947
- *
948
- * Providers extracted via `importProvidersFrom` are only usable in an application injector or
949
- * another environment injector (such as a route injector). They should not be used in component
950
- * providers.
951
- *
952
- * More information about standalone components can be found in [this
953
- * guide](guide/standalone-components).
954
- *
955
- * @usageNotes
956
- * The results of the `importProvidersFrom` call can be used in the `bootstrapApplication` call:
957
- *
958
- * ```typescript
959
- * await bootstrapApplication(RootComponent, {
960
- * providers: [
961
- * importProvidersFrom(NgModuleOne, NgModuleTwo)
962
- * ]
963
- * });
964
- * ```
965
- *
966
- * You can also use the `importProvidersFrom` results in the `providers` field of a route, when a
967
- * standalone component is used:
968
- *
969
- * ```typescript
970
- * export const ROUTES: Route[] = [
971
- * {
972
- * path: 'foo',
973
- * providers: [
974
- * importProvidersFrom(NgModuleOne, NgModuleTwo)
975
- * ],
976
- * component: YourStandaloneComponent
977
- * }
978
- * ];
979
- * ```
980
- *
981
- * @returns Collected providers from the specified list of types.
982
- * @publicApi
983
- */
984
- function importProvidersFrom(...sources) {
985
- return {
986
- ɵproviders: internalImportProvidersFrom(true, sources),
987
- ɵfromNgModule: true,
988
- };
989
- }
990
- function internalImportProvidersFrom(checkForStandaloneCmp, ...sources) {
991
- const providersOut = [];
992
- return providersOut;
993
- }
994
- const USE_VALUE = getClosureSafeProperty({
995
- provide: String,
996
- useValue: getClosureSafeProperty,
997
- });
998
- function isValueProvider(value) {
999
- return value !== null && typeof value == 'object' && USE_VALUE in value;
1000
- }
1001
- function isExistingProvider(value) {
1002
- return !!(value && value.useExisting);
1003
- }
1004
- function isFactoryProvider(value) {
1005
- return !!(value && value.useFactory);
1006
- }
1007
- function isTypeProvider(value) {
1008
- return typeof value === 'function';
1009
- }
1010
-
1011
- /**
1012
- * @license
1013
- * Copyright Google LLC All Rights Reserved.
1014
- *
1015
- * Use of this source code is governed by an MIT-style license that can be
1016
- * found in the LICENSE file at https://angular.io/license
1017
- */
1018
- /**
1019
- * An internal token whose presence in an injector indicates that the injector should treat itself
1020
- * as a root scoped injector when processing requests for unknown tokens which may indicate
1021
- * they are provided in the root scope.
1022
- */
1023
- const INJECTOR_SCOPE = new InjectionToken('');
1024
-
1025
- /**
1026
- * @license
1027
- * Copyright Google LLC All Rights Reserved.
1028
- *
1029
- * Use of this source code is governed by an MIT-style license that can be
1030
- * found in the LICENSE file at https://angular.io/license
1031
- */
1032
- /**
1033
- * Marker which indicates that a value has not yet been created from the factory function.
1034
- */
1035
- const NOT_YET = {};
1036
- /**
1037
- * Marker which indicates that the factory function for a token is in the process of being called.
1038
- *
1039
- * If the injector is asked to inject a token with its value set to CIRCULAR, that indicates
1040
- * injection of a dependency has recursively attempted to inject the original token, and there is
1041
- * a circular dependency among the providers.
1042
- */
1043
- const CIRCULAR = {};
1044
- /**
1045
- * A lazily initialized NullInjector.
1046
- */
1047
- let NULL_INJECTOR = undefined;
1048
- function getNullInjector() {
1049
- if (NULL_INJECTOR === undefined) {
1050
- NULL_INJECTOR = new NullInjector();
1051
- }
1052
- return NULL_INJECTOR;
1053
- }
1054
- /**
1055
- * An `Injector` that's part of the environment injector hierarchy, which exists outside of the
1056
- * component tree.
1057
- */
1058
- class EnvironmentInjector {
1059
- }
1060
- class R3Injector extends EnvironmentInjector {
1061
- parent;
1062
- source;
1063
- scopes;
1064
- /**
1065
- * Map of tokens to records which contain the instances of those tokens.
1066
- * - `null` value implies that we don't have the record. Used by tree-shakable injectors
1067
- * to prevent further searches.
1068
- */
1069
- records = new Map();
1070
- /**
1071
- * Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
1072
- */
1073
- _ngOnDestroyHooks = new Set();
1074
- _onDestroyHooks = [];
1075
- /**
1076
- * Flag indicating that this injector was previously destroyed.
1077
- */
1078
- get destroyed() {
1079
- return this._destroyed;
1080
- }
1081
- _destroyed = false;
1082
- injectorDefTypes;
1083
- constructor(providers, parent, source, scopes) {
1084
- super();
1085
- this.parent = parent;
1086
- this.source = source;
1087
- this.scopes = scopes;
1088
- // Start off by creating Records for every provider.
1089
- forEachSingleProvider(providers, (provider) => this.processProvider(provider));
1090
- // Make sure the INJECTOR token provides this injector.
1091
- this.records.set(INJECTOR, makeRecord(undefined, this));
1092
- // And `EnvironmentInjector` if the current injector is supposed to be env-scoped.
1093
- if (scopes.has('environment')) {
1094
- this.records.set(EnvironmentInjector, makeRecord(undefined, this));
1095
- }
1096
- // Detect whether this injector has the APP_ROOT_SCOPE token and thus should provide
1097
- // any injectable scoped to APP_ROOT_SCOPE.
1098
- const record = this.records.get(INJECTOR_SCOPE);
1099
- if (record != null && typeof record.value === 'string') {
1100
- this.scopes.add(record.value);
1101
- }
1102
- this.injectorDefTypes = new Set(this.get(INJECTOR_DEF_TYPES, EMPTY_ARRAY, exports.InjectFlags.Self));
1103
- }
1104
- /**
1105
- * Destroy the injector and release references to every instance or provider associated with it.
1106
- *
1107
- * Also calls the `OnDestroy` lifecycle hooks of every instance that was created for which a
1108
- * hook was found.
1109
- */
1110
- destroy() {
1111
- this.assertNotDestroyed();
1112
- // Set destroyed = true first, in case lifecycle hooks re-enter destroy().
1113
- this._destroyed = true;
1114
- try {
1115
- // Call all the lifecycle hooks.
1116
- for (const service of this._ngOnDestroyHooks) {
1117
- service.ngOnDestroy();
1118
- }
1119
- const onDestroyHooks = this._onDestroyHooks;
1120
- // Reset the _onDestroyHooks array before iterating over it to prevent hooks that unregister
1121
- // themselves from mutating the array during iteration.
1122
- this._onDestroyHooks = [];
1123
- for (const hook of onDestroyHooks) {
1124
- hook();
1125
- }
1126
- }
1127
- finally {
1128
- // Release all references.
1129
- this.records.clear();
1130
- this._ngOnDestroyHooks.clear();
1131
- this.injectorDefTypes.clear();
1132
- }
1133
- }
1134
- onDestroy(callback) {
1135
- this.assertNotDestroyed();
1136
- this._onDestroyHooks.push(callback);
1137
- return () => this.removeOnDestroy(callback);
1138
- }
1139
- runInContext(fn) {
1140
- this.assertNotDestroyed();
1141
- const previousInjector = setCurrentInjector(this);
1142
- const previousInjectImplementation = setInjectImplementation(undefined);
1143
- try {
1144
- return fn();
1145
- }
1146
- finally {
1147
- setCurrentInjector(previousInjector);
1148
- setInjectImplementation(previousInjectImplementation);
1149
- }
1150
- }
1151
- get(token, notFoundValue = THROW_IF_NOT_FOUND, flags = exports.InjectFlags.Default) {
1152
- this.assertNotDestroyed();
1153
- if (token.hasOwnProperty(NG_ENV_ID)) {
1154
- return token[NG_ENV_ID](this);
1155
- }
1156
- flags = convertToBitFlags(flags);
1157
- const previousInjector = setCurrentInjector(this);
1158
- const previousInjectImplementation = setInjectImplementation(undefined);
1159
- try {
1160
- // Check for the SkipSelf flag.
1161
- if (!(flags & exports.InjectFlags.SkipSelf)) {
1162
- // SkipSelf isn't set, check if the record belongs to this injector.
1163
- let record = this.records.get(token);
1164
- if (record === undefined) {
1165
- // No record, but maybe the token is scoped to this injector. Look for an injectable
1166
- // def with a scope matching this injector.
1167
- const def = couldBeInjectableType(token) && getInjectableDef(token);
1168
- if (def && this.injectableDefInScope(def)) {
1169
- // Found an injectable def and it's scoped to this injector. Pretend as if it was here
1170
- // all along.
1171
- if (false) ;
1172
- record = makeRecord(injectableDefOrInjectorDefFactory(token), NOT_YET);
1173
- }
1174
- else {
1175
- record = null;
1176
- }
1177
- this.records.set(token, record);
1178
- }
1179
- // If a record was found, get the instance for it and return it.
1180
- if (record != null /* NOT null || undefined */) {
1181
- return this.hydrate(token, record);
1182
- }
1183
- }
1184
- // Select the next injector based on the Self flag - if self is set, the next injector is
1185
- // the NullInjector, otherwise it's the parent.
1186
- const nextInjector = !(flags & exports.InjectFlags.Self)
1187
- ? this.parent
1188
- : getNullInjector();
1189
- // Set the notFoundValue based on the Optional flag - if optional is set and notFoundValue
1190
- // is undefined, the value is null, otherwise it's the notFoundValue.
1191
- notFoundValue =
1192
- flags & exports.InjectFlags.Optional && notFoundValue === THROW_IF_NOT_FOUND
1193
- ? null
1194
- : notFoundValue;
1195
- return nextInjector.get(token, notFoundValue);
1196
- }
1197
- catch (e) {
1198
- if (e.name === 'NullInjectorError') {
1199
- const path = (e[NG_TEMP_TOKEN_PATH] =
1200
- e[NG_TEMP_TOKEN_PATH] || []);
1201
- path.unshift(stringify(token));
1202
- if (previousInjector) {
1203
- // We still have a parent injector, keep throwing
1204
- throw e;
1205
- }
1206
- else {
1207
- // Format & throw the final error message when we don't have any previous injector
1208
- return catchInjectorError(e, token, 'R3InjectorError', this.source);
1209
- }
1210
- }
1211
- else {
1212
- throw e;
1213
- }
1214
- }
1215
- finally {
1216
- // Lastly, restore the previous injection context.
1217
- setInjectImplementation(previousInjectImplementation);
1218
- setCurrentInjector(previousInjector);
1219
- }
1220
- }
1221
- /** @internal */
1222
- resolveInjectorInitializers() {
1223
- const previousInjector = setCurrentInjector(this);
1224
- const previousInjectImplementation = setInjectImplementation(undefined);
1225
- try {
1226
- const initializers = this.get(ENVIRONMENT_INITIALIZER, EMPTY_ARRAY, exports.InjectFlags.Self);
1227
- if (false) ;
1228
- for (const initializer of initializers) {
1229
- initializer();
1230
- }
1231
- }
1232
- finally {
1233
- setCurrentInjector(previousInjector);
1234
- setInjectImplementation(previousInjectImplementation);
1235
- }
1236
- }
1237
- toString() {
1238
- const tokens = [];
1239
- const records = this.records;
1240
- for (const token of records.keys()) {
1241
- tokens.push(stringify(token));
1242
- }
1243
- return `R3Injector[${tokens.join(', ')}]`;
1244
- }
1245
- assertNotDestroyed() {
1246
- if (this._destroyed) {
1247
- throw new RuntimeError(205 /* RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED */, null);
1248
- }
1249
- }
1250
- /**
1251
- * Process a `SingleProvider` and add it.
1252
- */
1253
- processProvider(provider) {
1254
- // Determine the token from the provider. Either it's its own token, or has a {provide: ...}
1255
- // property.
1256
- provider = resolveForwardRef(provider);
1257
- let token = isTypeProvider(provider)
1258
- ? provider
1259
- : resolveForwardRef(provider && provider.provide);
1260
- // Construct a `Record` for the provider.
1261
- const record = providerToRecord(provider);
1262
- if (!isTypeProvider(provider) && provider.multi === true) {
1263
- // If the provider indicates that it's a multi-provider, process it specially.
1264
- // First check whether it's been defined already.
1265
- let multiRecord = this.records.get(token);
1266
- if (multiRecord) ;
1267
- else {
1268
- multiRecord = makeRecord(undefined, NOT_YET, true);
1269
- multiRecord.factory = () => injectArgs(multiRecord.multi);
1270
- this.records.set(token, multiRecord);
1271
- }
1272
- token = provider;
1273
- multiRecord.multi.push(provider);
1274
- }
1275
- this.records.set(token, record);
1276
- }
1277
- hydrate(token, record) {
1278
- try {
1279
- if (false) ;
1280
- else if (record.value === NOT_YET) {
1281
- record.value = CIRCULAR;
1282
- if (false) ;
1283
- else {
1284
- record.value = record.factory();
1285
- }
1286
- }
1287
- if (typeof record.value === 'object' &&
1288
- record.value &&
1289
- hasOnDestroy(record.value)) {
1290
- this._ngOnDestroyHooks.add(record.value);
1291
- }
1292
- return record.value;
1293
- }
1294
- finally {
1295
- }
1296
- }
1297
- injectableDefInScope(def) {
1298
- if (!def.providedIn) {
1299
- return false;
1300
- }
1301
- const providedIn = resolveForwardRef(def.providedIn);
1302
- if (typeof providedIn === 'string') {
1303
- return providedIn === 'any' || this.scopes.has(providedIn);
1304
- }
1305
- else {
1306
- return this.injectorDefTypes.has(providedIn);
1307
- }
1308
- }
1309
- removeOnDestroy(callback) {
1310
- const destroyCBIdx = this._onDestroyHooks.indexOf(callback);
1311
- if (destroyCBIdx !== -1) {
1312
- this._onDestroyHooks.splice(destroyCBIdx, 1);
1313
- }
1314
- }
1315
- }
1316
- function injectableDefOrInjectorDefFactory(token) {
1317
- // Most tokens will have an injectable def directly on them, which specifies a factory directly.
1318
- const injectableDef = getInjectableDef(token);
1319
- const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
1320
- if (factory !== null) {
1321
- return factory;
1322
- }
1323
- // InjectionTokens should have an injectable def (ɵprov) and thus should be handled above.
1324
- // If it's missing that, it's an error.
1325
- if (token instanceof InjectionToken) {
1326
- throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
1327
- }
1328
- // Undecorated types can sometimes be created if they have no constructor arguments.
1329
- if (token instanceof Function) {
1330
- return getUndecoratedInjectableFactory(token);
1331
- }
1332
- // There was no way to resolve a factory for this token.
1333
- throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
1334
- }
1335
- function getUndecoratedInjectableFactory(token) {
1336
- // If the token has parameters then it has dependencies that we cannot resolve implicitly.
1337
- const paramLength = token.length;
1338
- if (paramLength > 0) {
1339
- throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
1340
- }
1341
- // The constructor function appears to have no parameters.
1342
- // This might be because it inherits from a super-class. In which case, use an injectable
1343
- // def from an ancestor if there is one.
1344
- // Otherwise this really is a simple class with no dependencies, so return a factory that
1345
- // just instantiates the zero-arg constructor.
1346
- const inheritedInjectableDef = getInheritedInjectableDef(token);
1347
- if (inheritedInjectableDef !== null) {
1348
- return () => inheritedInjectableDef.factory(token);
1349
- }
1350
- else {
1351
- return () => new token();
1352
- }
1353
- }
1354
- function providerToRecord(provider) {
1355
- if (isValueProvider(provider)) {
1356
- return makeRecord(undefined, provider.useValue);
1357
- }
1358
- else {
1359
- const factory = providerToFactory(provider);
1360
- return makeRecord(factory, NOT_YET);
1361
- }
1362
- }
1363
- /**
1364
- * Converts a `SingleProvider` into a factory function.
1365
- *
1366
- * @param provider provider to convert to factory
1367
- */
1368
- function providerToFactory(provider, ngModuleType, providers) {
1369
- let factory = undefined;
1370
- if (isTypeProvider(provider)) {
1371
- const unwrappedProvider = resolveForwardRef(provider);
1372
- return (getFactoryDef(unwrappedProvider) ||
1373
- injectableDefOrInjectorDefFactory(unwrappedProvider));
1374
- }
1375
- else {
1376
- if (isValueProvider(provider)) {
1377
- factory = () => resolveForwardRef(provider.useValue);
1378
- }
1379
- else if (isFactoryProvider(provider)) {
1380
- factory = () => provider.useFactory(...injectArgs(provider.deps || []));
1381
- }
1382
- else if (isExistingProvider(provider)) {
1383
- factory = () => ɵɵinject(resolveForwardRef(provider.useExisting));
1384
- }
1385
- else {
1386
- const classRef = resolveForwardRef(provider &&
1387
- (provider.useClass ||
1388
- provider.provide));
1389
- if (hasDeps(provider)) {
1390
- factory = () => new classRef(...injectArgs(provider.deps));
1391
- }
1392
- else {
1393
- return (getFactoryDef(classRef) || injectableDefOrInjectorDefFactory(classRef));
1394
- }
1395
- }
1396
- }
1397
- return factory;
1398
- }
1399
- function makeRecord(factory, value, multi = false) {
1400
- return {
1401
- factory: factory,
1402
- value: value,
1403
- multi: multi ? [] : undefined,
1404
- };
1405
- }
1406
- function hasDeps(value) {
1407
- return !!value.deps;
1408
- }
1409
- function hasOnDestroy(value) {
1410
- return (value !== null &&
1411
- typeof value === 'object' &&
1412
- typeof value.ngOnDestroy === 'function');
1413
- }
1414
- function couldBeInjectableType(value) {
1415
- return (typeof value === 'function' ||
1416
- (typeof value === 'object' && value instanceof InjectionToken));
1417
- }
1418
- function forEachSingleProvider(providers, fn) {
1419
- for (const provider of providers) {
1420
- if (Array.isArray(provider)) {
1421
- forEachSingleProvider(provider, fn);
1422
- }
1423
- else if (provider && isEnvironmentProviders(provider)) {
1424
- forEachSingleProvider(provider.ɵproviders, fn);
1425
- }
1426
- else {
1427
- fn(provider);
1428
- }
1429
- }
1430
- }
1431
-
1432
- /**
1433
- * @license
1434
- * Copyright Google LLC All Rights Reserved.
1435
- *
1436
- * Use of this source code is governed by an MIT-style license that can be
1437
- * found in the LICENSE file at https://angular.io/license
1438
- */
1439
- /**
1440
- * Create a new `Injector` which is configured using a `defType` of `InjectorType<any>`s.
1441
- */
1442
- function createInjector(defType, parent = null, additionalProviders = null, name) {
1443
- const injector = createInjectorWithoutInjectorInstances(defType, parent, additionalProviders, name);
1444
- injector.resolveInjectorInitializers();
1445
- return injector;
1446
- }
1447
- /**
1448
- * Creates a new injector without eagerly resolving its injector types. Can be used in places
1449
- * where resolving the injector types immediately can lead to an infinite loop. The injector types
1450
- * should be resolved at a later point by calling `_resolveInjectorDefTypes`.
1451
- */
1452
- function createInjectorWithoutInjectorInstances(defType, parent = null, additionalProviders = null, name, scopes = new Set()) {
1453
- const providers = [
1454
- additionalProviders || EMPTY_ARRAY,
1455
- importProvidersFrom(defType),
1456
- ];
1457
- name = name || (typeof defType === 'object' ? undefined : stringify(defType));
1458
- return new R3Injector(providers, parent || getNullInjector(), name || null, scopes);
1459
- }
1460
-
1461
- /**
1462
- * @license
1463
- * Copyright Google LLC All Rights Reserved.
1464
- *
1465
- * Use of this source code is governed by an MIT-style license that can be
1466
- * found in the LICENSE file at https://angular.io/license
1467
- */
1468
- /**
1469
- * Concrete injectors implement this interface. Injectors are configured
1470
- * with [providers](guide/dependency-injection-providers) that associate
1471
- * dependencies of various types with [injection tokens](guide/dependency-injection-providers).
1472
- *
1473
- * @see [DI Providers](guide/dependency-injection-providers).
1474
- * @see {@link StaticProvider}
1475
- *
1476
- * @usageNotes
1477
- *
1478
- * The following example creates a service injector instance.
1479
- *
1480
- * {@example core/di/ts/provider_spec.ts region='ConstructorProvider'}
1481
- *
1482
- * ### Usage example
1483
- *
1484
- * {@example core/di/ts/injector_spec.ts region='Injector'}
1485
- *
1486
- * `Injector` returns itself when given `Injector` as a token:
1487
- *
1488
- * {@example core/di/ts/injector_spec.ts region='injectInjector'}
1489
- *
1490
- * @publicApi
1491
- */
1492
- class Injector {
1493
- static THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
1494
- static NULL = new NullInjector();
1495
- static create(options, parent) {
1496
- if (Array.isArray(options)) {
1497
- return createInjector({ name: '' }, parent, options, '');
1498
- }
1499
- else {
1500
- const name = options.name ?? '';
1501
- return createInjector({ name }, options.parent, options.providers, name);
1502
- }
1503
- }
1504
- /** @nocollapse */
1505
- static ɵprov = /** @pureOrBreakMyCode */ ɵɵdefineInjectable({
1506
- token: Injector,
1507
- providedIn: 'any',
1508
- factory: () => ɵɵinject(INJECTOR),
1509
- });
1510
- /**
1511
- * @internal
1512
- * @nocollapse
1513
- */
1514
- static __NG_ELEMENT_ID__ = -1 /* InjectorMarkers.Injector */;
1515
- }
1516
-
1517
- /**
1518
- * @license
1519
- * Copyright Google LLC All Rights Reserved.
1520
- *
1521
- * Use of this source code is governed by an MIT-style license that can be
1522
- * found in the LICENSE file at https://angular.io/license
1523
- */
1524
- /**
1525
- * Throws an error indicating that a factory function could not be generated by the compiler for a
1526
- * particular class.
1527
- *
1528
- * This instruction allows the actual error message to be optimized away when ngDevMode is turned
1529
- * off, saving bytes of generated code while still providing a good experience in dev mode.
1530
- *
1531
- * The name of the class is not mentioned here, but will be in the generated factory function name
1532
- * and thus in the stack trace.
1533
- *
1534
- * @codeGenApi
1535
- */
1536
- function ɵɵinvalidFactory() {
1537
- const msg = 'invalid';
1538
- throw new Error(msg);
1539
- }
1540
-
1541
- exports.EnvironmentInjector = EnvironmentInjector;
1542
- exports.INJECTOR_SCOPE = INJECTOR_SCOPE;
1543
- exports.Inject = Inject;
1544
- exports.InjectionToken = InjectionToken;
1545
- exports.Injector = Injector;
1546
- exports.NG_INJ_DEF = NG_INJ_DEF;
1547
- exports.NG_PROV_DEF = NG_PROV_DEF;
1548
- exports.NG_TEMP_TOKEN_PATH = NG_TEMP_TOKEN_PATH;
1549
- exports.NullInjector = NullInjector;
1550
- exports.Optional = Optional;
1551
- exports.R3Injector = R3Injector;
1552
- exports.SOURCE = SOURCE;
1553
- exports.Self = Self;
1554
- exports.SkipSelf = SkipSelf;
1555
- exports.THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
1556
- exports.attachInjectFlag = attachInjectFlag;
1557
- exports.catchInjectorError = catchInjectorError;
1558
- exports.convertToBitFlags = convertToBitFlags;
1559
- exports.formatError = formatError;
1560
- exports.getCurrentInjector = getCurrentInjector;
1561
- exports.getInheritedInjectableDef = getInheritedInjectableDef;
1562
- exports.getInjectFlag = getInjectFlag;
1563
- exports.getInjectableDef = getInjectableDef;
1564
- exports.getInjectorDef = getInjectorDef;
1565
- exports.getNullInjector = getNullInjector;
1566
- exports.inject = inject;
1567
- exports.injectArgs = injectArgs;
1568
- exports.injectInjectorOnly = injectInjectorOnly;
1569
- exports.isInjectable = isInjectable;
1570
- exports.providerToFactory = providerToFactory;
1571
- exports.setCurrentInjector = setCurrentInjector;
1572
- exports.ɵɵdefineInjectable = ɵɵdefineInjectable;
1573
- exports.ɵɵdefineInjector = ɵɵdefineInjector;
1574
- exports.ɵɵinject = ɵɵinject;
1575
- exports.ɵɵinvalidFactory = ɵɵinvalidFactory;
1576
- exports.ɵɵinvalidFactoryDep = ɵɵinvalidFactoryDep;