static-injector 1.0.6 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/import/commonjs/index.js +1295 -0
  2. package/import/{decorator → es2015/decorator}/injectable.js +1 -4
  3. package/import/{di → es2015/decorator}/interface/provider.js +1 -2
  4. package/import/{di → es2015/di}/forward_ref.js +8 -14
  5. package/import/{di → es2015/di}/inject_switch.js +8 -12
  6. package/import/{di → es2015/di}/injection_token.js +3 -9
  7. package/import/es2015/di/injector.js +63 -0
  8. package/import/{di → es2015/di}/injector_compatibility.js +31 -42
  9. package/import/{di → es2015/di}/injector_marker.js +1 -2
  10. package/import/{di → es2015/di}/injector_token.js +2 -5
  11. package/import/{di → es2015/di}/interface/defs.js +7 -42
  12. package/import/{di → es2015/di}/interface/injector.js +2 -5
  13. package/import/{decorator → es2015/di}/interface/provider.js +1 -2
  14. package/import/{di → es2015/di}/metadata.js +10 -13
  15. package/import/es2015/di/null_injector.js +19 -0
  16. package/import/{di → es2015/di}/provider_token.js +1 -2
  17. package/import/{di → es2015/di}/r3_injector.js +53 -153
  18. package/import/{di → es2015/di}/scope.js +2 -5
  19. package/import/es2015/index.js +12 -0
  20. package/import/{interface → es2015/interface}/lifecycle_hooks.js +1 -2
  21. package/import/es2015/interface/type.js +8 -0
  22. package/import/es2015/render3/definition_factory.js +15 -0
  23. package/import/es2015/render3/di.js +49 -0
  24. package/import/{render3 → es2015/render3}/error_code.js +2 -7
  25. package/import/es2015/render3/errors_di.js +14 -0
  26. package/import/es2015/render3/fields.js +11 -0
  27. package/import/{render3 → es2015/render3}/instructions/di.js +1 -5
  28. package/import/{render3 → es2015/render3}/util/stringify_utils.js +2 -7
  29. package/import/{util → es2015/util}/array_utils.js +2 -7
  30. package/import/{util → es2015/util}/closure.js +1 -5
  31. package/import/es2015/util/decorators.js +30 -0
  32. package/import/{util → es2015/util}/empty.js +1 -4
  33. package/import/{util → es2015/util}/property.js +1 -5
  34. package/import/{util → es2015/util}/stringify.js +1 -5
  35. package/import/fesm2015/index.js +1257 -0
  36. package/import/{decorator → typings/decorator}/injectable.d.ts +0 -0
  37. package/import/{decorator → typings/decorator}/interface/provider.d.ts +0 -0
  38. package/import/{di → typings/di}/forward_ref.d.ts +0 -0
  39. package/import/{di → typings/di}/inject_switch.d.ts +0 -0
  40. package/import/{di → typings/di}/injection_token.d.ts +0 -2
  41. package/import/{di → typings/di}/injector.d.ts +0 -10
  42. package/import/{di → typings/di}/injector_compatibility.d.ts +0 -0
  43. package/import/{di → typings/di}/injector_marker.d.ts +0 -0
  44. package/import/{di → typings/di}/injector_token.d.ts +0 -0
  45. package/import/{di → typings/di}/interface/defs.d.ts +4 -20
  46. package/import/{di → typings/di}/interface/injector.d.ts +0 -0
  47. package/import/{di → typings/di}/interface/provider.d.ts +0 -0
  48. package/import/{di → typings/di}/metadata.d.ts +0 -0
  49. package/import/{di → typings/di}/null_injector.d.ts +0 -0
  50. package/import/{di → typings/di}/provider_token.d.ts +0 -0
  51. package/import/{di → typings/di}/r3_injector.d.ts +0 -2
  52. package/import/{di → typings/di}/scope.d.ts +0 -0
  53. package/import/{index.d.ts → typings/index.d.ts} +1 -0
  54. package/import/{interface → typings/interface}/lifecycle_hooks.d.ts +0 -0
  55. package/import/{interface → typings/interface}/type.d.ts +0 -11
  56. package/import/{render3 → typings/render3}/definition_factory.d.ts +0 -0
  57. package/import/typings/render3/di.d.ts +12 -0
  58. package/import/{render3 → typings/render3}/error_code.d.ts +0 -0
  59. package/import/{render3 → typings/render3}/errors_di.d.ts +0 -0
  60. package/import/{render3 → typings/render3}/fields.d.ts +0 -0
  61. package/import/{render3 → typings/render3}/instructions/di.d.ts +0 -0
  62. package/import/{render3 → typings/render3}/util/stringify_utils.d.ts +0 -0
  63. package/import/{util → typings/util}/array_utils.d.ts +0 -0
  64. package/import/{util → typings/util}/closure.d.ts +0 -0
  65. package/import/{util → typings/util}/decorators.d.ts +1 -3
  66. package/import/{util → typings/util}/empty.d.ts +0 -0
  67. package/import/{util → typings/util}/property.d.ts +0 -0
  68. package/import/{util → typings/util}/stringify.d.ts +0 -0
  69. package/package.json +8 -4
  70. package/readme.md +6 -0
  71. package/transform/compiler/index.js +15 -6
  72. package/transform/compiler/src/injectable_compiler_2.js +20 -2
  73. package/transform/compiler/src/render3/partial/util.js +20 -2
  74. package/transform/compiler/src/render3/r3_factory.js +20 -2
  75. package/transform/compiler/src/render3/util.js +20 -2
  76. package/transform/compiler/src/render3/view/util.js +20 -2
  77. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +20 -2
  78. package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +20 -2
  79. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +20 -2
  80. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +12 -3
  81. package/transform/compiler-cli/src/ngtsc/imports/index.js +11 -2
  82. package/transform/compiler-cli/src/ngtsc/reflection/index.js +13 -4
  83. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +20 -2
  84. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +20 -2
  85. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +20 -2
  86. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +20 -2
  87. package/transform/compiler-cli/src/ngtsc/transform/index.js +12 -3
  88. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +20 -2
  89. package/transform/compiler-cli/src/ngtsc/translator/index.js +15 -6
  90. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +20 -2
  91. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +20 -2
  92. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +20 -2
  93. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +20 -2
  94. package/transform/index.js +11 -2
  95. package/transform/injectable-transform.js +23 -2
  96. package/transform/node-Iteration.js +4 -2
  97. package/import/di/injector.js +0 -350
  98. package/import/di/null_injector.js +0 -23
  99. package/import/index.js +0 -14
  100. package/import/interface/type.js +0 -21
  101. package/import/render3/definition_factory.js +0 -19
  102. package/import/render3/errors_di.js +0 -18
  103. package/import/render3/fields.js +0 -14
  104. package/import/util/decorators.js +0 -58
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,4 +5,4 @@
6
5
  * Use of this source code is governed by an MIT-style license that can be
