static-injector 2.1.0 → 2.2.0

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 (108) hide show
  1. package/import/commonjs/index.js +403 -211
  2. package/import/{es2015 → es2022}/di/create_injector.js +5 -3
  3. package/import/{es2015 → es2022}/di/forward_ref.js +32 -5
  4. package/import/{es2015 → es2022}/di/injection_token.js +20 -11
  5. package/import/{es2015 → es2022}/di/injector.js +15 -16
  6. package/import/{es2015 → es2022}/di/injector_compatibility.js +27 -13
  7. package/import/{es2015 → es2022}/di/injector_token.js +3 -3
  8. package/import/{es2015 → es2022}/di/interface/defs.js +22 -27
  9. package/import/{es2015 → es2022}/di/interface/injector.js +1 -1
  10. package/import/{es2015 → es2022}/di/interface/provider.js +3 -1
  11. package/import/{es2015 → es2022}/di/null_injector.js +3 -3
  12. package/import/es2022/di/provider_collection.js +104 -0
  13. package/import/{es2015 → es2022}/di/r3_injector.js +71 -37
  14. package/import/es2022/error_details_base_url.js +19 -0
  15. package/import/es2022/errors.js +44 -0
  16. package/import/es2022/interface/type.js +21 -0
  17. package/import/{es2015 → es2022}/render3/definition_factory.js +2 -3
  18. package/import/{es2015 → es2022}/render3/error_code.js +1 -0
  19. package/import/{es2015 → es2022}/render3/errors_di.js +2 -3
  20. package/import/es2022/render3/fields.js +22 -0
  21. package/import/{es2015 → es2022}/render3/instructions/di.js +0 -7
  22. package/import/{es2015 → es2022}/render3/util/stringify_utils.js +5 -5
  23. package/import/{es2015 → es2022}/util/array_utils.js +0 -7
  24. package/import/es2022/util/decorators.js +53 -0
  25. package/import/{es2015 → es2022}/util/empty.js +4 -0
  26. package/import/{es2015 → es2022}/util/stringify.js +5 -5
  27. package/import/{fesm2015 → fesm2022}/index.js +399 -209
  28. package/import/typings/di/create_injector.d.ts +3 -5
  29. package/import/typings/di/forward_ref.d.ts +30 -3
  30. package/import/typings/di/inject_switch.d.ts +1 -1
  31. package/import/typings/di/injectable.d.ts +4 -3
  32. package/import/typings/di/injection_token.d.ts +21 -6
  33. package/import/typings/di/injector.d.ts +19 -3
  34. package/import/typings/di/injector_compatibility.d.ts +12 -5
  35. package/import/typings/di/injector_token.d.ts +2 -2
  36. package/import/typings/di/interface/defs.d.ts +17 -9
  37. package/import/typings/di/interface/injector.d.ts +2 -2
  38. package/import/typings/di/interface/provider.d.ts +64 -4
  39. package/import/typings/di/metadata.d.ts +4 -4
  40. package/import/typings/di/null_injector.d.ts +1 -1
  41. package/import/typings/di/provider_collection.d.ts +53 -11
  42. package/import/typings/di/provider_token.d.ts +2 -2
  43. package/import/typings/di/r3_injector.d.ts +11 -14
  44. package/import/typings/di/scope.d.ts +1 -1
  45. package/import/typings/error_details_base_url.d.ts +19 -0
  46. package/import/typings/errors.d.ts +114 -0
  47. package/import/typings/interface/type.d.ts +45 -0
  48. package/import/typings/render3/errors_di.d.ts +7 -0
  49. package/import/typings/render3/fields.d.ts +9 -0
  50. package/import/typings/render3/instructions/di.d.ts +0 -7
  51. package/import/typings/util/array_utils.d.ts +15 -7
  52. package/import/typings/util/decorators.d.ts +3 -1
  53. package/import/typings/util/empty.d.ts +1 -0
  54. package/package.json +7 -7
  55. package/readme.md +4 -1
  56. package/transform/compiler/src/injectable_compiler_2.d.ts +0 -1
  57. package/transform/compiler/src/injectable_compiler_2.js +31 -16
  58. package/transform/compiler/src/output/output_ast.d.ts +53 -10
  59. package/transform/compiler/src/output/output_ast.js +211 -12
  60. package/transform/compiler/src/parse_util.js +10 -0
  61. package/transform/compiler/src/render3/partial/api.js +1 -1
  62. package/transform/compiler/src/render3/r3_factory.d.ts +0 -8
  63. package/transform/compiler/src/render3/r3_factory.js +5 -4
  64. package/transform/compiler/src/render3/r3_identifiers.js +37 -37
  65. package/transform/compiler/src/render3/view/util.js +1 -3
  66. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +2 -4
  67. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +1 -0
  68. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +1 -1
  69. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +5 -9
  70. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +2 -1
  71. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +12 -8
  72. package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +2 -2
  73. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +8 -4
  74. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +1 -1
  75. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +1 -2
  76. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +24 -173
  77. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +2 -51
  78. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +5 -3
  79. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +5 -10
  80. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +5 -23
  81. package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -21
  82. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +1 -2
  83. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +7 -0
  84. package/transform/compiler-cli/src/ngtsc/translator/src/context.js +1 -0
  85. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -2
  86. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +1 -0
  87. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +10 -4
  88. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +2 -1
  89. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +20 -16
  90. package/transform/injectable-transform.d.ts +2 -2
  91. package/transform/injectable-transform.js +32 -6
  92. package/import/es2015/di/provider_collection.js +0 -49
  93. package/import/es2015/interface/type.js +0 -8
  94. package/import/es2015/render3/fields.js +0 -11
  95. package/import/es2015/util/decorators.js +0 -30
  96. /package/import/{es2015 → es2022}/di/initializer_token.js +0 -0
  97. /package/import/{es2015 → es2022}/di/inject_switch.js +0 -0
  98. /package/import/{es2015 → es2022}/di/injectable.js +0 -0
  99. /package/import/{es2015 → es2022}/di/injector_marker.js +0 -0
  100. /package/import/{es2015 → es2022}/di/internal_tokens.js +0 -0
  101. /package/import/{es2015 → es2022}/di/metadata.js +0 -0
  102. /package/import/{es2015 → es2022}/di/provider_token.js +0 -0
  103. /package/import/{es2015 → es2022}/di/scope.js +0 -0
  104. /package/import/{es2015 → es2022}/index.js +0 -0
  105. /package/import/{es2015 → es2022}/interface/lifecycle_hooks.js +0 -0
  106. /package/import/{es2015 → es2022}/render3/di.js +0 -0
  107. /package/import/{es2015 → es2022}/util/closure.js +0 -0
  108. /package/import/{es2015 → es2022}/util/property.js +0 -0
