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