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.
Files changed (44) hide show
  1. package/import/commonjs/index.js +419 -157
  2. package/import/es2015/di/create_injector.js +5 -1
  3. package/import/es2015/di/forward_ref.js +3 -3
  4. package/import/es2015/di/injection_token.js +18 -11
  5. package/import/es2015/di/injector_compatibility.js +19 -10
  6. package/import/es2015/di/injector_token.js +3 -3
  7. package/import/es2015/di/interface/defs.js +21 -12
  8. package/import/es2015/di/interface/provider.js +3 -1
  9. package/import/es2015/di/null_injector.js +3 -3
  10. package/import/es2015/di/provider_collection.js +196 -1
  11. package/import/es2015/di/r3_injector.js +25 -22
  12. package/import/es2015/error_details_base_url.js +19 -0
  13. package/import/es2015/errors.js +42 -0
  14. package/import/es2015/interface/type.js +14 -1
  15. package/import/es2015/render3/definition_factory.js +2 -3
  16. package/import/es2015/render3/errors_di.js +2 -3
  17. package/import/es2015/render3/instructions/di.js +0 -7
  18. package/import/es2015/render3/util/stringify_utils.js +5 -5
  19. package/import/es2015/util/array_utils.js +0 -7
  20. package/import/es2015/util/decorators.js +24 -1
  21. package/import/es2015/util/empty.js +4 -0
  22. package/import/es2015/util/stringify.js +5 -5
  23. package/import/fesm2015/index.js +416 -155
  24. package/import/typings/di/forward_ref.d.ts +1 -1
  25. package/import/typings/di/injectable.d.ts +4 -3
  26. package/import/typings/di/injection_token.d.ts +21 -6
  27. package/import/typings/di/injector.d.ts +16 -0
  28. package/import/typings/di/injector_compatibility.d.ts +11 -5
  29. package/import/typings/di/injector_token.d.ts +2 -2
  30. package/import/typings/di/interface/defs.d.ts +15 -8
  31. package/import/typings/di/interface/provider.d.ts +60 -0
  32. package/import/typings/di/null_injector.d.ts +1 -1
  33. package/import/typings/di/provider_collection.d.ts +54 -1
  34. package/import/typings/di/provider_token.d.ts +2 -2
  35. package/import/typings/di/r3_injector.d.ts +3 -8
  36. package/import/typings/error_details_base_url.d.ts +19 -0
  37. package/import/typings/errors.d.ts +89 -0
  38. package/import/typings/interface/type.d.ts +45 -0
  39. package/import/typings/render3/errors_di.d.ts +7 -0
  40. package/import/typings/render3/instructions/di.d.ts +0 -7
  41. package/import/typings/util/array_utils.d.ts +15 -7
  42. package/import/typings/util/decorators.d.ts +2 -1
  43. package/import/typings/util/empty.d.ts +1 -0
  44. package/package.json +1 -1
@@ -0,0 +1,42 @@
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 logic.
22
+ */
23
+ export class RuntimeError extends Error {
24
+ constructor(code, message) {
25
+ super(formatRuntimeError(code, message));
26
+ this.code = code;
27
+ }
28
+ }
29
+ /**
30
+ * Called to format a runtime error.
31
+ * See additional info on the `message` argument type in the `RuntimeError` class description.
32
+ */
33
+ export function formatRuntimeError(code, message) {
34
+ // Error code might be a negative number, which is a special marker that instructs the logic to
35
+ // generate a link to the error details page on angular.io.
36
+ // We also prepend `0` to non-compile-time errors.
37
+ const fullCode = `NG0${Math.abs(code)}`;
38
+ let errorMessage = `${fullCode}${message ? ': ' + message.trim() : ''}`;
39
+ if (false) {
40
+ }
41
+ return errorMessage;
42
+ }
@@ -5,4 +5,17 @@
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
- export {};
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
  }
@@ -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
  }
@@ -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
  }
@@ -6,6 +6,7 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import { noSideEffects } from './closure';
9
+ export const PARAMETERS = '__parameters__';
9
10
  function makeMetadataCtor(props) {
10
11
  return function ctor(...args) {
11
12
  if (props) {
@@ -16,7 +17,7 @@ function makeMetadataCtor(props) {
16
17
  }
17
18
  };
18
19
  }
19
- export function makeParamDecorator(name, props) {
20
+ export function makeParamDecorator(name, props, parentClass) {
20
21
  return noSideEffects(() => {
21
22
  const metaCtor = makeMetadataCtor(props);
22
23
  function ParamDecoratorFactory(...args) {
@@ -24,7 +25,29 @@ export function makeParamDecorator(name, props) {
24
25
  metaCtor.apply(this, args);
25
26
  return this;
26
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);
27
48
  }
49
+ ParamDecoratorFactory.prototype.ngMetadataName = name;
50
+ ParamDecoratorFactory.annotationCls = ParamDecoratorFactory;
28
51
  return ParamDecoratorFactory;
29
52
  });
30
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
  }