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
+ /**
9
+ * Injectable decorator and metadata.
10
+ *
11
+ * @Annotation
12
+ * @publicApi
13
+ */
14
+ export const Injectable = undefined;
@@ -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,53 @@
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
+ import { stringify } from "../util/stringify";
10
+ const __forward_ref__ = getClosureSafeProperty({
11
+ __forward_ref__: getClosureSafeProperty,
12
+ });
13
+ /**
14
+ * Allows to refer to references which are not yet defined.
15
+ *
16
+ * For instance, `forwardRef` is used when the `token` which we need to refer to for the purposes of
17
+ * DI is declared, but not yet defined. It is also used when the `token` which we use when creating
18
+ * a query is not yet defined.
19
+ *
20
+ * @usageNotes
21
+ * ### Example
22
+ * {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref'}
23
+ * @publicApi
24
+ */
25
+ export function forwardRef(forwardRefFn) {
26
+ forwardRefFn.__forward_ref__ = forwardRef;
27
+ forwardRefFn.toString = function () {
28
+ return stringify(this());
29
+ };
30
+ return forwardRefFn;
31
+ }
32
+ /**
33
+ * Lazily retrieves the reference value from a forwardRef.
34
+ *
35
+ * Acts as the identity function when given a non-forward-ref value.
36
+ *
37
+ * @usageNotes
38
+ * ### Example
39
+ *
40
+ * {@example core/di/ts/forward_ref/forward_ref_spec.ts region='resolve_forward_ref'}
41
+ *
42
+ * @see `forwardRef`
43
+ * @publicApi
44
+ */
45
+ export function resolveForwardRef(type) {
46
+ return isForwardRef(type) ? type() : type;
47
+ }
48
+ /** Checks whether a function is wrapped by a `forwardRef`. */
49
+ export function isForwardRef(fn) {
50
+ return (typeof fn === "function" &&
51
+ fn.hasOwnProperty(__forward_ref__) &&
52
+ fn.__forward_ref__ === forwardRef);
53
+ }
@@ -0,0 +1,31 @@
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 { throwProviderNotFoundError } from "../render3/errors_di";
9
+ import { stringify } from "../util/stringify";
10
+ import { getInjectableDef } from "./interface/defs";
11
+ import { InjectFlags } from "./interface/injector";
12
+ /**
13
+ * Injects `root` tokens in limp mode.
14
+ *
15
+ * If no injector exists, we can still inject tree-shakable providers which have `providedIn` set to
16
+ * `"root"`. This is known as the limp mode injection. In such case the value is stored in the
17
+ * injectable definition.
18
+ */
19
+ export function injectRootLimpMode(token, notFoundValue, flags) {
20
+ const injectableDef = getInjectableDef(token);
21
+ if (injectableDef && injectableDef.providedIn == "root") {
22
+ return injectableDef.value === undefined
23
+ ? (injectableDef.value = injectableDef.factory())
24
+ : injectableDef.value;
25
+ }
26
+ if (flags & InjectFlags.Optional)
27
+ return null;
28
+ if (notFoundValue !== undefined)
29
+ return notFoundValue;
30
+ throwProviderNotFoundError(stringify(token), "Injector");
31
+ }
@@ -0,0 +1,71 @@
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 { ɵɵdefineInjectable } from './interface/defs';
9
+ /**
10
+ * Creates a token that can be used in a DI Provider.
11
+ *
12
+ * Use an `InjectionToken` whenever the type you are injecting is not reified (does not have a
13
+ * runtime representation) such as when injecting an interface, callable type, array or
14
+ * parameterized type.
15
+ *
16
+ * `InjectionToken` is parameterized on `T` which is the type of object which will be returned by
17
+ * the `Injector`. This provides additional level of type safety.
18
+ *
19
+ * ```
20
+ * interface MyInterface {...}
21
+ * var myInterface = injector.get(new InjectionToken<MyInterface>('SomeToken'));
22
+ * // myInterface is inferred to be MyInterface.
23
+ * ```
24
+ *
25
+ * When creating an `InjectionToken`, you can optionally specify a factory function which returns
26
+ * (possibly by creating) a default value of the parameterized type `T`. This sets up the
27
+ * `InjectionToken` using this factory as a provider as if it was defined explicitly in the
28
+ * application's root injector. If the factory function, which takes zero arguments, needs to inject
29
+ * dependencies, it can do so using the `inject` function. See below for an example.
30
+ *
31
+ * Additionally, if a `factory` is specified you can also specify the `providedIn` option, which
32
+ * overrides the above behavior and marks the token as belonging to a particular `@NgModule`. As
33
+ * mentioned above, `'root'` is the default value for `providedIn`.
34
+ *
35
+ * @usageNotes
36
+ * ### Basic Example
37
+ *
38
+ * ### Plain InjectionToken
39
+ *
40
+ * {@example core/di/ts/injector_spec.ts region='InjectionToken'}
41
+ *
42
+ * ### Tree-shakable InjectionToken
43
+ *
44
+ * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
45
+ *
46
+ *
47
+ * @publicApi
48
+ */
49
+ export class InjectionToken {
50
+ constructor(_desc, options) {
51
+ this._desc = _desc;
52
+ this.ɵprov = undefined;
53
+ if (typeof options == 'number') {
54
+ // (typeof ngDevMode === "undefined" || ngDevMode) &&
55
+ // assertLessThan(options, 0, "Only negative numbers are supported here");
56
+ // // This is a special hack to assign __NG_ELEMENT_ID__ to this instance.
57
+ // // See `InjectorMarkers`
58
+ // (this as any).__NG_ELEMENT_ID__ = options;
59
+ }
60
+ else if (options !== undefined) {
61
+ this.ɵprov = ɵɵdefineInjectable({
62
+ token: this,
63
+ providedIn: options.providedIn || 'root',
64
+ factory: options.factory,
65
+ });
66
+ }
67
+ }
68
+ toString() {
69
+ return `InjectionToken ${this._desc}`;
70
+ }
71
+ }
@@ -0,0 +1,63 @@
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 { THROW_IF_NOT_FOUND, ɵɵinject } from './injector_compatibility';
9
+ import { INJECTOR } from './injector_token';
10
+ import { ɵɵdefineInjectable } from './interface/defs';
11
+ import { NullInjector } from './null_injector';
12
+ import { createInjector } from './r3_injector';
13
+ export function INJECTOR_IMPL__POST_R3__(providers, parent, name) {
14
+ return createInjector({ name: name }, parent, providers, name);
15
+ }
16
+ export const INJECTOR_IMPL = INJECTOR_IMPL__POST_R3__;
17
+ /**
18
+ * Concrete injectors implement this interface. Injectors are configured
19
+ * with [providers](guide/glossary#provider) that associate
20
+ * dependencies of various types with [injection tokens](guide/glossary#di-token).
21
+ *
22
+ * @see ["DI Providers"](guide/dependency-injection-providers).
23
+ * @see `StaticProvider`
24
+ *
25
+ * @usageNotes
26
+ *
27
+ * The following example creates a service injector instance.
28
+ *
29
+ * {@example core/di/ts/provider_spec.ts region='ConstructorProvider'}
30
+ *
31
+ * ### Usage example
32
+ *
33
+ * {@example core/di/ts/injector_spec.ts region='Injector'}
34
+ *
35
+ * `Injector` returns itself when given `Injector` as a token:
36
+ *
37
+ * {@example core/di/ts/injector_spec.ts region='injectInjector'}
38
+ *
39
+ * @publicApi
40
+ */
41
+ export class Injector {
42
+ static create(options, parent) {
43
+ if (Array.isArray(options)) {
44
+ return INJECTOR_IMPL(options, parent, '');
45
+ }
46
+ else {
47
+ return INJECTOR_IMPL(options.providers, options.parent, options.name || '');
48
+ }
49
+ }
50
+ }
51
+ Injector.THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
52
+ Injector.NULL = new NullInjector();
53
+ /** @nocollapse */
54
+ Injector.ɵprov = ɵɵdefineInjectable({
55
+ token: Injector,
56
+ providedIn: 'any',
57
+ factory: () => ɵɵinject(INJECTOR),
58
+ });
59
+ /**
60
+ * @internal
61
+ * @nocollapse
62
+ */
63
+ Injector.__NG_ELEMENT_ID__ = -1 /* Injector */;
@@ -0,0 +1,172 @@
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
+ import { stringify } from "../util/stringify";
10
+ import { resolveForwardRef } from "./forward_ref";
11
+ import { injectRootLimpMode } from "./inject_switch";
12
+ import { InjectFlags, } from "./interface/injector";
13
+ const _THROW_IF_NOT_FOUND = {};
14
+ export const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
15
+ /*
16
+ * Name of a property (that we patch onto DI decorator), which is used as an annotation of which
17
+ * InjectFlag this decorator represents. This allows to avoid direct references to the DI decorators
18
+ * in the code, thus making them tree-shakable.
19
+ */
20
+ const DI_DECORATOR_FLAG = "__NG_DI_FLAG__";
21
+ export const NG_TEMP_TOKEN_PATH = "ngTempTokenPath";
22
+ const NG_TOKEN_PATH = "ngTokenPath";
23
+ const NEW_LINE = /\n/gm;
24
+ const NO_NEW_LINE = "ɵ";
25
+ export const SOURCE = "__source";
26
+ export const USE_VALUE = getClosureSafeProperty({
27
+ provide: String,
28
+ useValue: getClosureSafeProperty,
29
+ });
30
+ /**
31
+ * Current injector value used by `inject`.
32
+ * - `undefined`: it is an error to call `inject`
33
+ * - `null`: `inject` can be called but there is no injector (limp-mode).
34
+ * - Injector instance: Use the injector for resolution.
35
+ */
36
+ let _currentInjector = undefined;
37
+ export function setCurrentInjector(injector) {
38
+ const former = _currentInjector;
39
+ _currentInjector = injector;
40
+ return former;
41
+ }
42
+ export function injectInjectorOnly(token, flags = InjectFlags.Default) {
43
+ if (_currentInjector === undefined) {
44
+ throw new Error(`inject() must be called from an injection context`);
45
+ }
46
+ else if (_currentInjector === null) {
47
+ return injectRootLimpMode(token, undefined, flags);
48
+ }
49
+ else {
50
+ return _currentInjector.get(token, flags & InjectFlags.Optional ? null : undefined, flags);
51
+ }
52
+ }
53
+ export function ɵɵinject(token, flags = InjectFlags.Default) {
54
+ return injectInjectorOnly(resolveForwardRef(token), flags);
55
+ }
56
+ /**
57
+ * Injects a token from the currently active injector.
58
+ *
59
+ * Must be used in the context of a factory function such as one defined for an
60
+ * `InjectionToken`. Throws an error if not called from such a context.
61
+ *
62
+ * Within such a factory function, using this function to request injection of a dependency
63
+ * is faster and more type-safe than providing an additional array of dependencies
64
+ * (as has been common with `useFactory` providers).
65
+ *
66
+ * @param token The injection token for the dependency to be injected.
67
+ * @param flags Optional flags that control how injection is executed.
68
+ * The flags correspond to injection strategies that can be specified with
69
+ * parameter decorators `@Host`, `@Self`, `@SkipSef`, and `@Optional`.
70
+ * @returns the injected value if injection is successful, `null` otherwise.
71
+ *
72
+ * @usageNotes
73
+ *
74
+ * ### Example
75
+ *
76
+ * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
77
+ *
78
+ * @publicApi
79
+ */
80
+ export const inject = ɵɵinject;
81
+ export function injectArgs(types) {
82
+ const args = [];
83
+ for (let i = 0; i < types.length; i++) {
84
+ const arg = resolveForwardRef(types[i]);
85
+ if (Array.isArray(arg)) {
86
+ if (arg.length === 0) {
87
+ throw new Error("Arguments array must have arguments.");
88
+ }
89
+ let type = undefined;
90
+ let flags = InjectFlags.Default;
91
+ for (let j = 0; j < arg.length; j++) {
92
+ const meta = arg[j];
93
+ const flag = getInjectFlag(meta);
94
+ if (typeof flag === "number") {
95
+ // Special case when we handle @Inject decorator.
96
+ if (flag === -1 /* Inject */) {
97
+ type = meta.token;
98
+ }
99
+ else {
100
+ flags |= flag;
101
+ }
102
+ }
103
+ else {
104
+ type = meta;
105
+ }
106
+ }
107
+ args.push(ɵɵinject(type, flags));
108
+ }
109
+ else {
110
+ args.push(ɵɵinject(arg));
111
+ }
112
+ }
113
+ return args;
114
+ }
115
+ /**
116
+ * Attaches a given InjectFlag to a given decorator using monkey-patching.
117
+ * Since DI decorators can be used in providers `deps` array (when provider is configured using
118
+ * `useFactory`) without initialization (e.g. `Host`) and as an instance (e.g. `new Host()`), we
119
+ * attach the flag to make it available both as a static property and as a field on decorator
120
+ * instance.
121
+ *
122
+ * @param decorator Provided DI decorator.
123
+ * @param flag InjectFlag that should be applied.
124
+ */
125
+ export function attachInjectFlag(decorator, flag) {
126
+ decorator[DI_DECORATOR_FLAG] = flag;
127
+ decorator.prototype[DI_DECORATOR_FLAG] = flag;
128
+ return decorator;
129
+ }
130
+ /**
131
+ * Reads monkey-patched property that contains InjectFlag attached to a decorator.
132
+ *
133
+ * @param token Token that may contain monkey-patched DI flags property.
134
+ */
135
+ export function getInjectFlag(token) {
136
+ return token[DI_DECORATOR_FLAG];
137
+ }
138
+ export function catchInjectorError(e, token, injectorErrorName, source) {
139
+ const tokenPath = e[NG_TEMP_TOKEN_PATH];
140
+ if (token[SOURCE]) {
141
+ tokenPath.unshift(token[SOURCE]);
142
+ }
143
+ e.message = formatError("\n" + e.message, tokenPath, injectorErrorName, source);
144
+ e[NG_TOKEN_PATH] = tokenPath;
145
+ e[NG_TEMP_TOKEN_PATH] = null;
146
+ throw e;
147
+ }
148
+ export function formatError(text, obj, injectorErrorName, source = null) {
149
+ text =
150
+ text && text.charAt(0) === "\n" && text.charAt(1) == NO_NEW_LINE
151
+ ? text.substr(2)
152
+ : text;
153
+ let context = stringify(obj);
154
+ if (Array.isArray(obj)) {
155
+ context = obj.map(stringify).join(" -> ");
156
+ }
157
+ else if (typeof obj === "object") {
158
+ let parts = [];
159
+ for (let key in obj) {
160
+ if (obj.hasOwnProperty(key)) {
161
+ let value = obj[key];
162
+ parts.push(key +
163
+ ":" +
164
+ (typeof value === "string"
165
+ ? JSON.stringify(value)
166
+ : stringify(value)));
167
+ }
168
+ }
169
+ context = `{${parts.join(", ")}}`;
170
+ }
171
+ return `${injectorErrorName}${source ? "(" + source + ")" : ""}[${context}]: ${text.replace(NEW_LINE, "\n ")}`;
172
+ }
@@ -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,21 @@
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 InjectionToken that gets the current `Injector` for `createInjector()`-style injectors.
11
+ *
12
+ * Requesting this token instead of `Injector` allows `StaticInjector` to be tree-shaken from a
13
+ * project.
14
+ *
15
+ * @publicApi
16
+ */
17
+ export const INJECTOR = new InjectionToken("INJECTOR",
18
+ // Dissable tslint because this is const enum which gets inlined not top level prop access.
19
+ // tslint:disable-next-line: no-toplevel-property-access
20
+ -1 /* Injector */ // Special value used by Ivy to identify `Injector`.
21
+ );