@@ -5,20 +5,24 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
+ import { RuntimeError } from '../errors';
8
9
  import { getFactoryDef } from '../render3/definition_factory';
10
+ import { NG_ENV_ID } from '../render3/fields';
9
11
  import { newArray } from '../util/array_utils';
10
12
  import { EMPTY_ARRAY } from '../util/empty';
11
13
  import { stringify } from '../util/stringify';
12
14
  import { resolveForwardRef } from './forward_ref';
13
15
  import { ENVIRONMENT_INITIALIZER } from './initializer_token';
16
+ import { setInjectImplementation } from './inject_switch';
14
17
  import { InjectionToken } from './injection_token';
15
- import { catchInjectorError, convertToBitFlags, injectArgs, NG_TEMP_TOKEN_PATH, setCurrentInjector, THROW_IF_NOT_FOUND, USE_VALUE, ɵɵinject, } from './injector_compatibility';
18
+ import { catchInjectorError, convertToBitFlags, injectArgs, NG_TEMP_TOKEN_PATH, setCurrentInjector, THROW_IF_NOT_FOUND, ɵɵinject, } from './injector_compatibility';
16
19
  import { INJECTOR } from './injector_token';
17
- import { setInjectImplementation } from './inject_switch';
18
20
  import { getInheritedInjectableDef, getInjectableDef, } from './interface/defs';