7
6
  * found in the LICENSE file at https://angular.io/license
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
8
+ export {};
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,20 +5,17 @@
6
5
  * Use of this source code is governed by an MIT-style license that can be
7
6
  * found in the LICENSE file at https://angular.io/license
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.isClassProvider = exports.isTypeProvider = exports.providerToFactory = exports.R3Injector = exports.createInjectorWithoutInjectorInstances = exports.createInjector = void 0;
11
- const definition_factory_1 = require("../render3/definition_factory");
12
- const array_utils_1 = require("../util/array_utils");
13
- const empty_1 = require("../util/empty");
14
- const stringify_1 = require("../util/stringify");
15
- const forward_ref_1 = require("./forward_ref");
16
- const injection_token_1 = require("./injection_token");
17
- const injector_compatibility_1 = require("./injector_compatibility");
18
- const injector_token_1 = require("./injector_token");
19
- const defs_1 = require("./interface/defs");
20
- const injector_1 = require("./interface/injector");
21
- const null_injector_1 = require("./null_injector");
22
- const scope_1 = require("./scope");
8
+ import { getFactoryDef } from '../render3/definition_factory';
9
+ import { deepForEach, newArray } from '../util/array_utils';
10
+ import { stringify } from '../util/stringify';
11
+ import { resolveForwardRef } from './forward_ref';
12
+ import { InjectionToken } from './injection_token';
13
+ import { catchInjectorError, injectArgs, NG_TEMP_TOKEN_PATH, setCurrentInjector, THROW_IF_NOT_FOUND, USE_VALUE, ɵɵinject, } from './injector_compatibility';
14
+ import { INJECTOR } from './injector_token';
15
+ import { getInjectableDef, } from './interface/defs';
16
+ import { InjectFlags } from './interface/injector';
17
+ import { NullInjector } from './null_injector';
18
+ import { INJECTOR_SCOPE } from './scope';
23
19
  /**
24
20
  * Marker which indicates that a value has not yet been created from the factory function.
25
21
  */
