static-injector 2.1.0 → 2.1.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.
Files changed (44) hide show
  1. package/import/commonjs/index.js +419 -157
  2. package/import/es2015/di/create_injector.js +5 -1
  3. package/import/es2015/di/forward_ref.js +3 -3
  4. package/import/es2015/di/injection_token.js +18 -11
  5. package/import/es2015/di/injector_compatibility.js +19 -10
  6. package/import/es2015/di/injector_token.js +3 -3
  7. package/import/es2015/di/interface/defs.js +21 -12
  8. package/import/es2015/di/interface/provider.js +3 -1
  9. package/import/es2015/di/null_injector.js +3 -3
  10. package/import/es2015/di/provider_collection.js +196 -1
  11. package/import/es2015/di/r3_injector.js +25 -22
  12. package/import/es2015/error_details_base_url.js +19 -0
  13. package/import/es2015/errors.js +42 -0
  14. package/import/es2015/interface/type.js +14 -1
  15. package/import/es2015/render3/definition_factory.js +2 -3
  16. package/import/es2015/render3/errors_di.js +2 -3
  17. package/import/es2015/render3/instructions/di.js +0 -7
  18. package/import/es2015/render3/util/stringify_utils.js +5 -5
  19. package/import/es2015/util/array_utils.js +0 -7
  20. package/import/es2015/util/decorators.js +24 -1
  21. package/import/es2015/util/empty.js +4 -0
  22. package/import/es2015/util/stringify.js +5 -5
  23. package/import/fesm2015/index.js +416 -155
  24. package/import/typings/di/forward_ref.d.ts +1 -1
  25. package/import/typings/di/injectable.d.ts +4 -3
  26. package/import/typings/di/injection_token.d.ts +21 -6
  27. package/import/typings/di/injector.d.ts +16 -0
  28. package/import/typings/di/injector_compatibility.d.ts +11 -5
  29. package/import/typings/di/injector_token.d.ts +2 -2
  30. package/import/typings/di/interface/defs.d.ts +15 -8
  31. package/import/typings/di/interface/provider.d.ts +60 -0
  32. package/import/typings/di/null_injector.d.ts +1 -1
  33. package/import/typings/di/provider_collection.d.ts +54 -1
  34. package/import/typings/di/provider_token.d.ts +2 -2
  35. package/import/typings/di/r3_injector.d.ts +3 -8
  36. package/import/typings/error_details_base_url.d.ts +19 -0
  37. package/import/typings/errors.d.ts +89 -0
  38. package/import/typings/interface/type.d.ts +45 -0
  39. package/import/typings/render3/errors_di.d.ts +7 -0
  40. package/import/typings/render3/instructions/di.d.ts +0 -7
  41. package/import/typings/util/array_utils.d.ts +15 -7
  42. package/import/typings/util/decorators.d.ts +2 -1
  43. package/import/typings/util/empty.d.ts +1 -0
  44. package/package.json +1 -1