19
21
  import { InjectFlags } from './interface/injector';
22
+ import { isEnvironmentProviders, } from './interface/provider';
20
23
  import { INJECTOR_DEF_TYPES } from './internal_tokens';
21
24
  import { NullInjector } from './null_injector';
25
+ import { isExistingProvider, isFactoryProvider, isTypeProvider, isValueProvider, } from './provider_collection';
22
26
  import { INJECTOR_SCOPE } from './scope';
23
27
  /**
24
28
  * Marker which indicates that a value has not yet been created from the factory function.
@@ -49,29 +53,33 @@ export function getNullInjector() {
49
53
  export class EnvironmentInjector {
50
54
  }
51
55
  export class R3Injector extends EnvironmentInjector {
56
+ parent;
57
+ source;
58
+ scopes;
59
+ /**
60
+ * Map of tokens to records which contain the instances of those tokens.
61
+ * - `null` value implies that we don't have the record. Used by tree-shakable injectors
62
+ * to prevent further searches.
63
+ */
64
+ records = new Map();
65
+ /**
66
+ * Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
67
+ */
68
+ _ngOnDestroyHooks = new Set();
69
+ _onDestroyHooks = [];
52
70
  /**
53
71
  * Flag indicating that this injector was previously destroyed.
54
72
  */
55
73
  get destroyed() {
56
74
  return this._destroyed;
57
75
  }