@@ -38,7 +34,7 @@ const CIRCULAR = {};
38
34
  let NULL_INJECTOR = undefined;
39
35
  function getNullInjector() {
40
36
  if (NULL_INJECTOR === undefined) {
41
- NULL_INJECTOR = new null_injector_1.NullInjector();
37
+ NULL_INJECTOR = new NullInjector();
42
38
  }
43
39
  return NULL_INJECTOR;
44
40
  }
@@ -47,22 +43,20 @@ function getNullInjector() {
47
43
  *
48
44
  * @publicApi
49
45
  */
50
- function createInjector(defType, parent = null, additionalProviders = null, name) {
46
+ export function createInjector(defType, parent = null, additionalProviders = null, name) {
51
47
  const injector = createInjectorWithoutInjectorInstances(defType, parent, additionalProviders, name);
52
48
  injector._resolveInjectorDefTypes();
53
49
  return injector;
54
50
  }
55
- exports.createInjector = createInjector;
56
51
  /**
57
52
  * Creates a new injector without eagerly resolving its injector types. Can be used in places
58
53
  * where resolving the injector types immediately can lead to an infinite loop. The injector types
59
54
  * should be resolved at a later point by calling `_resolveInjectorDefTypes`.
60
55
  */
61
- function createInjectorWithoutInjectorInstances(defType, parent = null, additionalProviders = null, name) {
56
+ export function createInjectorWithoutInjectorInstances(defType, parent = null, additionalProviders = null, name) {
62
57
  return new R3Injector(defType, additionalProviders, parent || getNullInjector(), name);
63
58
  }
64
- exports.createInjectorWithoutInjectorInstances = createInjectorWithoutInjectorInstances;
65
- class R3Injector {
59
+ export class R3Injector {
66
60
  constructor(def, additionalProviders, parent, source = null) {
67
61
  this.parent = parent;
68
62
  /**
@@ -80,21 +74,19 @@ class R3Injector {
80
74
  */
81
75
  this.onDestroy = new Set();
82
76
  this._destroyed = false;
83
- const dedupStack = [];
84
77
  // Start off by creating Records for every provider declared in every InjectorType
85
78
  // included transitively in additional providers then do the same for `def`. This order is
86
79
  // important because `def` may include providers that override ones in additionalProviders.
87
80
  additionalProviders &&
88
- array_utils_1.deepForEach(additionalProviders, (provider) => this.processProvider(provider, def, additionalProviders));
89
- array_utils_1.deepForEach([def], (injectorDef) => this.processInjectorType(injectorDef, [], dedupStack));
81
+ deepForEach(additionalProviders, (provider) => this.processProvider(provider, def, additionalProviders));
90
82
  // Make sure the INJECTOR token provides this injector.
91
- this.records.set(injector_token_1.INJECTOR, makeRecord(undefined, this));
83
+ this.records.set(INJECTOR, makeRecord(undefined, this));
92
84
  // Detect whether this injector has the APP_ROOT_SCOPE token and thus should provide
93
85
  // any injectable scoped to APP_ROOT_SCOPE.
94
- const record = this.records.get(scope_1.INJECTOR_SCOPE);
86
+ const record = this.records.get(INJECTOR_SCOPE);
95
87
  this.scope = record != null ? record.value : null;
96
88
  // Source name, used for debugging
97
- this.source = source || (typeof def === 'object' ? null : stringify_1.stringify(def));
89
+ this.source = source || (typeof def === 'object' ? null : stringify(def));
98
90
  }
99
91
  /**
100
92
  * Flag indicating that this injector was previously destroyed.
@@ -123,19 +115,19 @@ class R3Injector {
123
115
  this.injectorDefTypes.clear();
124
116
  }
125
117
  }
126
- get(token, notFoundValue = injector_compatibility_1.THROW_IF_NOT_FOUND, flags = injector_1.InjectFlags.Default) {
118
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
127
119
  this.assertNotDestroyed();
128
120
  // Set the injection context.
129
- const previousInjector = injector_compatibility_1.setCurrentInjector(this);
121
+ const previousInjector = setCurrentInjector(this);
130
122
  try {
131
123
  // Check for the SkipSelf flag.
132
- if (!(flags & injector_1.InjectFlags.SkipSelf)) {
124
+ if (!(flags & InjectFlags.SkipSelf)) {
133
125
  // SkipSelf isn't set, check if the record belongs to this injector.
134
126
  let record = this.records.get(token);
135
127
  if (record === undefined) {
136
128
  // No record, but maybe the token is scoped to this injector. Look for an injectable
137
129
  // def with a scope matching this injector.
138
- const def = couldBeInjectableType(token) && defs_1.getInjectableDef(token);
130
+ const def = couldBeInjectableType(token) && getInjectableDef(token);
139
131
  if (def && this.injectableDefInScope(def)) {
140
132
  // Found an injectable def and it's scoped to this injector. Pretend as if it was here
141
133
  // all along.
@@ -153,29 +145,29 @@ class R3Injector {
153
145
  }
154
146
  // Select the next injector based on the Self flag - if self is set, the next injector is
155
147
  // the NullInjector, otherwise it's the parent.
156
- const nextInjector = !(flags & injector_1.InjectFlags.Self)
148
+ const nextInjector = !(flags & InjectFlags.Self)
157
149
  ? this.parent
158
150
  : getNullInjector();
159
151
  // Set the notFoundValue based on the Optional flag - if optional is set and notFoundValue
160
152
  // is undefined, the value is null, otherwise it's the notFoundValue.
161
153
  notFoundValue =
162
- flags & injector_1.InjectFlags.Optional && notFoundValue === injector_compatibility_1.THROW_IF_NOT_FOUND
154
+ flags & InjectFlags.Optional && notFoundValue === THROW_IF_NOT_FOUND
163
155
  ? null
164
156
  : notFoundValue;
165
157
  return nextInjector.get(token, notFoundValue);
166
158
  }
167
159
  catch (e) {
168
160
  if (e.name === 'NullInjectorError') {
169
- const path = (e[injector_compatibility_1.NG_TEMP_TOKEN_PATH] =
170
- e[injector_compatibility_1.NG_TEMP_TOKEN_PATH] || []);
171
- path.unshift(stringify_1.stringify(token));
161
+ const path = (e[NG_TEMP_TOKEN_PATH] =
162
+ e[NG_TEMP_TOKEN_PATH] || []);
163
+ path.unshift(stringify(token));
172
164
  if (previousInjector) {
173
165
  // We still have a parent injector, keep throwing
174
166
  throw e;
175
167
  }
176
168
  else {
177
169
  // Format & throw the final error message when we don't have any previous injector
178
- return injector_compatibility_1.catchInjectorError(e, token, 'R3InjectorError', this.source);
170
+ return catchInjectorError(e, token, 'R3InjectorError', this.source);
179
171
  }
180
172
  }
181
173
  else {
@@ -184,7 +176,7 @@ class R3Injector {
184
176
  }
185
177
  finally {
186
178
  // Lastly, restore the previous injection context.
187
- injector_compatibility_1.setCurrentInjector(previousInjector);
179
+ setCurrentInjector(previousInjector);
188
180
  }
189
181
  }
190
182
  /** @internal */
@@ -193,7 +185,7 @@ class R3Injector {
193
185
  }
194
186
  toString() {
195
187
  const tokens = [], records = this.records;
196
- records.forEach((v, token) => tokens.push(stringify_1.stringify(token)));
188
+ records.forEach((v, token) => tokens.push(stringify(token)));
197
189
  return `R3Injector[${tokens.join(', ')}]`;
198
190
  }
199
191
  assertNotDestroyed() {
@@ -210,101 +202,16 @@ class R3Injector {
210
202
  * to be processed. This allows us to process providers of injector types after all imports of
211
203
  * an injector definition are processed. (following View Engine semantics: see FW-1349)
212
204
  */
213
- processInjectorType(defOrWrappedDef, parents, dedupStack) {
214
- defOrWrappedDef = forward_ref_1.resolveForwardRef(defOrWrappedDef);
215
- if (!defOrWrappedDef)
216
- return false;
217
- // Either the defOrWrappedDef is an InjectorType (with injector def) or an
218
- // InjectorDefTypeWithProviders (aka ModuleWithProviders). Detecting either is a megamorphic
219
- // read, so care is taken to only do the read once.
220
- // First attempt to read the injector def (`ɵinj`).
221
- let def = defs_1.getInjectorDef(defOrWrappedDef);
222
- // If that's not present, then attempt to read ngModule from the InjectorDefTypeWithProviders.
223
- const ngModule = (def == null &&
224
- defOrWrappedDef.ngModule) ||
225
- undefined;
226
- // Determine the InjectorType. In the case where `defOrWrappedDef` is an `InjectorType`,
227
- // then this is easy. In the case of an InjectorDefTypeWithProviders, then the definition type
228
- // is the `ngModule`.
229
- const defType = ngModule === undefined
230
- ? defOrWrappedDef
231
- : ngModule;
232
- // Check for circular dependencies.
233
- // if (ngDevMode && parents.indexOf(defType) !== -1) {
234
- // const defName = stringify(defType);
235
- // const path = parents.map(stringify);
236
- // throwCyclicDependencyError(defName, path);
237
- // }
238
- // Check for multiple imports of the same module
239
- const isDuplicate = dedupStack.indexOf(defType) !== -1;
240
- // Finally, if defOrWrappedType was an `InjectorDefTypeWithProviders`, then the actual
241
- // `InjectorDef` is on its `ngModule`.
242
- if (ngModule !== undefined) {
243
- def = defs_1.getInjectorDef(ngModule);
244
- }
245
- // If no definition was found, it might be from exports. Remove it.
246
- if (def == null) {
247
- return false;
248
- }
249
- // Add providers in the same way that @NgModule resolution did:
250
- // First, include providers from any imports.
251
- if (def.imports != null && !isDuplicate) {
252
- // Before processing defType's imports, add it to the set of parents. This way, if it ends
253
- // up deeply importing itself, this can be detected.
254
- // ngDevMode && parents.push(defType);
255
- // Add it to the set of dedups. This way we can detect multiple imports of the same module
256
- dedupStack.push(defType);
257
- let importTypesWithProviders;
258
- try {
259
- array_utils_1.deepForEach(def.imports, (imported) => {
260
- if (this.processInjectorType(imported, parents, dedupStack)) {
261
- if (importTypesWithProviders === undefined)
262
- importTypesWithProviders = [];
263
- // If the processed import is an injector type with providers, we store it in the
264
- // list of import types with providers, so that we can process those afterwards.
265
- importTypesWithProviders.push(imported);
266
- }
267
- });
268
- }
269
- finally {
270
- // Remove it from the parents set when finished.
271
- // ngDevMode && parents.pop();
272
- }
273
- // Imports which are declared with providers (TypeWithProviders) need to be processed
274
- // after all imported modules are processed. This is similar to how View Engine
275
- // processes/merges module imports in the metadata resolver. See: FW-1349.
276
- if (importTypesWithProviders !== undefined) {
277
- for (let i = 0; i < importTypesWithProviders.length; i++) {
278
- const { ngModule, providers } = importTypesWithProviders[i];
279
- array_utils_1.deepForEach(providers, (provider) => this.processProvider(provider, ngModule, providers || empty_1.EMPTY_ARRAY));
280
- }
281
- }
282
- }
283
- // Track the InjectorType and add a provider for it. It's important that this is done after the
284
- // def's imports.
285
- this.injectorDefTypes.add(defType);
286
- const factory = definition_factory_1.getFactoryDef(defType) || (() => new defType());
287
- this.records.set(defType, makeRecord(factory, NOT_YET));
288
- // Next, include providers listed on the definition itself.
289
- const defProviders = def.providers;
290
- if (defProviders != null && !isDuplicate) {
291
- const injectorType = defOrWrappedDef;
292
- array_utils_1.deepForEach(defProviders, (provider) => this.processProvider(provider, injectorType, defProviders));
293
- }
294
- return (ngModule !== undefined &&
295
- defOrWrappedDef.providers !==
296
- undefined);
297
- }
298
205
  /**
299
206
  * Process a `SingleProvider` and add it.
300
207
  */
301
208
  processProvider(provider, ngModuleType, providers) {
302
209
  // Determine the token from the provider. Either it's its own token, or has a {provide: ...}
303
210
  // property.
304
- provider = forward_ref_1.resolveForwardRef(provider);
211
+ provider = resolveForwardRef(provider);
305
212
  let token = isTypeProvider(provider)
306
213
  ? provider
307
- : forward_ref_1.resolveForwardRef(provider && provider.provide);
214
+ : resolveForwardRef(provider && provider.provide);
308
215
  // Construct a `Record` for the provider.
309
216
  const record = providerToRecord(provider, ngModuleType, providers);
310
217
  if (!isTypeProvider(provider) && provider.multi === true) {
@@ -319,7 +226,7 @@ class R3Injector {
319
226
  }
320
227
  else {
321
228
  multiRecord = makeRecord(undefined, NOT_YET, true);
322
- multiRecord.factory = () => injector_compatibility_1.injectArgs(multiRecord.multi);
229
+ multiRecord.factory = () => injectArgs(multiRecord.multi);
323
230
  this.records.set(token, multiRecord);
324
231
  }
325
232
  token = provider;
@@ -352,7 +259,7 @@ class R3Injector {
352
259
  if (!def.providedIn) {
353
260
  return false;
354
261
  }
355
- const providedIn = forward_ref_1.resolveForwardRef(def.providedIn);
262
+ const providedIn = resolveForwardRef(def.providedIn);
356
263
  if (typeof providedIn === 'string') {
357
264
  return providedIn === 'any' || providedIn === this.scope;
358
265
  }
@@ -361,18 +268,17 @@ class R3Injector {
361
268
  }
362
269
  }
363
270
  }
364
- exports.R3Injector = R3Injector;
365
271
  function injectableDefOrInjectorDefFactory(token) {
366
272
  // Most tokens will have an injectable def directly on them, which specifies a factory directly.
367
- const injectableDef = defs_1.getInjectableDef(token);
368
- const factory = injectableDef !== null ? injectableDef.factory : definition_factory_1.getFactoryDef(token);
273
+ const injectableDef = getInjectableDef(token);
274
+ const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
369
275
  if (factory !== null) {
370
276
  return factory;
371
277
  }
372
278
  // InjectionTokens should have an injectable def (ɵprov) and thus should be handled above.
373
279
  // If it's missing that, it's an error.
374
- if (token instanceof injection_token_1.InjectionToken) {
375
- throw new Error(`Token ${stringify_1.stringify(token)} is missing a ɵprov definition.`);
280
+ if (token instanceof InjectionToken) {
281
+ throw new Error(`Token ${stringify(token)} is missing a ɵprov definition.`);
376
282
  }
377
283
  // Undecorated types can sometimes be created if they have no constructor arguments.
378
284
  if (token instanceof Function) {
@@ -385,8 +291,8 @@ function getUndecoratedInjectableFactory(token) {
385
291
  // If the token has parameters then it has dependencies that we cannot resolve implicitly.
386
292
  const paramLength = token.length;
387
293
  if (paramLength > 0) {
388
- const args = array_utils_1.newArray(paramLength, '?');
389
- throw new Error(`Can't resolve all parameters for ${stringify_1.stringify(token)}: (${args.join(', ')}).`);
294
+ const args = newArray(paramLength, '?');
295
+ throw new Error(`Can't resolve all parameters for ${stringify(token)}: (${args.join(', ')}).`);
390
296
  }
391
297
  // The constructor function appears to have no parameters.
392
298
  // This might be because it inherits from a super-class. In which case, use an injectable
@@ -409,41 +315,40 @@ function providerToRecord(provider, ngModuleType, providers) {
409
315
  *
410
316
  * @param provider provider to convert to factory
411
317
  */
412
- function providerToFactory(provider, ngModuleType, providers) {
318
+ export function providerToFactory(provider, ngModuleType, providers) {
413
319
  let factory = undefined;
414
320
  if (isTypeProvider(provider)) {
415
- const unwrappedProvider = forward_ref_1.resolveForwardRef(provider);
416
- return (definition_factory_1.getFactoryDef(unwrappedProvider) ||
321
+ const unwrappedProvider = resolveForwardRef(provider);
322
+ return (getFactoryDef(unwrappedProvider) ||
417
323
  injectableDefOrInjectorDefFactory(unwrappedProvider));
418
324
  }
419
325
  else {
420
326
  if (isValueProvider(provider)) {
421
- factory = () => forward_ref_1.resolveForwardRef(provider.useValue);
327
+ factory = () => resolveForwardRef(provider.useValue);
422
328
  }
423
329
  else if (isFactoryProvider(provider)) {
424
- factory = () => provider.useFactory(...injector_compatibility_1.injectArgs(provider.deps || []));
330
+ factory = () => provider.useFactory(...injectArgs(provider.deps || []));
425
331
  }
426
332
  else if (isExistingProvider(provider)) {
427
- factory = () => injector_compatibility_1.ɵɵinject(forward_ref_1.resolveForwardRef(provider.useExisting));
333
+ factory = () => ɵɵinject(resolveForwardRef(provider.useExisting));
428
334
  }
429
335
  else {
430
- const classRef = forward_ref_1.resolveForwardRef(provider &&
336
+ const classRef = resolveForwardRef(provider &&
431
337
  (provider.useClass ||
432
338
  provider.provide));
433
339
  // if (ngDevMode && !classRef) {
434
340
  // throwInvalidProviderError(ngModuleType, providers, provider);
435
341
  // }
436
342
  if (hasDeps(provider)) {
437
- factory = () => new classRef(...injector_compatibility_1.injectArgs(provider.deps));
343
+ factory = () => new classRef(...injectArgs(provider.deps));
438
344
  }
439
345
  else {
440
- return (definition_factory_1.getFactoryDef(classRef) || injectableDefOrInjectorDefFactory(classRef));
346
+ return (getFactoryDef(classRef) || injectableDefOrInjectorDefFactory(classRef));
441
347
  }
442
348
  }
443
349
  }
444
350
  return factory;
445
351
  }
446
- exports.providerToFactory = providerToFactory;
447
352
  function makeRecord(factory, value, multi = false) {
448
353
  return {
449
354
  factory: factory,
@@ -452,7 +357,7 @@ function makeRecord(factory, value, multi = false) {
452
357
  };
453
358
  }
454
359
  function isValueProvider(value) {
455
- return value !== null && typeof value == 'object' && injector_compatibility_1.USE_VALUE in value;
360
+ return value !== null && typeof value == 'object' && USE_VALUE in value;
456
361
  }
457
362
  function isExistingProvider(value) {
458
363
  return !!(value && value.useExisting);
@@ -460,14 +365,9 @@ function isExistingProvider(value) {
460
365
  function isFactoryProvider(value) {
461
366
  return !!(value && value.useFactory);
462
367
  }
463
- function isTypeProvider(value) {
368
+ export function isTypeProvider(value) {
464
369
  return typeof value === 'function';
465
370
  }
466
- exports.isTypeProvider = isTypeProvider;
467
- function isClassProvider(value) {
468
- return !!value.useClass;
469
- }
470
- exports.isClassProvider = isClassProvider;
471
371
  function hasDeps(value) {
472
372
  return !!value.deps;
473
373
  }
@@ -478,5 +378,5 @@ function hasOnDestroy(value) {
478
378
  }
479
379
  function couldBeInjectableType(value) {
480
380
  return (typeof value === 'function' ||
481
- (typeof value === 'object' && value instanceof injection_token_1.InjectionToken));
381
+ (typeof value === 'object' && value instanceof InjectionToken));
482
382
  }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,12 +5,10 @@
6
5
  * Use of this source code is governed by an MIT-style license that can be
7
6
  * found in the LICENSE file at https://angular.io/license
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.INJECTOR_SCOPE = void 0;
11
- const injection_token_1 = require("./injection_token");
8
+ import { InjectionToken } from "./injection_token";
12
9
  /**
13
10
  * An internal token whose presence in an injector indicates that the injector should treat itself
14
11
  * as a root scoped injector when processing requests for unknown tokens which may indicate
15
12
  * they are provided in the root scope.
16
13
  */
17
- exports.INJECTOR_SCOPE = new injection_token_1.InjectionToken("Set Injector scope.");
14
+ export const INJECTOR_SCOPE = new InjectionToken("Set Injector scope.");
@@ -0,0 +1,12 @@
1
+ export * from './decorator/injectable';
2
+ export * from './di/metadata';
3
+ export * from './di/r3_injector';
4
+ export * from './di/interface/defs';
5
+ export * from './di/injector_compatibility';
6
+ export * from './di/injection_token';
7
+ export * from './di/null_injector';
8
+ export * from './di/injector';
9
+ export * from './di/interface/injector';
10
+ export * from './di/scope';
11
+ export * from './render3/instructions/di';
12
+ export * from './render3/di';
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,4 +5,4 @@
6
5
  * Use of this source code is governed by an MIT-style license that can be
7
6
  * found in the LICENSE file at https://angular.io/license
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
8
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { NG_FACTORY_DEF } from './fields';
9
+ export function getFactoryDef(type, throwNotFound) {
10
+ const hasFactoryDef = type.hasOwnProperty(NG_FACTORY_DEF);
11
+ // if (!hasFactoryDef && throwNotFound === true && ngDevMode) {
12
+ // throw new Error(`Type ${stringify(type)} does not have 'ɵfac' property.`);
13
+ // }
14
+ return hasFactoryDef ? type[NG_FACTORY_DEF] : null;
15
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { isForwardRef, resolveForwardRef } from '../di/forward_ref';
9
+ import { noSideEffects } from '../util/closure';
10
+ import { getFactoryDef } from './definition_factory';
11
+ import { NG_FACTORY_DEF } from './fields';
12
+ /**
13
+ * @codeGenApi
14
+ */
15
+ export function ɵɵgetInheritedFactory(type) {
16
+ return noSideEffects(() => {
17
+ const ownConstructor = type.prototype.constructor;
18
+ const ownFactory = ownConstructor[NG_FACTORY_DEF] || getFactoryOf(ownConstructor);
19
+ const objectPrototype = Object.prototype;
20
+ let parent = Object.getPrototypeOf(type.prototype).constructor;
21
+ // Go up the prototype until we hit `Object`.
22
+ while (parent && parent !== objectPrototype) {
23
+ const factory = parent[NG_FACTORY_DEF] || getFactoryOf(parent);
24
+ // If we hit something that has a factory and the factory isn't the same as the type,
25
+ // we've found the inherited factory. Note the check that the factory isn't the type's
26
+ // own factory is redundant in most cases, but if the user has custom decorators on the
27
+ // class, this lookup will start one level down in the prototype chain, causing us to
28
+ // find the own factory first and potentially triggering an infinite loop downstream.
29
+ if (factory && factory !== ownFactory) {
30
+ return factory;
31
+ }
32
+ parent = Object.getPrototypeOf(parent);
33
+ }
34
+ // There is no factory defined. Either this was improper usage of inheritance
35
+ // (no Angular decorator on the superclass) or there is no constructor at all
36
+ // in the inheritance chain. Since the two cases cannot be distinguished, the
37
+ // latter has to be assumed.
38
+ return (t) => new t();
39
+ });
40
+ }
41
+ function getFactoryOf(type) {
42
+ if (isForwardRef(type)) {
43
+ return () => {
44
+ const factory = getFactoryOf(resolveForwardRef(type));
45
+ return factory && factory();
46
+ };
47
+ }
48
+ return getFactoryDef(type);
49
+ }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,18 +5,15 @@
6
5
  * Use of this source code is governed by an MIT-style license that can be
7
6
  * found in the LICENSE file at https://angular.io/license
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.formatRuntimeError = exports.RuntimeError = void 0;
11
- class RuntimeError extends Error {
8
+ export class RuntimeError extends Error {
12
9
  constructor(code, message) {
13
10
  super(formatRuntimeError(code, message));
14
11
  this.code = code;
15
12
  }
16
13
  }
17
- exports.RuntimeError = RuntimeError;
18
14
  /* tslint:enable:no-toplevel-property-access */
19
15
  /** Called to format a runtime error */
20
- function formatRuntimeError(code, message) {
16
+ export function formatRuntimeError(code, message) {
21
17
  const fullCode = code ? `NG0${code}: ` : '';
22
18
  let errorMessage = `${fullCode}${message}`;
23
19
  // Some runtime errors are still thrown without `ngDevMode` (for example
@@ -31,4 +27,3 @@ function formatRuntimeError(code, message) {
31
27
  // }
32
28
  return errorMessage;
33
29
  }
34
- exports.formatRuntimeError = formatRuntimeError;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { RuntimeError } from './error_code';
9
+ import { stringifyForError } from './util/stringify_utils';
10
+ /** Throws an error when a token is not found in DI. */
11
+ export function throwProviderNotFoundError(token, injectorName) {
12
+ const injectorDetails = injectorName ? ` in ${injectorName}` : '';
13
+ throw new RuntimeError("201" /* PROVIDER_NOT_FOUND */, `No provider for ${stringifyForError(token)} found${injectorDetails}`);
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { getClosureSafeProperty } from '../util/property';
9
+ export const NG_FACTORY_DEF = getClosureSafeProperty({
10
+ ɵfac: getClosureSafeProperty,
11
+ });
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,8 +5,6 @@
6
5
  * Use of this source code is governed by an MIT-style license that can be
7
6
  * found in the LICENSE file at https://angular.io/license
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ɵɵinvalidFactory = void 0;
11
8
  /**
12
9
  * Throws an error indicating that a factory function could not be generated by the compiler for a
13
10
  * particular class.
@@ -20,8 +17,7 @@ exports.ɵɵinvalidFactory = void 0;
20
17
  *
21
18
  * @codeGenApi
22
19
  */
23
- function ɵɵinvalidFactory() {
20
+ export function ɵɵinvalidFactory() {
24
21
  const msg = 'invalid';
25
22
  throw new Error(msg);
26
23
  }
27
- exports.ɵɵinvalidFactory = ɵɵinvalidFactory;