static-injector 1.0.8

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 (146) hide show
  1. package/import/commonjs/index.js +1248 -0
  2. package/import/es2015/decorator/injectable.js +14 -0
  3. package/import/es2015/decorator/interface/provider.js +8 -0
  4. package/import/es2015/di/forward_ref.js +53 -0
  5. package/import/es2015/di/inject_switch.js +31 -0
  6. package/import/es2015/di/injection_token.js +71 -0
  7. package/import/es2015/di/injector.js +63 -0
  8. package/import/es2015/di/injector_compatibility.js +172 -0
  9. package/import/es2015/di/injector_marker.js +8 -0
  10. package/import/es2015/di/injector_token.js +21 -0
  11. package/import/es2015/di/interface/defs.js +72 -0
  12. package/import/es2015/di/interface/injector.js +25 -0
  13. package/import/es2015/di/interface/provider.js +8 -0
  14. package/import/es2015/di/metadata.js +49 -0
  15. package/import/es2015/di/null_injector.js +19 -0
  16. package/import/es2015/di/provider_token.js +8 -0
  17. package/import/es2015/di/r3_injector.js +382 -0
  18. package/import/es2015/di/scope.js +14 -0
  19. package/import/es2015/index.js +11 -0
  20. package/import/es2015/interface/lifecycle_hooks.js +8 -0
  21. package/import/es2015/interface/type.js +8 -0
  22. package/import/es2015/render3/definition_factory.js +15 -0
  23. package/import/es2015/render3/error_code.js +29 -0
  24. package/import/es2015/render3/errors_di.js +14 -0
  25. package/import/es2015/render3/fields.js +11 -0
  26. package/import/es2015/render3/instructions/di.js +23 -0
  27. package/import/es2015/render3/util/stringify_utils.js +37 -0
  28. package/import/es2015/util/array_utils.js +17 -0
  29. package/import/es2015/util/closure.js +19 -0
  30. package/import/es2015/util/decorators.js +30 -0
  31. package/import/es2015/util/empty.js +14 -0
  32. package/import/es2015/util/property.js +15 -0
  33. package/import/es2015/util/stringify.js +30 -0
  34. package/import/fesm2015/index.js +1211 -0
  35. package/import/typings/decorator/injectable.d.ts +82 -0
  36. package/import/typings/decorator/interface/provider.d.ts +312 -0
  37. package/import/typings/di/forward_ref.d.ts +49 -0
  38. package/import/typings/di/inject_switch.d.ts +17 -0
  39. package/import/typings/di/injection_token.d.ts +57 -0
  40. package/import/typings/di/injector.d.ts +76 -0
  41. package/import/typings/di/injector_compatibility.d.ts +77 -0
  42. package/import/typings/di/injector_marker.d.ts +23 -0
  43. package/import/typings/di/injector_token.d.ts +18 -0
  44. package/import/typings/di/interface/defs.d.ts +155 -0
  45. package/import/typings/di/interface/injector.d.ts +48 -0
  46. package/import/typings/di/interface/provider.d.ts +312 -0
  47. package/import/typings/di/metadata.d.ts +176 -0
  48. package/import/typings/di/null_injector.d.ts +11 -0
  49. package/import/typings/di/provider_token.d.ts +17 -0
  50. package/import/typings/di/r3_injector.d.ts +92 -0
  51. package/import/typings/di/scope.d.ts +14 -0
  52. package/import/typings/index.d.ts +11 -0
  53. package/import/typings/interface/lifecycle_hooks.d.ts +28 -0
  54. package/import/typings/interface/type.d.ts +21 -0
  55. package/import/typings/render3/definition_factory.d.ts +24 -0
  56. package/import/typings/render3/error_code.d.ts +24 -0
  57. package/import/typings/render3/errors_di.d.ts +2 -0
  58. package/import/typings/render3/fields.d.ts +8 -0
  59. package/import/typings/render3/instructions/di.d.ts +20 -0
  60. package/import/typings/render3/util/stringify_utils.d.ts +20 -0
  61. package/import/typings/util/array_utils.d.ts +10 -0
  62. package/import/typings/util/closure.d.ts +17 -0
  63. package/import/typings/util/decorators.d.ts +27 -0
  64. package/import/typings/util/empty.d.ts +14 -0
  65. package/import/typings/util/property.d.ts +8 -0
  66. package/import/typings/util/stringify.d.ts +8 -0
  67. package/package.json +34 -0
  68. package/readme.md +27 -0
  69. package/transform/compiler/index.d.ts +5 -0
  70. package/transform/compiler/index.js +17 -0
  71. package/transform/compiler/src/core.d.ts +19 -0
  72. package/transform/compiler/src/core.js +9 -0
  73. package/transform/compiler/src/injectable_compiler_2.d.ts +53 -0
  74. package/transform/compiler/src/injectable_compiler_2.js +159 -0
  75. package/transform/compiler/src/output/output_ast.d.ts +534 -0
  76. package/transform/compiler/src/output/output_ast.js +986 -0
  77. package/transform/compiler/src/parse_util.d.ts +50 -0
  78. package/transform/compiler/src/parse_util.js +61 -0
  79. package/transform/compiler/src/render3/partial/api.d.ts +166 -0
  80. package/transform/compiler/src/render3/partial/api.js +11 -0
  81. package/transform/compiler/src/render3/partial/util.d.ts +16 -0
  82. package/transform/compiler/src/render3/partial/util.js +44 -0
  83. package/transform/compiler/src/render3/r3_factory.d.ts +97 -0
  84. package/transform/compiler/src/render3/r3_factory.js +239 -0
  85. package/transform/compiler/src/render3/r3_identifiers.d.ts +20 -0
  86. package/transform/compiler/src/render3/r3_identifiers.js +51 -0
  87. package/transform/compiler/src/render3/util.d.ts +21 -0
  88. package/transform/compiler/src/render3/util.js +41 -0
  89. package/transform/compiler/src/render3/view/util.d.ts +30 -0
  90. package/transform/compiler/src/render3/view/util.js +57 -0
  91. package/transform/compiler-cli/src/ngtsc/annotations/src/factory.d.ts +11 -0
  92. package/transform/compiler-cli/src/ngtsc/annotations/src/factory.js +21 -0
  93. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +42 -0
  94. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +278 -0
  95. package/transform/compiler-cli/src/ngtsc/annotations/src/util.d.ts +91 -0
  96. package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +370 -0
  97. package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +24 -0
  98. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +76 -0
  99. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.d.ts +188 -0
  100. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +206 -0
  101. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +2 -0
  102. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +14 -0
  103. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +1 -0
  104. package/transform/compiler-cli/src/ngtsc/imports/index.js +13 -0
  105. package/transform/compiler-cli/src/ngtsc/imports/src/core.d.ts +36 -0
  106. package/transform/compiler-cli/src/ngtsc/imports/src/core.js +25 -0
  107. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +3 -0
  108. package/transform/compiler-cli/src/ngtsc/reflection/index.js +15 -0
  109. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +667 -0
  110. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +98 -0
  111. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +24 -0
  112. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +271 -0
  113. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +50 -0
  114. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +396 -0
  115. package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +12 -0
  116. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +45 -0
  117. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +2 -0
  118. package/transform/compiler-cli/src/ngtsc/transform/index.js +14 -0
  119. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +115 -0
  120. package/transform/compiler-cli/src/ngtsc/transform/src/api.js +30 -0
  121. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +15 -0
  122. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +84 -0
  123. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +5 -0
  124. package/transform/compiler-cli/src/ngtsc/translator/index.js +17 -0
  125. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +274 -0
  126. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.js +9 -0
  127. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.d.ts +27 -0
  128. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.js +9 -0
  129. package/transform/compiler-cli/src/ngtsc/translator/src/context.d.ts +18 -0
  130. package/transform/compiler-cli/src/ngtsc/translator/src/context.js +27 -0
  131. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +29 -0
  132. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +70 -0
  133. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +58 -0
  134. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +270 -0
  135. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +54 -0
  136. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +245 -0
  137. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +13 -0
  138. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.js +21 -0
  139. package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +11 -0
  140. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +39 -0
  141. package/transform/index.d.ts +1 -0
  142. package/transform/index.js +13 -0
  143. package/transform/injectable-transform.d.ts +41 -0
  144. package/transform/injectable-transform.js +195 -0
  145. package/transform/node-Iteration.d.ts +2 -0
  146. package/transform/node-Iteration.js +12 -0
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { InjectionToken } from "./injection_token";
9
+ /**
10
+ * An internal token whose presence in an injector indicates that the injector should treat itself
11
+ * as a root scoped injector when processing requests for unknown tokens which may indicate
12
+ * they are provided in the root scope.
13
+ */
14
+ export const INJECTOR_SCOPE = new InjectionToken("Set Injector scope.");
@@ -0,0 +1,11 @@
1
+ export * from './decorator/injectable';
2
+ export * from './di/metadata';
3
+ export * from './di/r3_injector';
4
+ export * from './di/interface/defs';
5
+ export * from './di/injector_compatibility';
6
+ export * from './di/injection_token';
7
+ export * from './di/null_injector';
8
+ export * from './di/injector';
9
+ export * from './di/interface/injector';
10
+ export * from './di/scope';
11
+ export * from './render3/instructions/di';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { NG_FACTORY_DEF } from './fields';
9
+ export function getFactoryDef(type, throwNotFound) {
10
+ const hasFactoryDef = type.hasOwnProperty(NG_FACTORY_DEF);
11
+ // if (!hasFactoryDef && throwNotFound === true && ngDevMode) {
12
+ // throw new Error(`Type ${stringify(type)} does not have 'ɵfac' property.`);
13
+ // }
14
+ return hasFactoryDef ? type[NG_FACTORY_DEF] : null;
15
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export class RuntimeError extends Error {
9
+ constructor(code, message) {
10
+ super(formatRuntimeError(code, message));
11
+ this.code = code;
12
+ }
13
+ }
14
+ /* tslint:enable:no-toplevel-property-access */
15
+ /** Called to format a runtime error */
16
+ export function formatRuntimeError(code, message) {
17
+ const fullCode = code ? `NG0${code}: ` : '';
18
+ let errorMessage = `${fullCode}${message}`;
19
+ // Some runtime errors are still thrown without `ngDevMode` (for example
20
+ // `throwProviderNotFoundError`), so we add `ngDevMode` check here to avoid pulling
21
+ // `RUNTIME_ERRORS_WITH_GUIDES` symbol into prod bundles.
22
+ // TODO: revisit all instances where `RuntimeError` is thrown and see if `ngDevMode` can be added
23
+ // there instead to tree-shake more devmode-only code (and eventually remove `ngDevMode` check
24
+ // from this code).
25
+ // if (ngDevMode && RUNTIME_ERRORS_WITH_GUIDES.has(code)) {
26
+ // errorMessage = `${errorMessage}. Find more at ${ERROR_DETAILS_PAGE_BASE_URL}/NG0${code}`;
27
+ // }
28
+ return errorMessage;
29
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { RuntimeError } from './error_code';
9
+ import { stringifyForError } from './util/stringify_utils';
10
+ /** Throws an error when a token is not found in DI. */
11
+ export function throwProviderNotFoundError(token, injectorName) {
12
+ const injectorDetails = injectorName ? ` in ${injectorName}` : '';
13
+ throw new RuntimeError("201" /* PROVIDER_NOT_FOUND */, `No provider for ${stringifyForError(token)} found${injectorDetails}`);
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { getClosureSafeProperty } from '../util/property';
9
+ export const NG_FACTORY_DEF = getClosureSafeProperty({
10
+ ɵfac: getClosureSafeProperty,
11
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /**
9
+ * Throws an error indicating that a factory function could not be generated by the compiler for a
10
+ * particular class.
11
+ *
12
+ * This instruction allows the actual error message to be optimized away when ngDevMode is turned
13
+ * off, saving bytes of generated code while still providing a good experience in dev mode.
14
+ *
15
+ * The name of the class is not mentioned here, but will be in the generated factory function name
16
+ * and thus in the stack trace.
17
+ *
18
+ * @codeGenApi
19
+ */
20
+ export function ɵɵinvalidFactory() {
21
+ const msg = 'invalid';
22
+ throw new Error(msg);
23
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /**
9
+ * Used for stringify render output in Ivy.
10
+ * Important! This function is very performance-sensitive and we should
11
+ * be extra careful not to introduce megamorphic reads in it.
12
+ * Check `core/test/render3/perf/render_stringify` for benchmarks and alternate implementations.
13
+ */
14
+ export function renderStringify(value) {
15
+ if (typeof value === "string")
16
+ return value;
17
+ if (value == null)
18
+ return "";
19
+ // Use `String` so that it invokes the `toString` method of the value. Note that this
20
+ // appears to be faster than calling `value.toString` (see `render_stringify` benchmark).
21
+ return String(value);
22
+ }
23
+ /**
24
+ * Used to stringify a value so that it can be displayed in an error message.
25
+ * Important! This function contains a megamorphic read and should only be
26
+ * used for error messages.
27
+ */
28
+ export function stringifyForError(value) {
29
+ if (typeof value === "function")
30
+ return value.name || value.toString();
31
+ if (typeof value === "object" &&
32
+ value != null &&
33
+ typeof value.type === "function") {
34
+ return value.type.name || value.type.toString();
35
+ }
36
+ return renderStringify(value);
37
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export function deepForEach(input, fn) {
9
+ input.forEach((value) => Array.isArray(value) ? deepForEach(value, fn) : fn(value));
10
+ }
11
+ export function newArray(size, value) {
12
+ const list = [];
13
+ for (let i = 0; i < size; i++) {
14
+ list.push(value);
15
+ }
16
+ return list;
17
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /**
9
+ * Convince closure compiler that the wrapped function has no side-effects.
10
+ *
11
+ * Closure compiler always assumes that `toString` has no side-effects. We use this quirk to
12
+ * allow us to execute a function but have closure compiler mark the call as no-side-effects.
13
+ * It is important that the return value for the `noSideEffects` function be assigned
14
+ * to something which is retained otherwise the call to `noSideEffects` will be removed by closure
15
+ * compiler.
16
+ */
17
+ export function noSideEffects(fn) {
18
+ return { toString: fn }.toString();
19
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { noSideEffects } from './closure';
9
+ function makeMetadataCtor(props) {
10
+ return function ctor(...args) {
11
+ if (props) {
12
+ const values = props(...args);
13
+ for (const propName in values) {
14
+ this[propName] = values[propName];
15
+ }
16
+ }
17
+ };
18
+ }
19
+ export function makeParamDecorator(name, props) {
20
+ return noSideEffects(() => {
21
+ const metaCtor = makeMetadataCtor(props);
22
+ function ParamDecoratorFactory(...args) {
23
+ if (this instanceof ParamDecoratorFactory) {
24
+ metaCtor.apply(this, args);
25
+ return this;
26
+ }
27
+ }
28
+ return ParamDecoratorFactory;
29
+ });
30
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /**
9
+ * This file contains reuseable "empty" symbols that can be used as default return values
10
+ * in different parts of the rendering code. Because the same symbols are returned, this
11
+ * allows for identity checks against these values to be consistently used by the framework
12
+ * code.
13
+ */
14
+ export const EMPTY_ARRAY = [];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export function getClosureSafeProperty(objWithPropertyToExtract) {
9
+ for (let key in objWithPropertyToExtract) {
10
+ if (objWithPropertyToExtract[key] === getClosureSafeProperty) {
11
+ return key;
12
+ }
13
+ }
14
+ throw Error('Could not find renamed property on target object.');
15
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export function stringify(token) {
9
+ if (typeof token === "string") {
10
+ return token;
11
+ }
12
+ if (Array.isArray(token)) {
13
+ return "[" + token.map(stringify).join(", ") + "]";
14
+ }
15
+ if (token == null) {
16
+ return "" + token;
17
+ }
18
+ if (token.overriddenName) {
19
+ return `${token.overriddenName}`;
20
+ }
21
+ if (token.name) {
22
+ return `${token.name}`;
23
+ }
24
+ const res = token.toString();
25
+ if (res == null) {
26
+ return "" + res;
27
+ }
28
+ const newLineIndex = res.indexOf("\n");
29
+ return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
30
+ }
@@ -0,0 +1,1211 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /**
9
+ * Injectable decorator and metadata.
10
+ *
11
+ * @Annotation
12
+ * @publicApi
13
+ */
14
+ const Injectable = undefined;
15
+
16
+ /**
17
+ * @license
18
+ * Copyright Google LLC All Rights Reserved.
19
+ *
20
+ * Use of this source code is governed by an MIT-style license that can be
21
+ * found in the LICENSE file at https://angular.io/license
22
+ */
23
+ /**
24
+ * Convince closure compiler that the wrapped function has no side-effects.
25
+ *
26
+ * Closure compiler always assumes that `toString` has no side-effects. We use this quirk to
27
+ * allow us to execute a function but have closure compiler mark the call as no-side-effects.
28
+ * It is important that the return value for the `noSideEffects` function be assigned
29
+ * to something which is retained otherwise the call to `noSideEffects` will be removed by closure
30
+ * compiler.
31
+ */
32
+ function noSideEffects(fn) {
33
+ return { toString: fn }.toString();
34
+ }
35
+
36
+ /**
37
+ * @license
38
+ * Copyright Google LLC All Rights Reserved.
39
+ *
40
+ * Use of this source code is governed by an MIT-style license that can be
41
+ * found in the LICENSE file at https://angular.io/license
42
+ */
43
+ function makeMetadataCtor(props) {
44
+ return function ctor(...args) {
45
+ if (props) {
46
+ const values = props(...args);
47
+ for (const propName in values) {
48
+ this[propName] = values[propName];
49
+ }
50
+ }
51
+ };
52
+ }
53
+ function makeParamDecorator(name, props) {
54
+ return noSideEffects(() => {
55
+ const metaCtor = makeMetadataCtor(props);
56
+ function ParamDecoratorFactory(...args) {
57
+ if (this instanceof ParamDecoratorFactory) {
58
+ metaCtor.apply(this, args);
59
+ return this;
60
+ }
61
+ }
62
+ return ParamDecoratorFactory;
63
+ });
64
+ }
65
+
66
+ /**
67
+ * @license
68
+ * Copyright Google LLC All Rights Reserved.
69
+ *
70
+ * Use of this source code is governed by an MIT-style license that can be
71
+ * found in the LICENSE file at https://angular.io/license
72
+ */
73
+ function getClosureSafeProperty(objWithPropertyToExtract) {
74
+ for (let key in objWithPropertyToExtract) {
75
+ if (objWithPropertyToExtract[key] === getClosureSafeProperty) {
76
+ return key;
77
+ }
78
+ }
79
+ throw Error('Could not find renamed property on target object.');
80
+ }
81
+
82
+ /**
83
+ * @license
84
+ * Copyright Google LLC All Rights Reserved.
85
+ *
86
+ * Use of this source code is governed by an MIT-style license that can be
87
+ * found in the LICENSE file at https://angular.io/license
88
+ */
89
+ function stringify(token) {
90
+ if (typeof token === "string") {
91
+ return token;
92
+ }
93
+ if (Array.isArray(token)) {
94
+ return "[" + token.map(stringify).join(", ") + "]";
95
+ }
96
+ if (token == null) {
97
+ return "" + token;
98
+ }
99
+ if (token.overriddenName) {
100
+ return `${token.overriddenName}`;
101
+ }
102
+ if (token.name) {
103
+ return `${token.name}`;
104
+ }
105
+ const res = token.toString();
106
+ if (res == null) {
107
+ return "" + res;
108
+ }
109
+ const newLineIndex = res.indexOf("\n");
110
+ return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
111
+ }
112
+
113
+ /**
114
+ * @license
115
+ * Copyright Google LLC All Rights Reserved.
116
+ *
117
+ * Use of this source code is governed by an MIT-style license that can be
118
+ * found in the LICENSE file at https://angular.io/license
119
+ */
120
+ const __forward_ref__ = getClosureSafeProperty({
121
+ __forward_ref__: getClosureSafeProperty,
122
+ });
123
+ /**
124
+ * Allows to refer to references which are not yet defined.
125
+ *
126
+ * For instance, `forwardRef` is used when the `token` which we need to refer to for the purposes of
127
+ * DI is declared, but not yet defined. It is also used when the `token` which we use when creating
128
+ * a query is not yet defined.
129
+ *
130
+ * @usageNotes
131
+ * ### Example
132
+ * {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref'}
133
+ * @publicApi
134
+ */
135
+ function forwardRef(forwardRefFn) {
136
+ forwardRefFn.__forward_ref__ = forwardRef;
137
+ forwardRefFn.toString = function () {
138
+ return stringify(this());
139
+ };
140
+ return forwardRefFn;
141
+ }
142
+ /**
143
+ * Lazily retrieves the reference value from a forwardRef.
144
+ *
145
+ * Acts as the identity function when given a non-forward-ref value.
146
+ *
147
+ * @usageNotes
148
+ * ### Example
149
+ *
150
+ * {@example core/di/ts/forward_ref/forward_ref_spec.ts region='resolve_forward_ref'}
151
+ *
152
+ * @see `forwardRef`
153
+ * @publicApi
154
+ */
155
+ function resolveForwardRef(type) {
156
+ return isForwardRef(type) ? type() : type;
157
+ }
158
+ /** Checks whether a function is wrapped by a `forwardRef`. */
159
+ function isForwardRef(fn) {
160
+ return (typeof fn === "function" &&
161
+ fn.hasOwnProperty(__forward_ref__) &&
162
+ fn.__forward_ref__ === forwardRef);
163
+ }
164
+
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
+ /**
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
+ /** Throws an error when a token is not found in DI. */
241
+ function throwProviderNotFoundError(token, injectorName) {
242
+ const injectorDetails = injectorName ? ` in ${injectorName}` : '';
243
+ throw new RuntimeError("201" /* PROVIDER_NOT_FOUND */, `No provider for ${stringifyForError(token)} found${injectorDetails}`);
244
+ }
245
+
246
+ /**
247
+ * @license
248
+ * Copyright Google LLC All Rights Reserved.
249
+ *
250
+ * Use of this source code is governed by an MIT-style license that can be
251
+ * found in the LICENSE file at https://angular.io/license
252
+ */
253
+ /**
254
+ * Construct an injectable definition which defines how a token will be constructed by the DI
255
+ * system, and in which injectors (if any) it will be available.
256
+ *
257
+ * This should be assigned to a static `ɵprov` field on a type, which will then be an
258
+ * `InjectableType`.
259
+ *
260
+ * Options:
261
+ * * `providedIn` determines which injectors will include the injectable, by either associating it
262
+ * with an `@NgModule` or other `InjectorType`, or by specifying that this injectable should be
263
+ * provided in the `'root'` injector, which will be the application-level injector in most apps.
264
+ * * `factory` gives the zero argument function which will create an instance of the injectable.
265
+ * The factory can call `inject` to access the `Injector` and request injection of dependencies.
266
+ *
267
+ * @codeGenApi
268
+ * @publicApi This instruction has been emitted by ViewEngine for some time and is deployed to npm.
269
+ */
270
+ function ɵɵdefineInjectable(opts) {
271
+ return {
272
+ token: opts.token,
273
+ providedIn: opts.providedIn || null,
274
+ factory: opts.factory,
275
+ value: undefined,
276
+ };
277
+ }
278
+ /**
279
+ * Construct an `InjectorDef` which configures an injector.
280
+ *
281
+ * This should be assigned to a static injector def (`ɵinj`) field on a type, which will then be an
282
+ * `InjectorType`.
283
+ *
284
+ * Options:
285
+ *
286
+ * * `providers`: an optional array of providers to add to the injector. Each provider must
287
+ * either have a factory or point to a type which has a `ɵprov` static property (the
288
+ * type must be an `InjectableType`).
289
+ * * `imports`: an optional array of imports of other `InjectorType`s or `InjectorTypeWithModule`s
290
+ * whose providers will also be added to the injector. Locally provided types will override
291
+ * providers from imports.
292
+ *
293
+ * @codeGenApi
294
+ */
295
+ function ɵɵdefineInjector(options) {
296
+ return { providers: options.providers || [], imports: options.imports || [] };
297
+ }
298
+ /**
299
+ * Read the injectable def (`ɵprov`) for `type` in a way which is immune to accidentally reading
300
+ * inherited value.
301
+ *
302
+ * @param type A type which may have its own (non-inherited) `ɵprov`.
303
+ */
304
+ function getInjectableDef(type) {
305
+ return getOwnDefinition(type, NG_PROV_DEF);
306
+ }
307
+ /**
308
+ * Return definition only if it is defined directly on `type` and is not inherited from a base
309
+ * class of `type`.
310
+ */
311
+ function getOwnDefinition(type, field) {
312
+ return type.hasOwnProperty(field) ? type[field] : null;
313
+ }
314
+ const NG_PROV_DEF = getClosureSafeProperty({
315
+ ɵprov: getClosureSafeProperty,
316
+ });
317
+
318
+ /**
319
+ * @license
320
+ * Copyright Google LLC All Rights Reserved.
321
+ *
322
+ * Use of this source code is governed by an MIT-style license that can be
323
+ * found in the LICENSE file at https://angular.io/license
324
+ */
325
+ /**
326
+ * Injection flags for DI.
327
+ *
328
+ * @publicApi
329
+ */
330
+ var InjectFlags;
331
+ (function (InjectFlags) {
332
+ // TODO(alxhub): make this 'const' (and remove `InternalInjectFlags` enum) when ngc no longer
333
+ // writes exports of it into ngfactory files.
334
+ /** Check self and check parent injector if needed */
335
+ InjectFlags[InjectFlags["Default"] = 0] = "Default";
336
+ /** Don't ascend to ancestors of the node requesting injection. */
337
+ InjectFlags[InjectFlags["Self"] = 2] = "Self";
338
+ /** Skip the node that is requesting injection. */
339
+ InjectFlags[InjectFlags["SkipSelf"] = 4] = "SkipSelf";
340
+ /** Inject `defaultValue` instead if token not found. */
341
+ InjectFlags[InjectFlags["Optional"] = 8] = "Optional";
342
+ })(InjectFlags || (InjectFlags = {}));
343
+
344
+ /**
345
+ * @license
346
+ * Copyright Google LLC All Rights Reserved.
347
+ *
348
+ * Use of this source code is governed by an MIT-style license that can be
349
+ * found in the LICENSE file at https://angular.io/license
350
+ */
351
+ /**
352
+ * Injects `root` tokens in limp mode.
353
+ *
354
+ * If no injector exists, we can still inject tree-shakable providers which have `providedIn` set to
355
+ * `"root"`. This is known as the limp mode injection. In such case the value is stored in the
356
+ * injectable definition.
357
+ */
358
+ function injectRootLimpMode(token, notFoundValue, flags) {
359
+ const injectableDef = getInjectableDef(token);
360
+ if (injectableDef && injectableDef.providedIn == "root") {
361
+ return injectableDef.value === undefined
362
+ ? (injectableDef.value = injectableDef.factory())
363
+ : injectableDef.value;
364
+ }
365
+ if (flags & InjectFlags.Optional)
366
+ return null;
367
+ if (notFoundValue !== undefined)
368
+ return notFoundValue;
369
+ throwProviderNotFoundError(stringify(token), "Injector");
370
+ }
371
+
372
+ /**
373
+ * @license
374
+ * Copyright Google LLC All Rights Reserved.
375
+ *
376
+ * Use of this source code is governed by an MIT-style license that can be
377
+ * found in the LICENSE file at https://angular.io/license
378
+ */
379
+ const _THROW_IF_NOT_FOUND = {};
380
+ const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
381
+ /*
382
+ * Name of a property (that we patch onto DI decorator), which is used as an annotation of which
383
+ * InjectFlag this decorator represents. This allows to avoid direct references to the DI decorators
384
+ * in the code, thus making them tree-shakable.
385
+ */
386
+ const DI_DECORATOR_FLAG = "__NG_DI_FLAG__";
387
+ const NG_TEMP_TOKEN_PATH = "ngTempTokenPath";
388
+ const NG_TOKEN_PATH = "ngTokenPath";
389
+ const NEW_LINE = /\n/gm;
390
+ const NO_NEW_LINE = "ɵ";
391
+ const SOURCE = "__source";
392
+ const USE_VALUE = getClosureSafeProperty({
393
+ provide: String,
394
+ useValue: getClosureSafeProperty,
395
+ });
396
+ /**
397
+ * Current injector value used by `inject`.
398
+ * - `undefined`: it is an error to call `inject`
399
+ * - `null`: `inject` can be called but there is no injector (limp-mode).
400
+ * - Injector instance: Use the injector for resolution.
401
+ */
402
+ let _currentInjector = undefined;
403
+ function setCurrentInjector(injector) {
404
+ const former = _currentInjector;
405
+ _currentInjector = injector;
406
+ return former;
407
+ }
408
+ function injectInjectorOnly(token, flags = InjectFlags.Default) {
409
+ if (_currentInjector === undefined) {
410
+ throw new Error(`inject() must be called from an injection context`);
411
+ }
412
+ else if (_currentInjector === null) {
413
+ return injectRootLimpMode(token, undefined, flags);
414
+ }
415
+ else {
416
+ return _currentInjector.get(token, flags & InjectFlags.Optional ? null : undefined, flags);
417
+ }
418
+ }
419
+ function ɵɵinject(token, flags = InjectFlags.Default) {
420
+ return injectInjectorOnly(resolveForwardRef(token), flags);
421
+ }
422
+ /**
423
+ * Injects a token from the currently active injector.
424
+ *
425
+ * Must be used in the context of a factory function such as one defined for an
426
+ * `InjectionToken`. Throws an error if not called from such a context.
427
+ *
428
+ * Within such a factory function, using this function to request injection of a dependency
429
+ * is faster and more type-safe than providing an additional array of dependencies
430
+ * (as has been common with `useFactory` providers).
431
+ *
432
+ * @param token The injection token for the dependency to be injected.
433
+ * @param flags Optional flags that control how injection is executed.
434
+ * The flags correspond to injection strategies that can be specified with
435
+ * parameter decorators `@Host`, `@Self`, `@SkipSef`, and `@Optional`.
436
+ * @returns the injected value if injection is successful, `null` otherwise.
437
+ *
438
+ * @usageNotes
439
+ *
440
+ * ### Example
441
+ *
442
+ * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
443
+ *
444
+ * @publicApi
445
+ */
446
+ const inject = ɵɵinject;
447
+ function injectArgs(types) {
448
+ const args = [];
449
+ for (let i = 0; i < types.length; i++) {
450
+ const arg = resolveForwardRef(types[i]);
451
+ if (Array.isArray(arg)) {
452
+ if (arg.length === 0) {
453
+ throw new Error("Arguments array must have arguments.");
454
+ }
455
+ let type = undefined;
456
+ let flags = InjectFlags.Default;
457
+ for (let j = 0; j < arg.length; j++) {
458
+ const meta = arg[j];
459
+ const flag = getInjectFlag(meta);
460
+ if (typeof flag === "number") {
461
+ // Special case when we handle @Inject decorator.
462
+ if (flag === -1 /* Inject */) {
463
+ type = meta.token;
464
+ }
465
+ else {
466
+ flags |= flag;
467
+ }
468
+ }
469
+ else {
470
+ type = meta;
471
+ }
472
+ }
473
+ args.push(ɵɵinject(type, flags));
474
+ }
475
+ else {
476
+ args.push(ɵɵinject(arg));
477
+ }
478
+ }
479
+ return args;
480
+ }
481
+ /**
482
+ * Attaches a given InjectFlag to a given decorator using monkey-patching.
483
+ * Since DI decorators can be used in providers `deps` array (when provider is configured using
484
+ * `useFactory`) without initialization (e.g. `Host`) and as an instance (e.g. `new Host()`), we
485
+ * attach the flag to make it available both as a static property and as a field on decorator
486
+ * instance.
487
+ *
488
+ * @param decorator Provided DI decorator.
489
+ * @param flag InjectFlag that should be applied.
490
+ */
491
+ function attachInjectFlag(decorator, flag) {
492
+ decorator[DI_DECORATOR_FLAG] = flag;
493
+ decorator.prototype[DI_DECORATOR_FLAG] = flag;
494
+ return decorator;
495
+ }
496
+ /**
497
+ * Reads monkey-patched property that contains InjectFlag attached to a decorator.
498
+ *
499
+ * @param token Token that may contain monkey-patched DI flags property.
500
+ */
501
+ function getInjectFlag(token) {
502
+ return token[DI_DECORATOR_FLAG];
503
+ }
504
+ function catchInjectorError(e, token, injectorErrorName, source) {
505
+ const tokenPath = e[NG_TEMP_TOKEN_PATH];
506
+ if (token[SOURCE]) {
507
+ tokenPath.unshift(token[SOURCE]);
508
+ }
509
+ e.message = formatError("\n" + e.message, tokenPath, injectorErrorName, source);
510
+ e[NG_TOKEN_PATH] = tokenPath;
511
+ e[NG_TEMP_TOKEN_PATH] = null;
512
+ throw e;
513
+ }
514
+ function formatError(text, obj, injectorErrorName, source = null) {
515
+ text =
516
+ text && text.charAt(0) === "\n" && text.charAt(1) == NO_NEW_LINE
517
+ ? text.substr(2)
518
+ : text;
519
+ let context = stringify(obj);
520
+ if (Array.isArray(obj)) {
521
+ context = obj.map(stringify).join(" -> ");
522
+ }
523
+ else if (typeof obj === "object") {
524
+ let parts = [];
525
+ for (let key in obj) {
526
+ if (obj.hasOwnProperty(key)) {
527
+ let value = obj[key];
528
+ parts.push(key +
529
+ ":" +
530
+ (typeof value === "string"
531
+ ? JSON.stringify(value)
532
+ : stringify(value)));
533
+ }
534
+ }
535
+ context = `{${parts.join(", ")}}`;
536
+ }
537
+ return `${injectorErrorName}${source ? "(" + source + ")" : ""}[${context}]: ${text.replace(NEW_LINE, "\n ")}`;
538
+ }
539
+
540
+ /**
541
+ * @license
542
+ * Copyright Google LLC All Rights Reserved.
543
+ *
544
+ * Use of this source code is governed by an MIT-style license that can be
545
+ * found in the LICENSE file at https://angular.io/license
546
+ */
547
+ /**
548
+ * Inject decorator and metadata.
549
+ *
550
+ * @Annotation
551
+ * @publicApi
552
+ */
553
+ const Inject = attachInjectFlag(
554
+ // Disable tslint because `DecoratorFlags` is a const enum which gets inlined.
555
+ // tslint:disable-next-line: no-toplevel-property-access
556
+ makeParamDecorator('Inject', (token) => ({ token })), -1 /* Inject */);
557
+ /**
558
+ * Optional decorator and metadata.
559
+ *
560
+ * @Annotation
561
+ * @publicApi
562
+ */
563
+ const Optional =
564
+ // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
565
+ // tslint:disable-next-line: no-toplevel-property-access
566
+ attachInjectFlag(makeParamDecorator('Optional'), 8 /* Optional */);
567
+ /**
568
+ * Self decorator and metadata.
569
+ *
570
+ * @Annotation
571
+ * @publicApi
572
+ */
573
+ const Self =
574
+ // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
575
+ // tslint:disable-next-line: no-toplevel-property-access
576
+ attachInjectFlag(makeParamDecorator('Self'), 2 /* Self */);
577
+ /**
578
+ * `SkipSelf` decorator and metadata.
579
+ *
580
+ * @Annotation
581
+ * @publicApi
582
+ */
583
+ const SkipSelf =
584
+ // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
585
+ // tslint:disable-next-line: no-toplevel-property-access
586
+ attachInjectFlag(makeParamDecorator('SkipSelf'), 4 /* SkipSelf */);
587
+
588
+ /**
589
+ * @license
590
+ * Copyright Google LLC All Rights Reserved.
591
+ *
592
+ * Use of this source code is governed by an MIT-style license that can be
593
+ * found in the LICENSE file at https://angular.io/license
594
+ */
595
+ const NG_FACTORY_DEF = getClosureSafeProperty({
596
+ ɵfac: getClosureSafeProperty,
597
+ });
598
+
599
+ /**
600
+ * @license
601
+ * Copyright Google LLC All Rights Reserved.
602
+ *
603
+ * Use of this source code is governed by an MIT-style license that can be
604
+ * found in the LICENSE file at https://angular.io/license
605
+ */
606
+ function getFactoryDef(type, throwNotFound) {
607
+ const hasFactoryDef = type.hasOwnProperty(NG_FACTORY_DEF);
608
+ // if (!hasFactoryDef && throwNotFound === true && ngDevMode) {
609
+ // throw new Error(`Type ${stringify(type)} does not have 'ɵfac' property.`);
610
+ // }
611
+ return hasFactoryDef ? type[NG_FACTORY_DEF] : null;
612
+ }
613
+
614
+ /**
615
+ * @license
616
+ * Copyright Google LLC All Rights Reserved.
617
+ *
618
+ * Use of this source code is governed by an MIT-style license that can be
619
+ * found in the LICENSE file at https://angular.io/license
620
+ */
621
+ function deepForEach(input, fn) {
622
+ input.forEach((value) => Array.isArray(value) ? deepForEach(value, fn) : fn(value));
623
+ }
624
+ function newArray(size, value) {
625
+ const list = [];
626
+ for (let i = 0; i < size; i++) {
627
+ list.push(value);
628
+ }
629
+ return list;
630
+ }
631
+
632
+ /**
633
+ * @license
634
+ * Copyright Google LLC All Rights Reserved.
635
+ *
636
+ * Use of this source code is governed by an MIT-style license that can be
637
+ * found in the LICENSE file at https://angular.io/license
638
+ */
639
+ /**
640
+ * Creates a token that can be used in a DI Provider.
641
+ *
642
+ * Use an `InjectionToken` whenever the type you are injecting is not reified (does not have a
643
+ * runtime representation) such as when injecting an interface, callable type, array or
644
+ * parameterized type.
645
+ *
646
+ * `InjectionToken` is parameterized on `T` which is the type of object which will be returned by
647
+ * the `Injector`. This provides additional level of type safety.
648
+ *
649
+ * ```
650
+ * interface MyInterface {...}
651
+ * var myInterface = injector.get(new InjectionToken<MyInterface>('SomeToken'));
652
+ * // myInterface is inferred to be MyInterface.
653
+ * ```
654
+ *
655
+ * When creating an `InjectionToken`, you can optionally specify a factory function which returns
656
+ * (possibly by creating) a default value of the parameterized type `T`. This sets up the
657
+ * `InjectionToken` using this factory as a provider as if it was defined explicitly in the
658
+ * application's root injector. If the factory function, which takes zero arguments, needs to inject
659
+ * dependencies, it can do so using the `inject` function. See below for an example.
660
+ *
661
+ * Additionally, if a `factory` is specified you can also specify the `providedIn` option, which
662
+ * overrides the above behavior and marks the token as belonging to a particular `@NgModule`. As
663
+ * mentioned above, `'root'` is the default value for `providedIn`.
664
+ *
665
+ * @usageNotes
666
+ * ### Basic Example
667
+ *
668
+ * ### Plain InjectionToken
669
+ *
670
+ * {@example core/di/ts/injector_spec.ts region='InjectionToken'}
671
+ *
672
+ * ### Tree-shakable InjectionToken
673
+ *
674
+ * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
675
+ *
676
+ *
677
+ * @publicApi
678
+ */
679
+ class InjectionToken {
680
+ constructor(_desc, options) {
681
+ this._desc = _desc;
682
+ this.ɵprov = undefined;
683
+ if (typeof options == 'number') {
684
+ // (typeof ngDevMode === "undefined" || ngDevMode) &&
685
+ // assertLessThan(options, 0, "Only negative numbers are supported here");
686
+ // // This is a special hack to assign __NG_ELEMENT_ID__ to this instance.
687
+ // // See `InjectorMarkers`
688
+ // (this as any).__NG_ELEMENT_ID__ = options;
689
+ }
690
+ else if (options !== undefined) {
691
+ this.ɵprov = ɵɵdefineInjectable({
692
+ token: this,
693
+ providedIn: options.providedIn || 'root',
694
+ factory: options.factory,
695
+ });
696
+ }
697
+ }
698
+ toString() {
699
+ return `InjectionToken ${this._desc}`;
700
+ }
701
+ }
702
+
703
+ /**
704
+ * @license
705
+ * Copyright Google LLC All Rights Reserved.
706
+ *
707
+ * Use of this source code is governed by an MIT-style license that can be
708
+ * found in the LICENSE file at https://angular.io/license
709
+ */
710
+ /**
711
+ * An InjectionToken that gets the current `Injector` for `createInjector()`-style injectors.
712
+ *
713
+ * Requesting this token instead of `Injector` allows `StaticInjector` to be tree-shaken from a
714
+ * project.
715
+ *
716
+ * @publicApi
717
+ */
718
+ const INJECTOR = new InjectionToken("INJECTOR",
719
+ // Dissable tslint because this is const enum which gets inlined not top level prop access.
720
+ // tslint:disable-next-line: no-toplevel-property-access
721
+ -1 /* Injector */ // Special value used by Ivy to identify `Injector`.
722
+ );
723
+
724
+ /**
725
+ * @license
726
+ * Copyright Google LLC All Rights Reserved.
727
+ *
728
+ * Use of this source code is governed by an MIT-style license that can be
729
+ * found in the LICENSE file at https://angular.io/license
730
+ */
731
+ class NullInjector {
732
+ get(token, notFoundValue = THROW_IF_NOT_FOUND) {
733
+ if (notFoundValue === THROW_IF_NOT_FOUND) {
734
+ const error = new Error(`NullInjectorError: No provider for ${stringify(token)}!`);
735
+ error.name = "NullInjectorError";
736
+ throw error;
737
+ }
738
+ return notFoundValue;
739
+ }
740
+ }
741
+
742
+ /**
743
+ * @license
744
+ * Copyright Google LLC All Rights Reserved.
745
+ *
746
+ * Use of this source code is governed by an MIT-style license that can be
747
+ * found in the LICENSE file at https://angular.io/license
748
+ */
749
+ /**
750
+ * An internal token whose presence in an injector indicates that the injector should treat itself
751
+ * as a root scoped injector when processing requests for unknown tokens which may indicate
752
+ * they are provided in the root scope.
753
+ */
754
+ const INJECTOR_SCOPE = new InjectionToken("Set Injector scope.");
755
+
756
+ /**
757
+ * @license
758
+ * Copyright Google LLC All Rights Reserved.
759
+ *
760
+ * Use of this source code is governed by an MIT-style license that can be
761
+ * found in the LICENSE file at https://angular.io/license
762
+ */
763
+ /**
764
+ * Marker which indicates that a value has not yet been created from the factory function.
765
+ */
766
+ const NOT_YET = {};
767
+ /**
768
+ * Marker which indicates that the factory function for a token is in the process of being called.
769
+ *
770
+ * If the injector is asked to inject a token with its value set to CIRCULAR, that indicates
771
+ * injection of a dependency has recursively attempted to inject the original token, and there is
772
+ * a circular dependency among the providers.
773
+ */
774
+ const CIRCULAR = {};
775
+ /**
776
+ * A lazily initialized NullInjector.
777
+ */
778
+ let NULL_INJECTOR = undefined;
779
+ function getNullInjector() {
780
+ if (NULL_INJECTOR === undefined) {
781
+ NULL_INJECTOR = new NullInjector();
782
+ }
783
+ return NULL_INJECTOR;
784
+ }
785
+ /**
786
+ * Create a new `Injector` which is configured using a `defType` of `InjectorType<any>`s.
787
+ *
788
+ * @publicApi
789
+ */
790
+ function createInjector(defType, parent = null, additionalProviders = null, name) {
791
+ const injector = createInjectorWithoutInjectorInstances(defType, parent, additionalProviders, name);
792
+ injector._resolveInjectorDefTypes();
793
+ return injector;
794
+ }
795
+ /**
796
+ * Creates a new injector without eagerly resolving its injector types. Can be used in places
797
+ * where resolving the injector types immediately can lead to an infinite loop. The injector types
798
+ * should be resolved at a later point by calling `_resolveInjectorDefTypes`.
799
+ */
800
+ function createInjectorWithoutInjectorInstances(defType, parent = null, additionalProviders = null, name) {
801
+ return new R3Injector(defType, additionalProviders, parent || getNullInjector(), name);
802
+ }
803
+ class R3Injector {
804
+ constructor(def, additionalProviders, parent, source = null) {
805
+ this.parent = parent;
806
+ /**
807
+ * Map of tokens to records which contain the instances of those tokens.
808
+ * - `null` value implies that we don't have the record. Used by tree-shakable injectors
809
+ * to prevent further searches.
810
+ */
811
+ this.records = new Map();
812
+ /**
813
+ * The transitive set of `InjectorType`s which define this injector.
814
+ */
815
+ this.injectorDefTypes = new Set();
816
+ /**
817
+ * Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
818
+ */
819
+ this.onDestroy = new Set();
820
+ this._destroyed = false;
821
+ // Start off by creating Records for every provider declared in every InjectorType
822
+ // included transitively in additional providers then do the same for `def`. This order is
823
+ // important because `def` may include providers that override ones in additionalProviders.
824
+ additionalProviders &&
825
+ deepForEach(additionalProviders, (provider) => this.processProvider(provider, def, additionalProviders));
826
+ // Make sure the INJECTOR token provides this injector.
827
+ this.records.set(INJECTOR, makeRecord(undefined, this));
828
+ // Detect whether this injector has the APP_ROOT_SCOPE token and thus should provide
829
+ // any injectable scoped to APP_ROOT_SCOPE.
830
+ const record = this.records.get(INJECTOR_SCOPE);
831
+ this.scope = record != null ? record.value : null;
832
+ // Source name, used for debugging
833
+ this.source = source || (typeof def === 'object' ? null : stringify(def));
834
+ }
835
+ /**
836
+ * Flag indicating that this injector was previously destroyed.
837
+ */
838
+ get destroyed() {
839
+ return this._destroyed;
840
+ }
841
+ /**
842
+ * Destroy the injector and release references to every instance or provider associated with it.
843
+ *
844
+ * Also calls the `OnDestroy` lifecycle hooks of every instance that was created for which a
845
+ * hook was found.
846
+ */
847
+ destroy() {
848
+ this.assertNotDestroyed();
849
+ // Set destroyed = true first, in case lifecycle hooks re-enter destroy().
850
+ this._destroyed = true;
851
+ try {
852
+ // Call all the lifecycle hooks.
853
+ this.onDestroy.forEach((service) => service.ngOnDestroy());
854
+ }
855
+ finally {
856
+ // Release all references.
857
+ this.records.clear();
858
+ this.onDestroy.clear();
859
+ this.injectorDefTypes.clear();
860
+ }
861
+ }
862
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
863
+ this.assertNotDestroyed();
864
+ // Set the injection context.
865
+ const previousInjector = setCurrentInjector(this);
866
+ try {
867
+ // Check for the SkipSelf flag.
868
+ if (!(flags & InjectFlags.SkipSelf)) {
869
+ // SkipSelf isn't set, check if the record belongs to this injector.
870
+ let record = this.records.get(token);
871
+ if (record === undefined) {
872
+ // No record, but maybe the token is scoped to this injector. Look for an injectable
873
+ // def with a scope matching this injector.
874
+ const def = couldBeInjectableType(token) && getInjectableDef(token);
875
+ if (def && this.injectableDefInScope(def)) {
876
+ // Found an injectable def and it's scoped to this injector. Pretend as if it was here
877
+ // all along.
878
+ record = makeRecord(injectableDefOrInjectorDefFactory(token), NOT_YET);
879
+ }
880
+ else {
881
+ record = null;
882
+ }
883
+ this.records.set(token, record);
884
+ }
885
+ // If a record was found, get the instance for it and return it.
886
+ if (record != null /* NOT null || undefined */) {
887
+ return this.hydrate(token, record);
888
+ }
889
+ }
890
+ // Select the next injector based on the Self flag - if self is set, the next injector is
891
+ // the NullInjector, otherwise it's the parent.
892
+ const nextInjector = !(flags & InjectFlags.Self)
893
+ ? this.parent
894
+ : getNullInjector();
895
+ // Set the notFoundValue based on the Optional flag - if optional is set and notFoundValue
896
+ // is undefined, the value is null, otherwise it's the notFoundValue.
897
+ notFoundValue =
898
+ flags & InjectFlags.Optional && notFoundValue === THROW_IF_NOT_FOUND
899
+ ? null
900
+ : notFoundValue;
901
+ return nextInjector.get(token, notFoundValue);
902
+ }
903
+ catch (e) {
904
+ if (e.name === 'NullInjectorError') {
905
+ const path = (e[NG_TEMP_TOKEN_PATH] =
906
+ e[NG_TEMP_TOKEN_PATH] || []);
907
+ path.unshift(stringify(token));
908
+ if (previousInjector) {
909
+ // We still have a parent injector, keep throwing
910
+ throw e;
911
+ }
912
+ else {
913
+ // Format & throw the final error message when we don't have any previous injector
914
+ return catchInjectorError(e, token, 'R3InjectorError', this.source);
915
+ }
916
+ }
917
+ else {
918
+ throw e;
919
+ }
920
+ }
921
+ finally {
922
+ // Lastly, restore the previous injection context.
923
+ setCurrentInjector(previousInjector);
924
+ }
925
+ }
926
+ /** @internal */
927
+ _resolveInjectorDefTypes() {
928
+ this.injectorDefTypes.forEach((defType) => this.get(defType));
929
+ }
930
+ toString() {
931
+ const tokens = [], records = this.records;
932
+ records.forEach((v, token) => tokens.push(stringify(token)));
933
+ return `R3Injector[${tokens.join(', ')}]`;
934
+ }
935
+ assertNotDestroyed() {
936
+ if (this._destroyed) {
937
+ throw new Error('Injector has already been destroyed.');
938
+ }
939
+ }
940
+ /**
941
+ * Add an `InjectorType` or `InjectorTypeWithProviders` and all of its transitive providers
942
+ * to this injector.
943
+ *
944
+ * If an `InjectorTypeWithProviders` that declares providers besides the type is specified,
945
+ * the function will return "true" to indicate that the providers of the type definition need
946
+ * to be processed. This allows us to process providers of injector types after all imports of
947
+ * an injector definition are processed. (following View Engine semantics: see FW-1349)
948
+ */
949
+ /**
950
+ * Process a `SingleProvider` and add it.
951
+ */
952
+ processProvider(provider, ngModuleType, providers) {
953
+ // Determine the token from the provider. Either it's its own token, or has a {provide: ...}
954
+ // property.
955
+ provider = resolveForwardRef(provider);
956
+ let token = isTypeProvider(provider)
957
+ ? provider
958
+ : resolveForwardRef(provider && provider.provide);
959
+ // Construct a `Record` for the provider.
960
+ const record = providerToRecord(provider, ngModuleType, providers);
961
+ if (!isTypeProvider(provider) && provider.multi === true) {
962
+ // If the provider indicates that it's a multi-provider, process it specially.
963
+ // First check whether it's been defined already.
964
+ let multiRecord = this.records.get(token);
965
+ if (multiRecord) {
966
+ // It has. Throw a nice error if
967
+ // if (ngDevMode && multiRecord.multi === undefined) {
968
+ // throwMixedMultiProviderError();
969
+ // }
970
+ }
971
+ else {
972
+ multiRecord = makeRecord(undefined, NOT_YET, true);
973
+ multiRecord.factory = () => injectArgs(multiRecord.multi);
974
+ this.records.set(token, multiRecord);
975
+ }
976
+ token = provider;
977
+ multiRecord.multi.push(provider);
978
+ }
979
+ else {
980
+ // const existing = this.records.get(token);
981
+ // if (ngDevMode && existing && existing.multi !== undefined) {
982
+ // throwMixedMultiProviderError();
983
+ // }
984
+ }
985
+ this.records.set(token, record);
986
+ }
987
+ hydrate(token, record) {
988
+ // if (ngDevMode && record.value === CIRCULAR) {
989
+ // throwCyclicDependencyError(stringify(token));
990
+ // } else
991
+ if (record.value === NOT_YET) {
992
+ record.value = CIRCULAR;
993
+ record.value = record.factory();
994
+ }
995
+ if (typeof record.value === 'object' &&
996
+ record.value &&
997
+ hasOnDestroy(record.value)) {
998
+ this.onDestroy.add(record.value);
999
+ }
1000
+ return record.value;
1001
+ }
1002
+ injectableDefInScope(def) {
1003
+ if (!def.providedIn) {
1004
+ return false;
1005
+ }
1006
+ const providedIn = resolveForwardRef(def.providedIn);
1007
+ if (typeof providedIn === 'string') {
1008
+ return providedIn === 'any' || providedIn === this.scope;
1009
+ }
1010
+ else {
1011
+ return this.injectorDefTypes.has(providedIn);
1012
+ }
1013
+ }
1014
+ }
1015
+ function injectableDefOrInjectorDefFactory(token) {
1016
+ // Most tokens will have an injectable def directly on them, which specifies a factory directly.
1017
+ const injectableDef = getInjectableDef(token);
1018
+ const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
1019
+ if (factory !== null) {
1020
+ return factory;
1021
+ }
1022
+ // InjectionTokens should have an injectable def (ɵprov) and thus should be handled above.
1023
+ // If it's missing that, it's an error.
1024
+ if (token instanceof InjectionToken) {
1025
+ throw new Error(`Token ${stringify(token)} is missing a ɵprov definition.`);
1026
+ }
1027
+ // Undecorated types can sometimes be created if they have no constructor arguments.
1028
+ if (token instanceof Function) {
1029
+ return getUndecoratedInjectableFactory(token);
1030
+ }
1031
+ // There was no way to resolve a factory for this token.
1032
+ throw new Error('unreachable');
1033
+ }
1034
+ function getUndecoratedInjectableFactory(token) {
1035
+ // If the token has parameters then it has dependencies that we cannot resolve implicitly.
1036
+ const paramLength = token.length;
1037
+ if (paramLength > 0) {
1038
+ const args = newArray(paramLength, '?');
1039
+ throw new Error(`Can't resolve all parameters for ${stringify(token)}: (${args.join(', ')}).`);
1040
+ }
1041
+ // The constructor function appears to have no parameters.
1042
+ // This might be because it inherits from a super-class. In which case, use an injectable
1043
+ // def from an ancestor if there is one.
1044
+ // Otherwise this really is a simple class with no dependencies, so return a factory that
1045
+ // just instantiates the zero-arg constructor.
1046
+ return () => new token();
1047
+ }
1048
+ function providerToRecord(provider, ngModuleType, providers) {
1049
+ if (isValueProvider(provider)) {
1050
+ return makeRecord(undefined, provider.useValue);
1051
+ }
1052
+ else {
1053
+ const factory = providerToFactory(provider, ngModuleType, providers);
1054
+ return makeRecord(factory, NOT_YET);
1055
+ }
1056
+ }
1057
+ /**
1058
+ * Converts a `SingleProvider` into a factory function.
1059
+ *
1060
+ * @param provider provider to convert to factory
1061
+ */
1062
+ function providerToFactory(provider, ngModuleType, providers) {
1063
+ let factory = undefined;
1064
+ if (isTypeProvider(provider)) {
1065
+ const unwrappedProvider = resolveForwardRef(provider);
1066
+ return (getFactoryDef(unwrappedProvider) ||
1067
+ injectableDefOrInjectorDefFactory(unwrappedProvider));
1068
+ }
1069
+ else {
1070
+ if (isValueProvider(provider)) {
1071
+ factory = () => resolveForwardRef(provider.useValue);
1072
+ }
1073
+ else if (isFactoryProvider(provider)) {
1074
+ factory = () => provider.useFactory(...injectArgs(provider.deps || []));
1075
+ }
1076
+ else if (isExistingProvider(provider)) {
1077
+ factory = () => ɵɵinject(resolveForwardRef(provider.useExisting));
1078
+ }
1079
+ else {
1080
+ const classRef = resolveForwardRef(provider &&
1081
+ (provider.useClass ||
1082
+ provider.provide));
1083
+ // if (ngDevMode && !classRef) {
1084
+ // throwInvalidProviderError(ngModuleType, providers, provider);
1085
+ // }
1086
+ if (hasDeps(provider)) {
1087
+ factory = () => new classRef(...injectArgs(provider.deps));
1088
+ }
1089
+ else {
1090
+ return (getFactoryDef(classRef) || injectableDefOrInjectorDefFactory(classRef));
1091
+ }
1092
+ }
1093
+ }
1094
+ return factory;
1095
+ }
1096
+ function makeRecord(factory, value, multi = false) {
1097
+ return {
1098
+ factory: factory,
1099
+ value: value,
1100
+ multi: multi ? [] : undefined,
1101
+ };
1102
+ }
1103
+ function isValueProvider(value) {
1104
+ return value !== null && typeof value == 'object' && USE_VALUE in value;
1105
+ }
1106
+ function isExistingProvider(value) {
1107
+ return !!(value && value.useExisting);
1108
+ }
1109
+ function isFactoryProvider(value) {
1110
+ return !!(value && value.useFactory);
1111
+ }
1112
+ function isTypeProvider(value) {
1113
+ return typeof value === 'function';
1114
+ }
1115
+ function hasDeps(value) {
1116
+ return !!value.deps;
1117
+ }
1118
+ function hasOnDestroy(value) {
1119
+ return (value !== null &&
1120
+ typeof value === 'object' &&
1121
+ typeof value.ngOnDestroy === 'function');
1122
+ }
1123
+ function couldBeInjectableType(value) {
1124
+ return (typeof value === 'function' ||
1125
+ (typeof value === 'object' && value instanceof InjectionToken));
1126
+ }
1127
+
1128
+ /**
1129
+ * @license
1130
+ * Copyright Google LLC All Rights Reserved.
1131
+ *
1132
+ * Use of this source code is governed by an MIT-style license that can be
1133
+ * found in the LICENSE file at https://angular.io/license
1134
+ */
1135
+ function INJECTOR_IMPL__POST_R3__(providers, parent, name) {
1136
+ return createInjector({ name: name }, parent, providers, name);
1137
+ }
1138
+ const INJECTOR_IMPL = INJECTOR_IMPL__POST_R3__;
1139
+ /**
1140
+ * Concrete injectors implement this interface. Injectors are configured
1141
+ * with [providers](guide/glossary#provider) that associate
1142
+ * dependencies of various types with [injection tokens](guide/glossary#di-token).
1143
+ *
1144
+ * @see ["DI Providers"](guide/dependency-injection-providers).
1145
+ * @see `StaticProvider`
1146
+ *
1147
+ * @usageNotes
1148
+ *
1149
+ * The following example creates a service injector instance.
1150
+ *
1151
+ * {@example core/di/ts/provider_spec.ts region='ConstructorProvider'}
1152
+ *
1153
+ * ### Usage example
1154
+ *
1155
+ * {@example core/di/ts/injector_spec.ts region='Injector'}
1156
+ *
1157
+ * `Injector` returns itself when given `Injector` as a token:
1158
+ *
1159
+ * {@example core/di/ts/injector_spec.ts region='injectInjector'}
1160
+ *
1161
+ * @publicApi
1162
+ */
1163
+ class Injector {
1164
+ static create(options, parent) {
1165
+ if (Array.isArray(options)) {
1166
+ return INJECTOR_IMPL(options, parent, '');
1167
+ }
1168
+ else {
1169
+ return INJECTOR_IMPL(options.providers, options.parent, options.name || '');
1170
+ }
1171
+ }
1172
+ }
1173
+ Injector.THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
1174
+ Injector.NULL = new NullInjector();
1175
+ /** @nocollapse */
1176
+ Injector.ɵprov = ɵɵdefineInjectable({
1177
+ token: Injector,
1178
+ providedIn: 'any',
1179
+ factory: () => ɵɵinject(INJECTOR),
1180
+ });
1181
+ /**
1182
+ * @internal
1183
+ * @nocollapse
1184
+ */
1185
+ Injector.__NG_ELEMENT_ID__ = -1 /* Injector */;
1186
+
1187
+ /**
1188
+ * @license
1189
+ * Copyright Google LLC All Rights Reserved.
1190
+ *
1191
+ * Use of this source code is governed by an MIT-style license that can be
1192
+ * found in the LICENSE file at https://angular.io/license
1193
+ */
1194
+ /**
1195
+ * Throws an error indicating that a factory function could not be generated by the compiler for a
1196
+ * particular class.
1197
+ *
1198
+ * This instruction allows the actual error message to be optimized away when ngDevMode is turned
1199
+ * off, saving bytes of generated code while still providing a good experience in dev mode.
1200
+ *
1201
+ * The name of the class is not mentioned here, but will be in the generated factory function name
1202
+ * and thus in the stack trace.
1203
+ *
1204
+ * @codeGenApi
1205
+ */
1206
+ function ɵɵinvalidFactory() {
1207
+ const msg = 'invalid';
1208
+ throw new Error(msg);
1209
+ }
1210
+
1211
+ export { INJECTOR_IMPL, INJECTOR_IMPL__POST_R3__, INJECTOR_SCOPE, Inject, InjectFlags, Injectable, InjectionToken, Injector, NG_PROV_DEF, NG_TEMP_TOKEN_PATH, NullInjector, Optional, R3Injector, SOURCE, Self, SkipSelf, THROW_IF_NOT_FOUND, USE_VALUE, attachInjectFlag, catchInjectorError, createInjector, createInjectorWithoutInjectorInstances, formatError, getInjectFlag, getInjectableDef, inject, injectArgs, injectInjectorOnly, isTypeProvider, providerToFactory, setCurrentInjector, ɵɵdefineInjectable, ɵɵdefineInjector, ɵɵinject, ɵɵinvalidFactory };