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