@@ -40,6 +40,7 @@ function noSideEffects(fn) {
40
40
  * Use of this source code is governed by an MIT-style license that can be
41
41
  * found in the LICENSE file at https://angular.io/license
42
42
  */
43
+ const PARAMETERS = '__parameters__';
43
44
  function makeMetadataCtor(props) {
44
45
  return function ctor(...args) {
45
46
  if (props) {
@@ -50,7 +51,7 @@ function makeMetadataCtor(props) {
50
51
  }
51
52
  };
52
53
  }
53
- function makeParamDecorator(name, props) {
54
+ function makeParamDecorator(name, props, parentClass) {
54
55
  return noSideEffects(() => {
55
56
  const metaCtor = makeMetadataCtor(props);
56
57
  function ParamDecoratorFactory(...args) {
@@ -58,7 +59,29 @@ function makeParamDecorator(name, props) {
58
59
  metaCtor.apply(this, args);
59
60
  return this;
60
61
  }
62
+ const annotationInstance = new ParamDecoratorFactory(...args);
63
+ ParamDecorator.annotation = annotationInstance;
64
+ return ParamDecorator;
65
+ function ParamDecorator(cls, unusedKey, index) {
66
+ // Use of Object.defineProperty is important since it creates non-enumerable property which
67
+ // prevents the property is copied during subclassing.
68
+ const parameters = cls.hasOwnProperty(PARAMETERS)
69
+ ? cls[PARAMETERS]
70
+ : Object.defineProperty(cls, PARAMETERS, { value: [] })[PARAMETERS];
71
+ // there might be gaps if some in between parameters do not have annotations.
72
+ // we pad with nulls.
73
+ while (parameters.length <= index) {
74
+ parameters.push(null);
75
+ }
76
+ (parameters[index] = parameters[index] || []).push(annotationInstance);
77
+ return cls;
78
+ }
61
79
  }
80
+ if (parentClass) {
81
+ ParamDecoratorFactory.prototype = Object.create(parentClass.prototype);
82
+ }
83
+ ParamDecoratorFactory.prototype.ngMetadataName = name;
84
+ ParamDecoratorFactory.annotationCls = ParamDecoratorFactory;
62
85
  return ParamDecoratorFactory;
63
86
  });
64
87
  }
@@ -70,13 +93,40 @@ function makeParamDecorator(name, props) {
70
93
  * Use of this source code is governed by an MIT-style license that can be
71
94
  * found in the LICENSE file at https://angular.io/license
72
95
  */
73
- function getClosureSafeProperty(objWithPropertyToExtract) {
74
- for (let key in objWithPropertyToExtract) {
75
- if (objWithPropertyToExtract[key] === getClosureSafeProperty) {
76
- return key;
77
- }
96
+ /**
97
+ * Class that represents a runtime error.
98
+ * Formats and outputs the error message in a consistent way.
99
+ *
100
+ * Example:
101
+ * ```
102
+ * throw new RuntimeError(
103
+ * RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
104
+ * ngDevMode && 'Injector has already been destroyed.');
105
+ * ```
106
+ *
107
+ * Note: the `message` argument contains a descriptive error message as a string in development
108
+ * mode (when the `ngDevMode` is defined). In production mode (after tree-shaking pass), the
109
+ * `message` argument becomes `false`, thus we account for it in the typings and the runtime logic.
110
+ */
111
+ class RuntimeError extends Error {
112
+ constructor(code, message) {
113
+ super(formatRuntimeError(code, message));
114
+ this.code = code;
78
115
  }
79
- throw Error('Could not find renamed property on target object.');
116
+ }
117
+ /**
118
+ * Called to format a runtime error.
119
+ * See additional info on the `message` argument type in the `RuntimeError` class description.
120
+ */
121
+ function formatRuntimeError(code, message) {
122
+ // Error code might be a negative number, which is a special marker that instructs the logic to
123
+ // generate a link to the error details page on angular.io.
124
+ // We also prepend `0` to non-compile-time errors.
125
+ const fullCode = `NG0${Math.abs(code)}`;
126
+ let errorMessage = `${fullCode}${message ? ': ' + message.trim() : ''}`;
127
+ if (false) {
128
+ }
129
+ return errorMessage;
80
130
  }
81
131
 
82
132
  /**
@@ -87,14 +137,14 @@ function getClosureSafeProperty(objWithPropertyToExtract) {
87
137
  * found in the LICENSE file at https://angular.io/license
88
138
  */
89
139
  function stringify(token) {
90
- if (typeof token === "string") {
140
+ if (typeof token === 'string') {
91
141
  return token;
92
142
  }
93
143
  if (Array.isArray(token)) {
94
- return "[" + token.map(stringify).join(", ") + "]";
144
+ return '[' + token.map(stringify).join(', ') + ']';
95
145
  }
96
146
  if (token == null) {
97
- return "" + token;
147
+ return '' + token;
98
148
  }
99
149
  if (token.overriddenName) {
100
150
  return `${token.overriddenName}`;
@@ -104,12 +154,28 @@ function stringify(token) {
104
154
  }
105
155
  const res = token.toString();
106
156
  if (res == null) {
107
- return "" + res;
157
+ return '' + res;
108
158
  }
109
- const newLineIndex = res.indexOf("\n");
159
+ const newLineIndex = res.indexOf('\n');
110
160
  return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
111
161
  }
112
162
 
163
+ /**
164
+ * @license
165
+ * Copyright Google LLC All Rights Reserved.
166
+ *
167
+ * Use of this source code is governed by an MIT-style license that can be
168
+ * found in the LICENSE file at https://angular.io/license
169
+ */
170
+ function getClosureSafeProperty(objWithPropertyToExtract) {
171
+ for (let key in objWithPropertyToExtract) {
172
+ if (objWithPropertyToExtract[key] === getClosureSafeProperty) {
173
+ return key;
174
+ }
175
+ }
176
+ throw Error('Could not find renamed property on target object.');
177
+ }
178
+
113
179
  /**
114
180
  * @license
115
181
  * Copyright Google LLC All Rights Reserved.
@@ -157,79 +223,11 @@ function resolveForwardRef(type) {
157
223
  }
158
224
  /** Checks whether a function is wrapped by a `forwardRef`. */
159
225
  function isForwardRef(fn) {
160
- return (typeof fn === "function" &&
226
+ return (typeof fn === 'function' &&
161
227
  fn.hasOwnProperty(__forward_ref__) &&
162
228
  fn.__forward_ref__ === forwardRef);
163
229
  }
164
230
 
165
- /**
166
- * @license
167
- * Copyright Google LLC All Rights Reserved.
168
- *
169
- * Use of this source code is governed by an MIT-style license that can be
170
- * found in the LICENSE file at https://angular.io/license
171
- */
172
- class RuntimeError extends Error {
173
- constructor(code, message) {
174
- super(formatRuntimeError(code, message));
175
- this.code = code;
176
- }
177
- }
178
- /* tslint:enable:no-toplevel-property-access */
179
- /** Called to format a runtime error */
180
- function formatRuntimeError(code, message) {
181
- const fullCode = code ? `NG0${code}: ` : '';
182
- let errorMessage = `${fullCode}${message}`;
183
- // Some runtime errors are still thrown without `ngDevMode` (for example
184
- // `throwProviderNotFoundError`), so we add `ngDevMode` check here to avoid pulling
185
- // `RUNTIME_ERRORS_WITH_GUIDES` symbol into prod bundles.
186
- // TODO: revisit all instances where `RuntimeError` is thrown and see if `ngDevMode` can be added
187
- // there instead to tree-shake more devmode-only code (and eventually remove `ngDevMode` check
188
- // from this code).
189
- // if (ngDevMode && RUNTIME_ERRORS_WITH_GUIDES.has(code)) {
190
- // errorMessage = `${errorMessage}. Find more at ${ERROR_DETAILS_PAGE_BASE_URL}/NG0${code}`;
191
- // }
192
- return errorMessage;
193
- }
194
-
195
- /**
196
- * @license
197
- * Copyright Google LLC All Rights Reserved.
198
- *
199
- * Use of this source code is governed by an MIT-style license that can be
200
- * found in the LICENSE file at https://angular.io/license
201
- */
202
- /**
203
- * Used for stringify render output in Ivy.
204
- * Important! This function is very performance-sensitive and we should
205
- * be extra careful not to introduce megamorphic reads in it.
206
- * Check `core/test/render3/perf/render_stringify` for benchmarks and alternate implementations.
207
- */
208
- function renderStringify(value) {
209
- if (typeof value === "string")
210
- return value;
211
- if (value == null)
212
- return "";
213
- // Use `String` so that it invokes the `toString` method of the value. Note that this
214
- // appears to be faster than calling `value.toString` (see `render_stringify` benchmark).
215
- return String(value);
216
- }
217
- /**
218
- * Used to stringify a value so that it can be displayed in an error message.
219
- * Important! This function contains a megamorphic read and should only be
220
- * used for error messages.
221
- */
222
- function stringifyForError(value) {
223
- if (typeof value === "function")
224
- return value.name || value.toString();
225
- if (typeof value === "object" &&
226
- value != null &&
227
- typeof value.type === "function") {
228
- return value.type.name || value.type.toString();
229
- }
230
- return renderStringify(value);
231
- }
232
-
233
231
  /**
234
232
  * @license
235
233
  * Copyright Google LLC All Rights Reserved.
@@ -240,7 +238,7 @@ function stringifyForError(value) {
240
238
  /** Throws an error when a token is not found in DI. */
241
239
  function throwProviderNotFoundError(token, injectorName) {
242
240
  const injectorDetails = injectorName ? ` in ${injectorName}` : '';
243
- throw new RuntimeError("201" /* RuntimeErrorCode.PROVIDER_NOT_FOUND */, `No provider for ${stringifyForError(token)} found${injectorDetails}`);
241
+ throw new RuntimeError(-201 /* RuntimeErrorCode.PROVIDER_NOT_FOUND */, null);
244
242
  }
245
243
 
246
244
  /**
@@ -302,7 +300,10 @@ function ɵɵdefineInjector(options) {
302
300
  * @param type A type which may have its own (non-inherited) `ɵprov`.
303
301
  */
304
302
  function getInjectableDef(type) {
305
- return getOwnDefinition(type, NG_PROV_DEF);
303
+ return getOwnDefinition(type, NG_PROV_DEF) || null;
304
+ }
305
+ function isInjectable(type) {
306
+ return getInjectableDef(type) !== null;
306
307
  }
307
308
  /**
308
309
  * Return definition only if it is defined directly on `type` and is not inherited from a base
@@ -311,9 +312,6 @@ function getInjectableDef(type) {
311
312
  function getOwnDefinition(type, field) {
312
313
  return type.hasOwnProperty(field) ? type[field] : null;
313
314
  }
314
- const NG_PROV_DEF = getClosureSafeProperty({
315
- ɵprov: getClosureSafeProperty,
316
- });
317
315
  /**
318
316
  * Read the injectable def (`ɵprov`) for `type` or read the `ɵprov` from one of its ancestors.
319
317
  *
@@ -323,22 +321,15 @@ const NG_PROV_DEF = getClosureSafeProperty({
323
321
  * scenario if we find the `ɵprov` on an ancestor only.
324
322
  */
325
323
  function getInheritedInjectableDef(type) {
326
- const def = type && (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF]);
324
+ const def = type && (type[NG_PROV_DEF] || null);
327
325
  if (def) {
328
326
  const typeName = getTypeName(type);
329
- // TODO(FW-1307): Re-add ngDevMode when closure can handle it
330
- // ngDevMode &&
331
- console.warn(`DEPRECATED: DI is instantiating a token "${typeName}" that inherits its @Injectable decorator but does not provide one itself.\n` +
332
- `This will become an error in a future version of Angular. Please add @Injectable() to the "${typeName}" class.`);
333
327
  return def;
334
328
  }
335
329
  else {
336
330
  return null;
337
331
  }
338
332
  }
339
- const NG_INJECTABLE_DEF = getClosureSafeProperty({
340
- ngInjectableDef: getClosureSafeProperty,
341
- });
342
333
  /** Gets the name of a type, accounting for some cross-browser differences. */
343
334
  function getTypeName(type) {
344
335
  // `Function.prototype.name` behaves differently between IE and other browsers. In most browsers
@@ -353,6 +344,22 @@ function getTypeName(type) {
353
344
  const match = ('' + type).match(/^function\s*([^\s(]+)/);
354
345
  return match === null ? '' : match[1];
355
346
  }
347
+ /**
348
+ * Read the injector def type in a way which is immune to accidentally reading inherited value.
349
+ *
350
+ * @param type type which may have an injector def (`ɵinj`)
351
+ */
352
+ function getInjectorDef(type) {
353
+ return type && (type.hasOwnProperty(NG_INJ_DEF) || false)
354
+ ? type[NG_INJ_DEF]
355
+ : null;
356
+ }
357
+ const NG_PROV_DEF = getClosureSafeProperty({
358
+ ɵprov: getClosureSafeProperty,
359
+ });
360
+ const NG_INJ_DEF = getClosureSafeProperty({
361
+ ɵinj: getClosureSafeProperty,
362
+ });
356
363
 
357
364
  /**
358
365
  * @license
@@ -450,10 +457,6 @@ const NG_TOKEN_PATH = 'ngTokenPath';
450
457
  const NEW_LINE = /\n/gm;
451
458
  const NO_NEW_LINE = 'ɵ';
452
459
  const SOURCE = '__source';
453
- const USE_VALUE = getClosureSafeProperty({
454
- provide: String,
455
- useValue: getClosureSafeProperty,
456
- });
457
460
  /**
458
461
  * Current injector value used by `inject`.
459
462
  * - `undefined`: it is an error to call `inject`
@@ -468,7 +471,7 @@ function setCurrentInjector(injector) {
468
471
  }
469
472
  function injectInjectorOnly(token, flags = InjectFlags.Default) {
470
473
  if (_currentInjector === undefined) {
471
- throw new Error(`inject() must be called from an injection context`);
474
+ throw new RuntimeError(-203 /* RuntimeErrorCode.MISSING_INJECTION_CONTEXT */, null);
472
475
  }
473
476
  else if (_currentInjector === null) {
474
477
  return injectRootLimpMode(token, undefined, flags);
@@ -478,7 +481,19 @@ function injectInjectorOnly(token, flags = InjectFlags.Default) {
478
481
  }
479
482
  }
480
483
  function ɵɵinject(token, flags = InjectFlags.Default) {
481
- return injectInjectorOnly(resolveForwardRef(token), flags);
484
+ return (getInjectImplementation() || injectInjectorOnly)(resolveForwardRef(token), flags);
485
+ }
486
+ /**
487
+ * Throws an error indicating that a factory function could not be generated by the compiler for a
488
+ * particular class.
489
+ *
490
+ * The name of the class is not mentioned here, but will be in the generated factory function name
491
+ * and thus in the stack trace.
492
+ *
493
+ * @codeGenApi
494
+ */
495
+ function ɵɵinvalidFactoryDep(index) {
496
+ throw new RuntimeError(202 /* RuntimeErrorCode.INVALID_FACTORY_DEPENDENCY */, null);
482
497
  }
483
498
  /**
484
499
  * Injects a token from the currently active injector.
@@ -493,7 +508,7 @@ function ɵɵinject(token, flags = InjectFlags.Default) {
493
508
  * @param token A token that represents a dependency that should be injected.
494
509
  * @param flags Optional flags that control how injection is executed.
495
510
  * The flags correspond to injection strategies that can be specified with
496
- * parameter decorators `@Host`, `@Self`, `@SkipSef`, and `@Optional`.
511
+ * parameter decorators `@Host`, `@Self`, `@SkipSelf`, and `@Optional`.
497
512
  * @returns the injected value if operation is successful, `null` otherwise.
498
513
  * @throws if called outside of a supported context.
499
514
  *
@@ -557,6 +572,7 @@ function convertToBitFlags(flags) {
557
572
  // `InjectOptions` to `InjectFlags`.
558
573
  return (0 /* InternalInjectFlags.Default */ | // comment to force a line break in the formatter
559
574
  (flags.optional && 8 /* InternalInjectFlags.Optional */) |
575
+ 0 |
560
576
  (flags.self && 2 /* InternalInjectFlags.Self */) |
561
577
  (flags.skipSelf &&
562
578
  4 /* InternalInjectFlags.SkipSelf */));
@@ -567,7 +583,7 @@ function injectArgs(types) {
567
583
  const arg = resolveForwardRef(types[i]);
568
584
  if (Array.isArray(arg)) {
569
585
  if (arg.length === 0) {
570
- throw new Error('Arguments array must have arguments.');
586
+ throw new RuntimeError(900 /* RuntimeErrorCode.INVALID_DIFFER_INPUT */, null);
571
587
  }
572
588
  let type = undefined;
573
589
  let flags = InjectFlags.Default;
@@ -722,19 +738,11 @@ const NG_FACTORY_DEF = getClosureSafeProperty({
722
738
  */
723
739
  function getFactoryDef(type, throwNotFound) {
724
740
  const hasFactoryDef = type.hasOwnProperty(NG_FACTORY_DEF);
725
- // if (!hasFactoryDef && throwNotFound === true && ngDevMode) {
726
- // throw new Error(`Type ${stringify(type)} does not have 'ɵfac' property.`);
727
- // }
741
+ if (false) {
742
+ }
728
743
  return hasFactoryDef ? type[NG_FACTORY_DEF] : null;
729
744
  }
730
745
 
731
- /**
732
- * @license
733
- * Copyright Google LLC All Rights Reserved.
734
- *
735
- * Use of this source code is governed by an MIT-style license that can be
736
- * found in the LICENSE file at https://angular.io/license
737
- */
738
746
  function deepForEach(input, fn) {
739
747
  input.forEach((value) => Array.isArray(value) ? deepForEach(value, fn) : fn(value));
740
748
  }
@@ -759,7 +767,11 @@ function newArray(size, value) {
759
767
  * allows for identity checks against these values to be consistently used by the framework
760
768
  * code.
761
769
  */
770
+ const EMPTY_OBJ = {};
762
771
  const EMPTY_ARRAY = [];
772
+ // freezing the values prevents any code from accidentally inserting new values in
773
+ if (false) {
774
+ }
763
775
 
764
776
  /**
765
777
  * @license
@@ -776,11 +788,11 @@ const EMPTY_ARRAY = [];
776
788
  * parameterized type.
777
789
  *
778
790
  * `InjectionToken` is parameterized on `T` which is the type of object which will be returned by
779
- * the `Injector`. This provides additional level of type safety.
791
+ * the `Injector`. This provides an additional level of type safety.
780
792
  *
781
793
  * ```
782
794
  * interface MyInterface {...}
783
- * var myInterface = injector.get(new InjectionToken<MyInterface>('SomeToken'));
795
+ * const myInterface = injector.get(new InjectionToken<MyInterface>('SomeToken'));
784
796
  * // myInterface is inferred to be MyInterface.
785
797
  * ```
786
798
  *
@@ -788,14 +800,18 @@ const EMPTY_ARRAY = [];
788
800
  * (possibly by creating) a default value of the parameterized type `T`. This sets up the
789
801
  * `InjectionToken` using this factory as a provider as if it was defined explicitly in the
790
802
  * application's root injector. If the factory function, which takes zero arguments, needs to inject
791
- * dependencies, it can do so using the `inject` function. See below for an example.
803
+ * dependencies, it can do so using the `inject` function.
804
+ * As you can see in the Tree-shakable InjectionToken example below.
792
805
  *
793
806
  * Additionally, if a `factory` is specified you can also specify the `providedIn` option, which
794
- * overrides the above behavior and marks the token as belonging to a particular `@NgModule`. As
795
- * mentioned above, `'root'` is the default value for `providedIn`.
807
+ * overrides the above behavior and marks the token as belonging to a particular `@NgModule` (note:
808
+ * this option is now deprecated). As mentioned above, `'root'` is the default value for
809
+ * `providedIn`.
810
+ *
811
+ * The `providedIn: NgModule` and `providedIn: 'any'` options are deprecated.
796
812
  *
797
813
  * @usageNotes
798
- * ### Basic Example
814
+ * ### Basic Examples
799
815
  *
800
816
  * ### Plain InjectionToken
801
817
  *
@@ -809,15 +825,18 @@ const EMPTY_ARRAY = [];
809
825
  * @publicApi
810
826
  */
811
827
  class InjectionToken {
828
+ /**
829
+ * @param _desc Description for the token,
830
+ * used only for debugging purposes,
831
+ * it should but does not need to be unique
832
+ * @param options Options for the token's usage, as described above
833
+ */
812
834
  constructor(_desc, options) {
813
835
  this._desc = _desc;
836
+ /** @internal */
837
+ this.ngMetadataName = 'InjectionToken';
814
838
  this.ɵprov = undefined;
815
839
  if (typeof options == 'number') {
816
- // (typeof ngDevMode === "undefined" || ngDevMode) &&
817
- // assertLessThan(options, 0, "Only negative numbers are supported here");
818
- // // This is a special hack to assign __NG_ELEMENT_ID__ to this instance.
819
- // // See `InjectorMarkers`
820
- // (this as any).__NG_ELEMENT_ID__ = options;
821
840
  }
822
841
  else if (options !== undefined) {
823
842
  this.ɵprov = ɵɵdefineInjectable({
@@ -868,12 +887,23 @@ const ENVIRONMENT_INITIALIZER = new InjectionToken('ENVIRONMENT_INITIALIZER');
868
887
  *
869
888
  * @publicApi
870
889
  */
871
- const INJECTOR = new InjectionToken("INJECTOR",
872
- // Dissable tslint because this is const enum which gets inlined not top level prop access.
890
+ const INJECTOR = new InjectionToken('INJECTOR',
891
+ // Disable tslint because this is const enum which gets inlined not top level prop access.
873
892
  // tslint:disable-next-line: no-toplevel-property-access
874
893
  -1 /* InjectorMarkers.Injector */ // Special value used by Ivy to identify `Injector`.
875
894
  );
876
895
 
896
+ /**
897
+ * @license
898
+ * Copyright Google LLC All Rights Reserved.
899
+ *
900
+ * Use of this source code is governed by an MIT-style license that can be
901
+ * found in the LICENSE file at https://angular.io/license
902
+ */
903
+ function isEnvironmentProviders(value) {
904
+ return value && !!value.ɵproviders;
905
+ }
906
+
877
907
  /**
878
908
  * @license
879
909
  * Copyright Google LLC All Rights Reserved.
@@ -894,13 +924,248 @@ class NullInjector {
894
924
  get(token, notFoundValue = THROW_IF_NOT_FOUND) {
895
925
  if (notFoundValue === THROW_IF_NOT_FOUND) {
896
926
  const error = new Error(`NullInjectorError: No provider for ${stringify(token)}!`);
897
- error.name = "NullInjectorError";
927
+ error.name = 'NullInjectorError';
898
928
  throw error;
899
929
  }
900
930
  return notFoundValue;
901
931
  }
902
932
  }
903
933
 
934
+ /**
935
+ * @license
936
+ * Copyright Google LLC All Rights Reserved.
937
+ *
938
+ * Use of this source code is governed by an MIT-style license that can be
939
+ * found in the LICENSE file at https://angular.io/license
940
+ */
941
+ /**
942
+ * Wrap an array of `Provider`s into `EnvironmentProviders`, preventing them from being accidentally
943
+ * referenced in `@Component in a component injector.
944
+ */
945
+ function makeEnvironmentProviders(providers) {
946
+ return {
947
+ ɵproviders: providers,
948
+ };
949
+ }
950
+ /**
951
+ * Collects providers from all NgModules and standalone components, including transitively imported
952
+ * ones.
953
+ *
954
+ * Providers extracted via `importProvidersFrom` are only usable in an application injector or
955
+ * another environment injector (such as a route injector). They should not be used in component
956
+ * providers.
957
+ *
958
+ * More information about standalone components can be found in [this
959
+ * guide](guide/standalone-components).
960
+ *
961
+ * @usageNotes
962
+ * The results of the `importProvidersFrom` call can be used in the `bootstrapApplication` call:
963
+ *
964
+ * ```typescript
965
+ * await bootstrapApplication(RootComponent, {
966
+ * providers: [
967
+ * importProvidersFrom(NgModuleOne, NgModuleTwo)
968
+ * ]
969
+ * });
970
+ * ```
971
+ *
972
+ * You can also use the `importProvidersFrom` results in the `providers` field of a route, when a
973
+ * standalone component is used:
974
+ *
975
+ * ```typescript
976
+ * export const ROUTES: Route[] = [
977
+ * {
978
+ * path: 'foo',
979
+ * providers: [
980
+ * importProvidersFrom(NgModuleOne, NgModuleTwo)
981
+ * ],
982
+ * component: YourStandaloneComponent
983
+ * }
984
+ * ];
985
+ * ```
986
+ *
987
+ * @returns Collected providers from the specified list of types.
988
+ * @publicApi
989
+ */
990
+ function importProvidersFrom(...sources) {
991
+ return {
992
+ ɵproviders: internalImportProvidersFrom(true, sources),
993
+ ɵfromNgModule: true,
994
+ };
995
+ }
996
+ function internalImportProvidersFrom(checkForStandaloneCmp, ...sources) {
997
+ const providersOut = [];
998
+ const dedup = new Set(); // already seen types
999
+ let injectorTypesWithProviders;
1000
+ // Collect all providers from `ModuleWithProviders` types.
1001
+ if (injectorTypesWithProviders !== undefined) {
1002
+ processInjectorTypesWithProviders(injectorTypesWithProviders, providersOut);
1003
+ }
1004
+ return providersOut;
1005
+ }
1006
+ /**
1007
+ * Collects all providers from the list of `ModuleWithProviders` and appends them to the provided
1008
+ * array.
1009
+ */
1010
+ function processInjectorTypesWithProviders(typesWithProviders, providersOut) {
1011
+ for (let i = 0; i < typesWithProviders.length; i++) {
1012
+ const { ngModule, providers } = typesWithProviders[i];
1013
+ }
1014
+ }
1015
+ /**
1016
+ * The logic visits an `InjectorType`, an `InjectorTypeWithProviders`, or a standalone
1017
+ * `ComponentType`, and all of its transitive providers and collects providers.
1018
+ *
1019
+ * If an `InjectorTypeWithProviders` that declares providers besides the type is specified,
1020
+ * the function will return "true" to indicate that the providers of the type definition need
1021
+ * to be processed. This allows us to process providers of injector types after all imports of
1022
+ * an injector definition are processed. (following View Engine semantics: see FW-1349)
1023
+ */
1024
+ function walkProviderTree(container, providersOut, parents, dedup) {
1025
+ container = resolveForwardRef(container);
1026
+ if (!container)
1027
+ return false;
1028
+ // The actual type which had the definition. Usually `container`, but may be an unwrapped type
1029
+ // from `InjectorTypeWithProviders`.
1030
+ let defType = null;
1031
+ let injDef = getInjectorDef(container);
1032
+ const cmpDef = !injDef && null;
1033
+ if (!injDef && !cmpDef) {
1034
+ // `container` is not an injector type or a component type. It might be:
1035
+ // * An `InjectorTypeWithProviders` that wraps an injector type.
1036
+ // * A standalone directive or pipe that got pulled in from a standalone component's
1037
+ // dependencies.
1038
+ // Try to unwrap it as an `InjectorTypeWithProviders` first.
1039
+ const ngModule = container.ngModule;
1040
+ injDef = getInjectorDef(ngModule);
1041
+ if (injDef) {
1042
+ defType = ngModule;
1043
+ }
1044
+ else {
1045
+ // Not a component or injector type, so ignore it.
1046
+ return false;
1047
+ }
1048
+ }
1049
+ else if (cmpDef && !cmpDef.standalone) {
1050
+ return false;
1051
+ }
1052
+ else {
1053
+ defType = container;
1054
+ }
1055
+ // Check for circular dependencies.
1056
+ if (false) {
1057
+ }
1058
+ // Check for multiple imports of the same module
1059
+ const isDuplicate = dedup.has(defType);
1060
+ if (cmpDef) {
1061
+ if (isDuplicate) {
1062
+ // This component definition has already been processed.
1063
+ return false;
1064
+ }
1065
+ dedup.add(defType);
1066
+ if (cmpDef.dependencies) {
1067
+ const deps = typeof cmpDef.dependencies === 'function'
1068
+ ? cmpDef.dependencies()
1069
+ : cmpDef.dependencies;
1070
+ for (const dep of deps) {
1071
+ walkProviderTree(dep, providersOut, parents, dedup);
1072
+ }
1073
+ }
1074
+ }
1075
+ else if (injDef) {
1076
+ // First, include providers from any imports.
1077
+ if (injDef.imports != null && !isDuplicate) {
1078
+ // Before processing defType's imports, add it to the set of parents. This way, if it ends
1079
+ // up deeply importing itself, this can be detected.
1080
+ // Add it to the set of dedups. This way we can detect multiple imports of the same module
1081
+ dedup.add(defType);
1082
+ let importTypesWithProviders;
1083
+ try {
1084
+ deepForEach(injDef.imports, (imported) => {
1085
+ if (walkProviderTree(imported, providersOut, parents, dedup)) {
1086
+ importTypesWithProviders || (importTypesWithProviders = []);
1087
+ // If the processed import is an injector type with providers, we store it in the
1088
+ // list of import types with providers, so that we can process those afterwards.
1089
+ importTypesWithProviders.push(imported);
1090
+ }
1091
+ });
1092
+ }
1093
+ finally {
1094
+ // Remove it from the parents set when finished.
1095
+ }
1096
+ // Imports which are declared with providers (TypeWithProviders) need to be processed
1097
+ // after all imported modules are processed. This is similar to how View Engine
1098
+ // processes/merges module imports in the metadata resolver. See: FW-1349.
1099
+ if (importTypesWithProviders !== undefined) {
1100
+ processInjectorTypesWithProviders(importTypesWithProviders, providersOut);
1101
+ }
1102
+ }
1103
+ if (!isDuplicate) {
1104
+ // Track the InjectorType and add a provider for it.
1105
+ // It's important that this is done after the def's imports.
1106
+ const factory = getFactoryDef(defType) || (() => new defType());
1107
+ // Append extra providers to make more info available for consumers (to retrieve an injector
1108
+ // type), as well as internally (to calculate an injection scope correctly and eagerly
1109
+ // instantiate a `defType` when an injector is created).
1110
+ providersOut.push(
1111
+ // Provider to create `defType` using its factory.
1112
+ { provide: defType, useFactory: factory, deps: EMPTY_ARRAY },
1113
+ // Make this `defType` available to an internal logic that calculates injector scope.
1114
+ { provide: INJECTOR_DEF_TYPES, useValue: defType, multi: true },
1115
+ // Provider to eagerly instantiate `defType` via `ENVIRONMENT_INITIALIZER`.
1116
+ {
1117
+ provide: ENVIRONMENT_INITIALIZER,
1118
+ useValue: () => ɵɵinject(defType),
1119
+ multi: true,
1120
+ } //
1121
+ );
1122
+ }
1123
+ // Next, include providers listed on the definition itself.
1124
+ const defProviders = injDef.providers;
1125
+ if (defProviders != null && !isDuplicate) {
1126
+ const injectorType = container;
1127
+ }
1128
+ }
1129
+ else {
1130
+ // Should not happen, but just in case.
1131
+ return false;
1132
+ }
1133
+ return (defType !== container &&
1134
+ container.providers !== undefined);
1135
+ }
1136
+ function deepForEachProvider(providers, fn) {
1137
+ for (let provider of providers) {
1138
+ if (isEnvironmentProviders(provider)) {
1139
+ provider = provider.ɵproviders;
1140
+ }
1141
+ if (Array.isArray(provider)) {
1142
+ deepForEachProvider(provider, fn);
1143
+ }
1144
+ else {
1145
+ fn(provider);
1146
+ }
1147
+ }
1148
+ }
1149
+ const USE_VALUE = getClosureSafeProperty({
1150
+ provide: String,
1151
+ useValue: getClosureSafeProperty,
1152
+ });
1153
+ function isValueProvider(value) {
1154
+ return value !== null && typeof value == 'object' && USE_VALUE in value;
1155
+ }
1156
+ function isExistingProvider(value) {
1157
+ return !!(value && value.useExisting);
1158
+ }
1159
+ function isFactoryProvider(value) {
1160
+ return !!(value && value.useFactory);
1161
+ }
1162
+ function isTypeProvider(value) {
1163
+ return typeof value === 'function';
1164
+ }
1165
+ function isClassProvider(value) {
1166
+ return !!value.useClass;
1167
+ }
1168
+
904
1169
  /**
905
1170
  * @license
906
1171
  * Copyright Google LLC All Rights Reserved.
@@ -1105,6 +1370,8 @@ class R3Injector extends EnvironmentInjector {
1105
1370
  const previousInjectImplementation = setInjectImplementation(undefined);
1106
1371
  try {
1107
1372
  const initializers = this.get(ENVIRONMENT_INITIALIZER.multi, EMPTY_ARRAY, InjectFlags.Self);
1373
+ if (false) {
1374
+ }
1108
1375
  for (const initializer of initializers) {
1109
1376
  initializer();
1110
1377
  }
@@ -1124,7 +1391,7 @@ class R3Injector extends EnvironmentInjector {
1124
1391
  }
1125
1392
  assertNotDestroyed() {
1126
1393
  if (this._destroyed) {
1127
- throw new Error('Injector has already been destroyed.');
1394
+ throw new RuntimeError(205 /* RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED */, null);
1128
1395
  }
1129
1396
  }
1130
1397
  /**
@@ -1145,6 +1412,8 @@ class R3Injector extends EnvironmentInjector {
1145
1412
  let multiRecord = this.records.get(token);
1146
1413
  if (multiRecord) {
1147
1414
  // It has. Throw a nice error if
1415
+ if (false) {
1416
+ }
1148
1417
  }
1149
1418
  else {
1150
1419
  multiRecord = makeRecord(undefined, NOT_YET, true);
@@ -1156,11 +1425,15 @@ class R3Injector extends EnvironmentInjector {
1156
1425
  }
1157
1426
  else {
1158
1427
  const existing = this.records.get(token);
1428
+ if (false) {
1429
+ }
1159
1430
  }
1160
1431
  this.records.set(token, record);
1161
1432
  }
1162
1433
  hydrate(token, record) {
1163
- if (record.value === NOT_YET) {
1434
+ if (false) {
1435
+ }
1436
+ else if (record.value === NOT_YET) {
1164
1437
  record.value = CIRCULAR;
1165
1438
  record.value = record.factory();
1166
1439
  }
@@ -1194,21 +1467,21 @@ function injectableDefOrInjectorDefFactory(token) {
1194
1467
  // InjectionTokens should have an injectable def (ɵprov) and thus should be handled above.
1195
1468
  // If it's missing that, it's an error.
1196
1469
  if (token instanceof InjectionToken) {
1197
- throw new Error(`Token ${stringify(token)} is missing a ɵprov definition.`);
1470
+ throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
1198
1471
  }
1199
1472
  // Undecorated types can sometimes be created if they have no constructor arguments.
1200
1473
  if (token instanceof Function) {
1201
1474
  return getUndecoratedInjectableFactory(token);
1202
1475
  }
1203
1476
  // There was no way to resolve a factory for this token.
1204
- throw new Error('unreachable');
1477
+ throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
1205
1478
  }
1206
1479
  function getUndecoratedInjectableFactory(token) {
1207
1480
  // If the token has parameters then it has dependencies that we cannot resolve implicitly.
1208
1481
  const paramLength = token.length;
1209
1482
  if (paramLength > 0) {
1210
1483
  const args = newArray(paramLength, '?');
1211
- throw new Error(`Can't resolve all parameters for ${stringify(token)}: (${args.join(', ')}).`);
1484
+ throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
1212
1485
  }
1213
1486
  // The constructor function appears to have no parameters.
1214
1487
  // This might be because it inherits from a super-class. In which case, use an injectable
@@ -1239,6 +1512,8 @@ function providerToRecord(provider) {
1239
1512
  */
1240
1513
  function providerToFactory(provider, ngModuleType, providers) {
1241
1514
  let factory = undefined;
1515
+ if (false) {
1516
+ }
1242
1517
  if (isTypeProvider(provider)) {
1243
1518
  const unwrappedProvider = resolveForwardRef(provider);
1244
1519
  return (getFactoryDef(unwrappedProvider) ||
@@ -1258,9 +1533,8 @@ function providerToFactory(provider, ngModuleType, providers) {
1258
1533
  const classRef = resolveForwardRef(provider &&
1259
1534
  (provider.useClass ||
1260
1535
  provider.provide));
1261
- // if (ngDevMode && !classRef) {
1262
- // throwInvalidProviderError(ngModuleType, providers, provider);
1263
- // }
1536
+ if (false) {
1537
+ }
1264
1538
  if (hasDeps(provider)) {
1265
1539
  factory = () => new classRef(...injectArgs(provider.deps));
1266
1540
  }
@@ -1278,18 +1552,6 @@ function makeRecord(factory, value, multi = false) {
1278
1552
  multi: multi ? [] : undefined,
1279
1553
  };
1280
1554
  }
1281
- function isValueProvider(value) {
1282
- return value !== null && typeof value == 'object' && USE_VALUE in value;
1283
- }
1284
- function isExistingProvider(value) {
1285
- return !!(value && value.useExisting);
1286
- }
1287
- function isFactoryProvider(value) {
1288
- return !!(value && value.useFactory);
1289
- }
1290
- function isTypeProvider(value) {
1291
- return typeof value === 'function';
1292
- }
1293
1555
  function hasDeps(value) {
1294
1556
  return !!value.deps;
1295
1557
  }
@@ -1307,6 +1569,9 @@ function forEachSingleProvider(providers, fn) {
1307
1569
  if (Array.isArray(provider)) {
1308
1570
  forEachSingleProvider(provider, fn);
1309
1571
  }
1572
+ else if (provider && isEnvironmentProviders(provider)) {
1573
+ forEachSingleProvider(provider.ɵproviders, fn);
1574
+ }
1310
1575
  else {
1311
1576
  fn(provider);
1312
1577
  }
@@ -1336,7 +1601,10 @@ function createInjector(defType, parent = null, additionalProviders = null, name
1336
1601
  * should be resolved at a later point by calling `_resolveInjectorDefTypes`.
1337
1602
  */
1338
1603
  function createInjectorWithoutInjectorInstances(defType, parent = null, additionalProviders = null, name, scopes = new Set()) {
1339
- const providers = [additionalProviders || EMPTY_ARRAY];
1604
+ const providers = [
1605
+ additionalProviders || EMPTY_ARRAY,
1606
+ importProvidersFrom(defType),
1607
+ ];
1340
1608
  name = name || (typeof defType === 'object' ? undefined : stringify(defType));
1341
1609
  return new R3Injector(providers, parent || getNullInjector(), name || null, scopes);
1342
1610
  }
@@ -1398,13 +1666,6 @@ Injector.ɵprov = ɵɵdefineInjectable({
1398
1666
  */
1399
1667
  Injector.__NG_ELEMENT_ID__ = -1 /* InjectorMarkers.Injector */;
1400
1668
 
1401
- /**
1402
- * @license
1403
- * Copyright Google LLC All Rights Reserved.
1404
- *
1405
- * Use of this source code is governed by an MIT-style license that can be
1406
- * found in the LICENSE file at https://angular.io/license
1407
- */
1408
1669
  /**
1409
1670
  * Throws an error indicating that a factory function could not be generated by the compiler for a
1410
1671
  * particular class.
@@ -1468,4 +1729,4 @@ function getFactoryOf(type) {
1468
1729
  return getFactoryDef(type);
1469
1730
  }
1470
1731
 
1471
- export { EnvironmentInjector, INJECTOR_SCOPE, Inject, InjectFlags, Injectable, InjectionToken, Injector, NG_INJECTABLE_DEF, NG_PROV_DEF, NG_TEMP_TOKEN_PATH, NullInjector, Optional, R3Injector, SOURCE, Self, SkipSelf, THROW_IF_NOT_FOUND, USE_VALUE, attachInjectFlag, catchInjectorError, convertToBitFlags, formatError, getInheritedInjectableDef, getInjectFlag, getInjectableDef, getNullInjector, inject, injectArgs, injectInjectorOnly, isTypeProvider, providerToFactory, setCurrentInjector, ɵɵdefineInjectable, ɵɵdefineInjector, ɵɵgetInheritedFactory, ɵɵinject, ɵɵinvalidFactory };
1732
+ export { EnvironmentInjector, INJECTOR_SCOPE, Inject, InjectFlags, Injectable, InjectionToken, Injector, NG_INJ_DEF, NG_PROV_DEF, NG_TEMP_TOKEN_PATH, NullInjector, Optional, R3Injector, SOURCE, Self, SkipSelf, THROW_IF_NOT_FOUND, attachInjectFlag, catchInjectorError, convertToBitFlags, formatError, getInheritedInjectableDef, getInjectFlag, getInjectableDef, getInjectorDef, getNullInjector, inject, injectArgs, injectInjectorOnly, isInjectable, providerToFactory, setCurrentInjector, ɵɵdefineInjectable, ɵɵdefineInjector, ɵɵgetInheritedFactory, ɵɵinject, ɵɵinvalidFactory, ɵɵinvalidFactoryDep };