76
+ _destroyed = false;
77
+ injectorDefTypes;
58
78
  constructor(providers, parent, source, scopes) {
59
79
  super();
60
80
  this.parent = parent;
61
81
  this.source = source;
62
82
  this.scopes = scopes;
63
- /**
64
- * Map of tokens to records which contain the instances of those tokens.
65
- * - `null` value implies that we don't have the record. Used by tree-shakable injectors
66
- * to prevent further searches.
67
- */
68
- this.records = new Map();
69
- /**
70
- * Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
71
- */
72
- this._ngOnDestroyHooks = new Set();
73
- this._onDestroyHooks = [];
74
- this._destroyed = false;
75
83
  // Start off by creating Records for every provider.
76
84
  forEachSingleProvider(providers, (provider) => this.processProvider(provider));
77
85
  // Make sure the INJECTOR token provides this injector.
@@ -103,7 +111,11 @@ export class R3Injector extends EnvironmentInjector {
103
111
  for (const service of this._ngOnDestroyHooks) {
104
112
  service.ngOnDestroy();
105
113
  }
106
- for (const hook of this._onDestroyHooks) {
114
+ const onDestroyHooks = this._onDestroyHooks;
115
+ // Reset the _onDestroyHooks array before iterating over it to prevent hooks that unregister
116
+ // themselves from mutating the array during iteration.
117
+ this._onDestroyHooks = [];
118
+ for (const hook of onDestroyHooks) {
107
119
  hook();
108
120
  }
109
121
  }
@@ -112,16 +124,19 @@ export class R3Injector extends EnvironmentInjector {
112
124
  this.records.clear();
113
125
  this._ngOnDestroyHooks.clear();
114
126
  this.injectorDefTypes.clear();
115
- this._onDestroyHooks.length = 0;
116
127
  }
117
128
  }
118
129
  onDestroy(callback) {
130
+ this.assertNotDestroyed();
119
131
  this._onDestroyHooks.push(callback);
132
+ return () => this.removeOnDestroy(callback);
120
133
  }
121
134
  runInContext(fn) {
122
135
  this.assertNotDestroyed();
123
136
  const previousInjector = setCurrentInjector(this);
124
137
  const previousInjectImplementation = setInjectImplementation(undefined);
138
+ if (false) {
139
+ }
125
140
  try {
126
141
  return fn();
127
142
  }
@@ -132,8 +147,13 @@ export class R3Injector extends EnvironmentInjector {
132
147
  }
133
148
  get(token, notFoundValue = THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
134
149
  this.assertNotDestroyed();
150
+ if (token.hasOwnProperty(NG_ENV_ID)) {
151
+ return token[NG_ENV_ID](this);
152
+ }
135
153
  flags = convertToBitFlags(flags);
136
154
  // Set the injection context.
155
+ if (false) {
156
+ }
137
157
  const previousInjector = setCurrentInjector(this);
138
158
  const previousInjectImplementation = setInjectImplementation(undefined);
139
159
  try {
@@ -201,8 +221,12 @@ export class R3Injector extends EnvironmentInjector {
201
221
  resolveInjectorInitializers() {
202
222
  const previousInjector = setCurrentInjector(this);
203
223
  const previousInjectImplementation = setInjectImplementation(undefined);
224
+ if (false) {
225
+ }
204
226
  try {
205
227
  const initializers = this.get(ENVIRONMENT_INITIALIZER.multi, EMPTY_ARRAY, InjectFlags.Self);
228
+ if (false) {
229
+ }
206
230
  for (const initializer of initializers) {
207
231
  initializer();
208
232
  }
@@ -222,7 +246,7 @@ export class R3Injector extends EnvironmentInjector {
222
246
  }
223
247
  assertNotDestroyed() {
224
248
  if (this._destroyed) {
225
- throw new Error('Injector has already been destroyed.');
249
+ throw new RuntimeError(205 /* RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED */, null);
226
250
  }
227
251
  }
228
252
  /**
@@ -237,12 +261,16 @@ export class R3Injector extends EnvironmentInjector {
237
261
  : resolveForwardRef(provider && provider.provide);
238
262
  // Construct a `Record` for the provider.
239
263
  const record = providerToRecord(provider);
264
+ if (false) {
265
+ }
240
266
  if (!isTypeProvider(provider) && provider.multi === true) {
241
267
  // If the provider indicates that it's a multi-provider, process it specially.
242
268
  // First check whether it's been defined already.
243
269
  let multiRecord = this.records.get(token);
244
270
  if (multiRecord) {
245
271
  // It has. Throw a nice error if
272
+ if (false) {
273
+ }
246
274
  }
247
275
  else {
248
276
  multiRecord = makeRecord(undefined, NOT_YET, true);
@@ -254,13 +282,21 @@ export class R3Injector extends EnvironmentInjector {
254
282
  }
255
283
  else {
256
284
  const existing = this.records.get(token);
285
+ if (false) {
286
+ }
257
287
  }
258
288
  this.records.set(token, record);
259
289
  }
260
290
  hydrate(token, record) {
261
- if (record.value === NOT_YET) {
291
+ if (false) {
292
+ }
293
+ else if (record.value === NOT_YET) {
262
294
  record.value = CIRCULAR;
263
- record.value = record.factory();
295
+ if (false) {
296
+ }
297
+ else {
298
+ record.value = record.factory();
299
+ }
264
300
  }
265
301
  if (typeof record.value === 'object' &&
266
302
  record.value &&
@@ -281,6 +317,12 @@ export class R3Injector extends EnvironmentInjector {
281
317
  return this.injectorDefTypes.has(providedIn);
282
318
  }
283
319
  }
320
+ removeOnDestroy(callback) {
321
+ const destroyCBIdx = this._onDestroyHooks.indexOf(callback);
322
+ if (destroyCBIdx !== -1) {
323
+ this._onDestroyHooks.splice(destroyCBIdx, 1);
324
+ }
325
+ }
284
326
  }
285
327
  function injectableDefOrInjectorDefFactory(token) {
286
328
  // Most tokens will have an injectable def directly on them, which specifies a factory directly.
@@ -292,21 +334,21 @@ function injectableDefOrInjectorDefFactory(token) {
292
334
  // InjectionTokens should have an injectable def (ɵprov) and thus should be handled above.
293
335
  // If it's missing that, it's an error.
294
336
  if (token instanceof InjectionToken) {
295
- throw new Error(`Token ${stringify(token)} is missing a ɵprov definition.`);
337
+ throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
296
338
  }
297
339
  // Undecorated types can sometimes be created if they have no constructor arguments.
298
340
  if (token instanceof Function) {
299
341
  return getUndecoratedInjectableFactory(token);
300
342
  }
301
343
  // There was no way to resolve a factory for this token.
302
- throw new Error('unreachable');
344
+ throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
303
345
  }
304
346
  function getUndecoratedInjectableFactory(token) {
305
347
  // If the token has parameters then it has dependencies that we cannot resolve implicitly.
306
348
  const paramLength = token.length;
307
349
  if (paramLength > 0) {
308
350
  const args = newArray(paramLength, '?');
309
- throw new Error(`Can't resolve all parameters for ${stringify(token)}: (${args.join(', ')}).`);
351
+ throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, null);
310
352
  }
311
353
  // The constructor function appears to have no parameters.
312
354
  // This might be because it inherits from a super-class. In which case, use an injectable
@@ -337,6 +379,8 @@ function providerToRecord(provider) {
337
379
  */
338
380
  export function providerToFactory(provider, ngModuleType, providers) {
339
381
  let factory = undefined;
382
+ if (false) {
383
+ }
340
384
  if (isTypeProvider(provider)) {
341
385
  const unwrappedProvider = resolveForwardRef(provider);
342
386
  return (getFactoryDef(unwrappedProvider) ||
@@ -356,9 +400,8 @@ export function providerToFactory(provider, ngModuleType, providers) {
356
400
  const classRef = resolveForwardRef(provider &&
357
401
  (provider.useClass ||
358
402
  provider.provide));
359
- // if (ngDevMode && !classRef) {
360
- // throwInvalidProviderError(ngModuleType, providers, provider);
361
- // }
403
+ if (false) {
404
+ }
362
405
  if (hasDeps(provider)) {
363
406
  factory = () => new classRef(...injectArgs(provider.deps));
364
407
  }
@@ -376,18 +419,6 @@ function makeRecord(factory, value, multi = false) {
376
419
  multi: multi ? [] : undefined,
377
420
  };
378
421
  }
379
- function isValueProvider(value) {
380
- return value !== null && typeof value == 'object' && USE_VALUE in value;
381
- }
382
- function isExistingProvider(value) {
383
- return !!(value && value.useExisting);
384
- }
385
- function isFactoryProvider(value) {
386
- return !!(value && value.useFactory);
387
- }
388
- export function isTypeProvider(value) {
389
- return typeof value === 'function';
390
- }
391
422
  function hasDeps(value) {
392
423
  return !!value.deps;
393
424
  }
@@ -405,6 +436,9 @@ function forEachSingleProvider(providers, fn) {
405
436
  if (Array.isArray(provider)) {
406
437
  forEachSingleProvider(provider, fn);
407
438
  }
439
+ else if (provider && isEnvironmentProviders(provider)) {
440
+ forEachSingleProvider(provider.ɵproviders, fn);
441
+ }
408
442
  else {
409
443
  fn(provider);
410
444
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /**
9
+ * Base URL for the error details page.
10
+ *
11
+ * Keep this constant in sync across:
12
+ * - packages/compiler-cli/src/ngtsc/diagnostics/src/error_details_base_url.ts
13
+ * - packages/core/src/error_details_base_url.ts
14
+ */
15
+ export const ERROR_DETAILS_PAGE_BASE_URL = 'https://angular.io/errors';
16
+ /**
17
+ * URL for the XSS security documentation.
18
+ */
19
+ export const XSS_SECURITY_URL = 'https://g.co/ng/security#xss';
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /**
9
+ * Class that represents a runtime error.
10
+ * Formats and outputs the error message in a consistent way.
11
+ *
12
+ * Example:
13
+ * ```
14
+ * throw new RuntimeError(
15
+ * RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
16
+ * ngDevMode && 'Injector has already been destroyed.');
17
+ * ```
18
+ *
19
+ * Note: the `message` argument contains a descriptive error message as a string in development
20
+ * mode (when the `ngDevMode` is defined). In production mode (after tree-shaking pass), the
21
+ * `message` argument becomes `false`, thus we account for it in the typings and the runtime
22
+ * logic.
23
+ */
24
+ export class RuntimeError extends Error {
25
+ code;
26
+ constructor(code, message) {
27
+ super(formatRuntimeError(code, message));
28
+ this.code = code;
29
+ }
30
+ }
31
+ /**
32
+ * Called to format a runtime error.
33
+ * See additional info on the `message` argument type in the `RuntimeError` class description.
34
+ */
35
+ export function formatRuntimeError(code, message) {
36
+ // Error code might be a negative number, which is a special marker that instructs the logic to
37
+ // generate a link to the error details page on angular.io.
38
+ // We also prepend `0` to non-compile-time errors.
39
+ const fullCode = `NG0${Math.abs(code)}`;
40
+ let errorMessage = `${fullCode}${message ? ': ' + message : ''}`;
41
+ if (false) {
42
+ }
43
+ return errorMessage;
44
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /**
9
+ * @description
10
+ *
11
+ * Represents a type that a Component or other object is instances of.
12
+ *
13
+ * An example of a `Type` is `MyCustomComponent` class, which in JavaScript is represented by
14
+ * the `MyCustomComponent` constructor function.
15
+ *
16
+ * @publicApi
17
+ */
18
+ export const Type = Function;
19
+ export function isType(v) {
20
+ return typeof v === 'function';
21
+ }
@@ -8,8 +8,7 @@
8
8
  import { NG_FACTORY_DEF } from './fields';
9
9
  export function getFactoryDef(type, throwNotFound) {
10
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
- // }
11
+ if (false) {
12
+ }
14
13
  return hasFactoryDef ? type[NG_FACTORY_DEF] : null;
15
14
  }
@@ -6,6 +6,7 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  export class RuntimeError extends Error {
9
+ code;
9
10
  constructor(code, message) {
10
11
  super(formatRuntimeError(code, message));
11
12
  this.code = code;
@@ -5,10 +5,9 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { RuntimeError } from './error_code';
9
- import { stringifyForError } from './util/stringify_utils';
8
+ import { RuntimeError } from '../errors';
10
9
  /** Throws an error when a token is not found in DI. */
11
10
  export function throwProviderNotFoundError(token, injectorName) {
12
11
  const injectorDetails = injectorName ? ` in ${injectorName}` : '';
13
- throw new RuntimeError("201" /* RuntimeErrorCode.PROVIDER_NOT_FOUND */, `No provider for ${stringifyForError(token)} found${injectorDetails}`);
12
+ throw new RuntimeError(-201 /* RuntimeErrorCode.PROVIDER_NOT_FOUND */, null);
14
13
  }
@@ -0,0 +1,22 @@
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
+ });
12
+ /**
13
+ * The `NG_ENV_ID` field on a DI token indicates special processing in the `EnvironmentInjector`:
14
+ * getting such tokens from the `EnvironmentInjector` will bypass the standard DI resolution
15
+ * strategy and instead will return implementation produced by the `NG_ENV_ID` factory function.
16
+ *
17
+ * This particular retrieval of DI tokens is mostly done to eliminate circular dependencies and
18
+ * improve tree-shaking.
19
+ */
20
+ export const NG_ENV_ID = getClosureSafeProperty({
21
+ __NG_ENV_ID__: getClosureSafeProperty,
22
+ });
@@ -1,10 +1,3 @@
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
1
  /**
9
2
  * Throws an error indicating that a factory function could not be generated by the compiler for a
10
3
  * particular class.
@@ -12,10 +12,10 @@
12
12
  * Check `core/test/render3/perf/render_stringify` for benchmarks and alternate implementations.
13
13
  */
14
14
  export function renderStringify(value) {
15
- if (typeof value === "string")
15
+ if (typeof value === 'string')
16
16
  return value;
17
17
  if (value == null)
18
- return "";
18
+ return '';
19
19
  // Use `String` so that it invokes the `toString` method of the value. Note that this
20
20
  // appears to be faster than calling `value.toString` (see `render_stringify` benchmark).
21
21
  return String(value);
@@ -26,11 +26,11 @@ export function renderStringify(value) {
26
26
  * used for error messages.
27
27
  */
28
28
  export function stringifyForError(value) {
29
- if (typeof value === "function")
29
+ if (typeof value === 'function')
30
30
  return value.name || value.toString();
31
- if (typeof value === "object" &&
31
+ if (typeof value === 'object' &&
32
32
  value != null &&
33
- typeof value.type === "function") {
33
+ typeof value.type === 'function') {
34
34
  return value.type.name || value.type.toString();
35
35
  }
36
36
  return renderStringify(value);
@@ -1,10 +1,3 @@
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
1
  export function deepForEach(input, fn) {
9
2
  input.forEach((value) => Array.isArray(value) ? deepForEach(value, fn) : fn(value));
10
3
  }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { noSideEffects } from './closure';
9
+ export const PARAMETERS = '__parameters__';
10
+ function makeMetadataCtor(props) {
11
+ return function ctor(...args) {
12
+ if (props) {
13
+ const values = props(...args);
14
+ for (const propName in values) {
15
+ this[propName] = values[propName];
16
+ }
17
+ }
18
+ };
19
+ }
20
+ export function makeParamDecorator(name, props, parentClass) {
21
+ return noSideEffects(() => {
22
+ const metaCtor = makeMetadataCtor(props);
23
+ function ParamDecoratorFactory(...args) {
24
+ if (this instanceof ParamDecoratorFactory) {
25
+ metaCtor.apply(this, args);
26
+ return this;
27
+ }
28
+ const annotationInstance = new ParamDecoratorFactory(...args);
29
+ ParamDecorator.annotation = annotationInstance;
30
+ return ParamDecorator;
31
+ function ParamDecorator(cls, unusedKey, index) {
32
+ // Use of Object.defineProperty is important since it creates non-enumerable property which
33
+ // prevents the property is copied during subclassing.
34
+ const parameters = cls.hasOwnProperty(PARAMETERS)
35
+ ? cls[PARAMETERS]
36
+ : Object.defineProperty(cls, PARAMETERS, { value: [] })[PARAMETERS];
37
+ // there might be gaps if some in between parameters do not have annotations.
38
+ // we pad with nulls.
39
+ while (parameters.length <= index) {
40
+ parameters.push(null);
41
+ }
42
+ (parameters[index] = parameters[index] || []).push(annotationInstance);
43
+ return cls;
44
+ }
45
+ }
46
+ if (parentClass) {
47
+ ParamDecoratorFactory.prototype = Object.create(parentClass.prototype);
48
+ }
49
+ ParamDecoratorFactory.prototype.ngMetadataName = name;
50
+ ParamDecoratorFactory.annotationCls = ParamDecoratorFactory;
51
+ return ParamDecoratorFactory;
52
+ });
53
+ }
@@ -11,4 +11,8 @@
11
11
  * allows for identity checks against these values to be consistently used by the framework
12
12
  * code.
13
13
  */
14
+ export const EMPTY_OBJ = {};
14
15
  export const EMPTY_ARRAY = [];
16
+ // freezing the values prevents any code from accidentally inserting new values in
17
+ if (false) {
18
+ }
@@ -6,14 +6,14 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  export function stringify(token) {
9
- if (typeof token === "string") {
9
+ if (typeof token === 'string') {
10
10
  return token;
11
11
  }
12
12
  if (Array.isArray(token)) {
13
- return "[" + token.map(stringify).join(", ") + "]";
13
+ return '[' + token.map(stringify).join(', ') + ']';
14
14
  }
15
15
  if (token == null) {
16
- return "" + token;
16
+ return '' + token;
17
17
  }
18
18
  if (token.overriddenName) {
19
19
  return `${token.overriddenName}`;
@@ -23,8 +23,8 @@ export function stringify(token) {
23
23
  }
24
24
  const res = token.toString();
25
25
  if (res == null) {
26
- return "" + res;
26
+ return '' + res;
27
27
  }
28
- const newLineIndex = res.indexOf("\n");
28
+ const newLineIndex = res.indexOf('\n');
29
29
  return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
30
30
  }