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,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.Injectable = void 0;
11
8
  /**
12
9
  * Injectable decorator and metadata.
13
10
  *
14
11
  * @Annotation
15
12
  * @publicApi
16
13
  */
17
- exports.Injectable = undefined;
14
+ export const Injectable = undefined;
@@ -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,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.isForwardRef = exports.resolveForwardRef = exports.forwardRef = void 0;
11
- const property_1 = require("../util/property");
12
- const stringify_1 = require("../util/stringify");
13
- const __forward_ref__ = property_1.getClosureSafeProperty({
14
- __forward_ref__: property_1.getClosureSafeProperty,
8
+ import { getClosureSafeProperty } from "../util/property";
9
+ import { stringify } from "../util/stringify";
10
+ const __forward_ref__ = getClosureSafeProperty({
11
+ __forward_ref__: getClosureSafeProperty,
15
12
  });
16
13
  /**
17
14
  * Allows to refer to references which are not yet defined.
@@ -25,14 +22,13 @@ const __forward_ref__ = property_1.getClosureSafeProperty({
25
22
  * {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref'}
26
23
  * @publicApi
27
24
  */
28
- function forwardRef(forwardRefFn) {
25
+ export function forwardRef(forwardRefFn) {
29
26
  forwardRefFn.__forward_ref__ = forwardRef;
30
27
  forwardRefFn.toString = function () {
31
- return stringify_1.stringify(this());
28
+ return stringify(this());
32
29
  };
33
30
  return forwardRefFn;
34
31
  }
35
- exports.forwardRef = forwardRef;
36
32
  /**
37
33
  * Lazily retrieves the reference value from a forwardRef.
38
34
  *
@@ -46,14 +42,12 @@ exports.forwardRef = forwardRef;
46
42
  * @see `forwardRef`
47
43
  * @publicApi
48
44
  */
49
- function resolveForwardRef(type) {
45
+ export function resolveForwardRef(type) {
50
46
  return isForwardRef(type) ? type() : type;
51
47
  }
52
- exports.resolveForwardRef = resolveForwardRef;
53
48
  /** Checks whether a function is wrapped by a `forwardRef`. */
54
- function isForwardRef(fn) {
49
+ export function isForwardRef(fn) {
55
50
  return (typeof fn === "function" &&
56
51
  fn.hasOwnProperty(__forward_ref__) &&
57
52
  fn.__forward_ref__ === forwardRef);
58
53
  }
59
- exports.isForwardRef = isForwardRef;
@@ -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.injectRootLimpMode = void 0;
11
- const errors_di_1 = require("../render3/errors_di");
12
- const stringify_1 = require("../util/stringify");
13
- const defs_1 = require("./interface/defs");
14
- const injector_1 = require("./interface/injector");
8
+ import { throwProviderNotFoundError } from "../render3/errors_di";
9
+ import { stringify } from "../util/stringify";
10
+ import { getInjectableDef } from "./interface/defs";
11
+ import { InjectFlags } from "./interface/injector";
15
12
  /**
16
13
  * Injects `root` tokens in limp mode.
17
14
  *
@@ -19,17 +16,16 @@ const injector_1 = require("./interface/injector");
19
16
  * `"root"`. This is known as the limp mode injection. In such case the value is stored in the
20
17
  * injectable definition.
21
18
  */
22
- function injectRootLimpMode(token, notFoundValue, flags) {
23
- const injectableDef = defs_1.getInjectableDef(token);
19
+ export function injectRootLimpMode(token, notFoundValue, flags) {
20
+ const injectableDef = getInjectableDef(token);
24
21
  if (injectableDef && injectableDef.providedIn == "root") {
25
22
  return injectableDef.value === undefined
26
23
  ? (injectableDef.value = injectableDef.factory())
27
24
  : injectableDef.value;
28
25
  }
29
- if (flags & injector_1.InjectFlags.Optional)
26
+ if (flags & InjectFlags.Optional)
30
27
  return null;
31
28
  if (notFoundValue !== undefined)
32
29
  return notFoundValue;
33
- errors_di_1.throwProviderNotFoundError(stringify_1.stringify(token), "Injector");
30
+ throwProviderNotFoundError(stringify(token), "Injector");
34
31
  }
35
- exports.injectRootLimpMode = injectRootLimpMode;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,9 +5,7 @@
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.InjectionToken = void 0;
11
- const defs_1 = require("./interface/defs");
8
+ import { ɵɵdefineInjectable } from './interface/defs';
12
9
  /**
13
10
  * Creates a token that can be used in a DI Provider.
14
11
  *
@@ -49,11 +46,9 @@ const defs_1 = require("./interface/defs");
49
46
  *
50
47
  * @publicApi
51
48
  */
52
- class InjectionToken {
49
+ export class InjectionToken {
53
50
  constructor(_desc, options) {
54
51
  this._desc = _desc;
55
- /** @internal */
56
- this.ngMetadataName = 'InjectionToken';
57
52
  this.ɵprov = undefined;
58
53
  if (typeof options == 'number') {
59
54
  // (typeof ngDevMode === "undefined" || ngDevMode) &&
@@ -63,7 +58,7 @@ class InjectionToken {
63
58
  // (this as any).__NG_ELEMENT_ID__ = options;
64
59
  }
65
60
  else if (options !== undefined) {
66
- this.ɵprov = defs_1.ɵɵdefineInjectable({
61
+ this.ɵprov = ɵɵdefineInjectable({
67
62
  token: this,
68
63
  providedIn: options.providedIn || 'root',
69
64
  factory: options.factory,
@@ -74,4 +69,3 @@ class InjectionToken {
74
69
  return `InjectionToken ${this._desc}`;
75
70
  }
76
71
  }
77
- exports.InjectionToken = InjectionToken;
@@ -0,0 +1,63 @@
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 { THROW_IF_NOT_FOUND, ɵɵinject } from './injector_compatibility';
9
+ import { INJECTOR } from './injector_token';
10
+ import { ɵɵdefineInjectable } from './interface/defs';
11
+ import { NullInjector } from './null_injector';
12
+ import { createInjector } from './r3_injector';
13
+ export function INJECTOR_IMPL__POST_R3__(providers, parent, name) {
14
+ return createInjector({ name: name }, parent, providers, name);
15
+ }
16
+ export const INJECTOR_IMPL = INJECTOR_IMPL__POST_R3__;
17
+ /**
18
+ * Concrete injectors implement this interface. Injectors are configured
19
+ * with [providers](guide/glossary#provider) that associate
20
+ * dependencies of various types with [injection tokens](guide/glossary#di-token).
21
+ *
22
+ * @see ["DI Providers"](guide/dependency-injection-providers).
23
+ * @see `StaticProvider`
24
+ *
25
+ * @usageNotes
26
+ *
27
+ * The following example creates a service injector instance.
28
+ *
29
+ * {@example core/di/ts/provider_spec.ts region='ConstructorProvider'}
30
+ *
31
+ * ### Usage example
32
+ *
33
+ * {@example core/di/ts/injector_spec.ts region='Injector'}
34
+ *
35
+ * `Injector` returns itself when given `Injector` as a token:
36
+ *
37
+ * {@example core/di/ts/injector_spec.ts region='injectInjector'}
38
+ *
39
+ * @publicApi
40
+ */
41
+ export class Injector {
42
+ static create(options, parent) {
43
+ if (Array.isArray(options)) {
44
+ return INJECTOR_IMPL(options, parent, '');
45
+ }
46
+ else {
47
+ return INJECTOR_IMPL(options.providers, options.parent, options.name || '');
48
+ }
49
+ }
50
+ }
51
+ Injector.THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
52
+ Injector.NULL = new NullInjector();
53
+ /** @nocollapse */
54
+ Injector.ɵprov = ɵɵdefineInjectable({
55
+ token: Injector,
56
+ providedIn: 'any',
57
+ factory: () => ɵɵinject(INJECTOR),
58
+ });
59
+ /**
60
+ * @internal
61
+ * @nocollapse
62
+ */
63
+ Injector.__NG_ELEMENT_ID__ = -1 /* Injector */;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,29 +5,27 @@
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.formatError = exports.catchInjectorError = exports.getInjectFlag = exports.attachInjectFlag = exports.injectArgs = exports.inject = exports.ɵɵinject = exports.injectInjectorOnly = exports.setCurrentInjector = exports.USE_VALUE = exports.SOURCE = exports.NG_TEMP_TOKEN_PATH = exports.THROW_IF_NOT_FOUND = void 0;
11
- const property_1 = require("../util/property");
12
- const stringify_1 = require("../util/stringify");
13
- const forward_ref_1 = require("./forward_ref");
14
- const inject_switch_1 = require("./inject_switch");
15
- const injector_1 = require("./interface/injector");
8
+ import { getClosureSafeProperty } from "../util/property";
9
+ import { stringify } from "../util/stringify";
10
+ import { resolveForwardRef } from "./forward_ref";
11
+ import { injectRootLimpMode } from "./inject_switch";
12
+ import { InjectFlags, } from "./interface/injector";
16
13
  const _THROW_IF_NOT_FOUND = {};
17
- exports.THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
14
+ export const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
18
15
  /*
19
16
  * Name of a property (that we patch onto DI decorator), which is used as an annotation of which
20
17
  * InjectFlag this decorator represents. This allows to avoid direct references to the DI decorators
21
18
  * in the code, thus making them tree-shakable.
22
19
  */
23
20
  const DI_DECORATOR_FLAG = "__NG_DI_FLAG__";
24
- exports.NG_TEMP_TOKEN_PATH = "ngTempTokenPath";
21
+ export const NG_TEMP_TOKEN_PATH = "ngTempTokenPath";
25
22
  const NG_TOKEN_PATH = "ngTokenPath";
26
23
  const NEW_LINE = /\n/gm;
27
24
  const NO_NEW_LINE = "ɵ";
28
- exports.SOURCE = "__source";
29
- exports.USE_VALUE = property_1.getClosureSafeProperty({
25
+ export const SOURCE = "__source";
26
+ export const USE_VALUE = getClosureSafeProperty({
30
27
  provide: String,
31
- useValue: property_1.getClosureSafeProperty,
28
+ useValue: getClosureSafeProperty,
32
29
  });
33
30
  /**
34
31
  * Current injector value used by `inject`.
@@ -37,28 +34,25 @@ exports.USE_VALUE = property_1.getClosureSafeProperty({
37
34
  * - Injector instance: Use the injector for resolution.
38
35
  */
39
36
  let _currentInjector = undefined;
40
- function setCurrentInjector(injector) {
37
+ export function setCurrentInjector(injector) {
41
38
  const former = _currentInjector;
42
39
  _currentInjector = injector;
43
40
  return former;
44
41
  }
45
- exports.setCurrentInjector = setCurrentInjector;
46
- function injectInjectorOnly(token, flags = injector_1.InjectFlags.Default) {
42
+ export function injectInjectorOnly(token, flags = InjectFlags.Default) {
47
43
  if (_currentInjector === undefined) {
48
44
  throw new Error(`inject() must be called from an injection context`);
49
45
  }
50
46
  else if (_currentInjector === null) {
51
- return inject_switch_1.injectRootLimpMode(token, undefined, flags);
47
+ return injectRootLimpMode(token, undefined, flags);
52
48
  }
53
49
  else {
54
- return _currentInjector.get(token, flags & injector_1.InjectFlags.Optional ? null : undefined, flags);
50
+ return _currentInjector.get(token, flags & InjectFlags.Optional ? null : undefined, flags);
55
51
  }
56
52
  }
57
- exports.injectInjectorOnly = injectInjectorOnly;
58
- function ɵɵinject(token, flags = injector_1.InjectFlags.Default) {
59
- return injectInjectorOnly(forward_ref_1.resolveForwardRef(token), flags);
53
+ export function ɵɵinject(token, flags = InjectFlags.Default) {
54
+ return injectInjectorOnly(resolveForwardRef(token), flags);
60
55
  }
61
- exports.ɵɵinject = ɵɵinject;
62
56
  /**
63
57
  * Injects a token from the currently active injector.
64
58
  *
@@ -83,17 +77,17 @@ exports.ɵɵinject = ɵɵinject;
83
77
  *
84
78
  * @publicApi
85
79
  */
86
- exports.inject = ɵɵinject;
87
- function injectArgs(types) {
80
+ export const inject = ɵɵinject;
81
+ export function injectArgs(types) {
88
82
  const args = [];
89
83
  for (let i = 0; i < types.length; i++) {
90
- const arg = forward_ref_1.resolveForwardRef(types[i]);
84
+ const arg = resolveForwardRef(types[i]);
91
85
  if (Array.isArray(arg)) {
92
86
  if (arg.length === 0) {
93
87
  throw new Error("Arguments array must have arguments.");
94
88
  }
95
89
  let type = undefined;
96
- let flags = injector_1.InjectFlags.Default;
90
+ let flags = InjectFlags.Default;
97
91
  for (let j = 0; j < arg.length; j++) {
98
92
  const meta = arg[j];
99
93
  const flag = getInjectFlag(meta);
@@ -118,7 +112,6 @@ function injectArgs(types) {
118
112
  }
119
113
  return args;
120
114
  }
121
- exports.injectArgs = injectArgs;
122
115
  /**
123
116
  * Attaches a given InjectFlag to a given decorator using monkey-patching.
124
117
  * Since DI decorators can be used in providers `deps` array (when provider is configured using
@@ -129,40 +122,37 @@ exports.injectArgs = injectArgs;
129
122
  * @param decorator Provided DI decorator.
130
123
  * @param flag InjectFlag that should be applied.
131
124
  */
132
- function attachInjectFlag(decorator, flag) {
125
+ export function attachInjectFlag(decorator, flag) {
133
126
  decorator[DI_DECORATOR_FLAG] = flag;
134
127
  decorator.prototype[DI_DECORATOR_FLAG] = flag;
135
128
  return decorator;
136
129
  }
137
- exports.attachInjectFlag = attachInjectFlag;
138
130
  /**
139
131
  * Reads monkey-patched property that contains InjectFlag attached to a decorator.
140
132
  *
141
133
  * @param token Token that may contain monkey-patched DI flags property.
142
134
  */
143
- function getInjectFlag(token) {
135
+ export function getInjectFlag(token) {
144
136
  return token[DI_DECORATOR_FLAG];
145
137
  }
146
- exports.getInjectFlag = getInjectFlag;
147
- function catchInjectorError(e, token, injectorErrorName, source) {
148
- const tokenPath = e[exports.NG_TEMP_TOKEN_PATH];
149
- if (token[exports.SOURCE]) {
150
- tokenPath.unshift(token[exports.SOURCE]);
138
+ export function catchInjectorError(e, token, injectorErrorName, source) {
139
+ const tokenPath = e[NG_TEMP_TOKEN_PATH];
140
+ if (token[SOURCE]) {
141
+ tokenPath.unshift(token[SOURCE]);
151
142
  }
152
143
  e.message = formatError("\n" + e.message, tokenPath, injectorErrorName, source);
153
144
  e[NG_TOKEN_PATH] = tokenPath;
154
- e[exports.NG_TEMP_TOKEN_PATH] = null;
145
+ e[NG_TEMP_TOKEN_PATH] = null;
155
146
  throw e;
156
147
  }
157
- exports.catchInjectorError = catchInjectorError;
158
- function formatError(text, obj, injectorErrorName, source = null) {
148
+ export function formatError(text, obj, injectorErrorName, source = null) {
159
149
  text =
160
150
  text && text.charAt(0) === "\n" && text.charAt(1) == NO_NEW_LINE
161
151
  ? text.substr(2)
162
152
  : text;
163
- let context = stringify_1.stringify(obj);
153
+ let context = stringify(obj);
164
154
  if (Array.isArray(obj)) {
165
- context = obj.map(stringify_1.stringify).join(" -> ");
155
+ context = obj.map(stringify).join(" -> ");
166
156
  }
167
157
  else if (typeof obj === "object") {
168
158
  let parts = [];
@@ -173,11 +163,10 @@ function formatError(text, obj, injectorErrorName, source = null) {
173
163
  ":" +
174
164
  (typeof value === "string"
175
165
  ? JSON.stringify(value)
176
- : stringify_1.stringify(value)));
166
+ : stringify(value)));
177
167
  }
178
168
  }
179
169
  context = `{${parts.join(", ")}}`;
180
170
  }
181
171
  return `${injectorErrorName}${source ? "(" + source + ")" : ""}[${context}]: ${text.replace(NEW_LINE, "\n ")}`;
182
172
  }
183
- exports.formatError = formatError;
@@ -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,9 +5,7 @@
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 = void 0;
11
- const injection_token_1 = require("./injection_token");
8
+ import { InjectionToken } from "./injection_token";
12
9
  /**
13
10
  * An InjectionToken that gets the current `Injector` for `createInjector()`-style injectors.
14
11
  *
@@ -17,7 +14,7 @@ const injection_token_1 = require("./injection_token");
17
14
  *
18
15
  * @publicApi
19
16
  */
20
- exports.INJECTOR = new injection_token_1.InjectionToken("INJECTOR",
17
+ export const INJECTOR = new InjectionToken("INJECTOR",
21
18
  // Dissable tslint because this is const enum which gets inlined not top level prop access.
22
19
  // tslint:disable-next-line: no-toplevel-property-access
23
20
  -1 /* Injector */ // Special value used by Ivy to identify `Injector`.
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,9 +5,7 @@
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.NG_INJECTOR_DEF = exports.NG_INJECTABLE_DEF = exports.NG_INJ_DEF = exports.NG_PROV_DEF = exports.getInjectorDef = exports.getInjectableDef = exports.ɵɵdefineInjector = exports.defineInjectable = exports.ɵɵdefineInjectable = void 0;
11
- const property_1 = require("../../util/property");
8
+ import { getClosureSafeProperty } from '../../util/property';
12
9
  /**
13
10
  * Construct an injectable definition which defines how a token will be constructed by the DI
14
11
  * system, and in which injectors (if any) it will be available.
@@ -26,7 +23,7 @@ const property_1 = require("../../util/property");
26
23
  * @codeGenApi
27
24
  * @publicApi This instruction has been emitted by ViewEngine for some time and is deployed to npm.
28
25
  */
29
- function ɵɵdefineInjectable(opts) {
26
+ export function ɵɵdefineInjectable(opts) {
30
27
  return {
31
28
  token: opts.token,
32
29
  providedIn: opts.providedIn || null,
@@ -34,13 +31,6 @@ function ɵɵdefineInjectable(opts) {
34
31
  value: undefined,
35
32
  };
36
33
  }
37
- exports.ɵɵdefineInjectable = ɵɵdefineInjectable;
38
- /**
39
- * @deprecated in v8, delete after v10. This API should be used only by generated code, and that
40
- * code should now use ɵɵdefineInjectable instead.
41
- * @publicApi
42
- */
43
- exports.defineInjectable = ɵɵdefineInjectable;
44
34
  /**
45
35
  * Construct an `InjectorDef` which configures an injector.
46
36
  *
@@ -58,21 +48,18 @@ exports.defineInjectable = ɵɵdefineInjectable;
58
48
  *
59
49
  * @codeGenApi
60
50
  */
61
- function ɵɵdefineInjector(options) {
51
+ export function ɵɵdefineInjector(options) {
62
52
  return { providers: options.providers || [], imports: options.imports || [] };
63
53
  }
64
- exports.ɵɵdefineInjector = ɵɵdefineInjector;
65
54
  /**
66
55
  * Read the injectable def (`ɵprov`) for `type` in a way which is immune to accidentally reading
67
56
  * inherited value.
68
57
  *
69
58
  * @param type A type which may have its own (non-inherited) `ɵprov`.
70
59
  */
71
- function getInjectableDef(type) {
72
- return (getOwnDefinition(type, exports.NG_PROV_DEF) ||
73
- getOwnDefinition(type, exports.NG_INJECTABLE_DEF));
60
+ export function getInjectableDef(type) {
61
+ return getOwnDefinition(type, NG_PROV_DEF);
74
62
  }
75
- exports.getInjectableDef = getInjectableDef;
76
63
  /**
77
64
  * Return definition only if it is defined directly on `type` and is not inherited from a base
78
65
  * class of `type`.
@@ -80,28 +67,6 @@ exports.getInjectableDef = getInjectableDef;
80
67
  function getOwnDefinition(type, field) {
81
68
  return type.hasOwnProperty(field) ? type[field] : null;
82
69
  }
83
- /**
84
- * Read the injector def type in a way which is immune to accidentally reading inherited value.
85
- *
86
- * @param type type which may have an injector def (`ɵinj`)
87
- */
88
- function getInjectorDef(type) {
89
- return type &&
90
- (type.hasOwnProperty(exports.NG_INJ_DEF) || type.hasOwnProperty(exports.NG_INJECTOR_DEF))
91
- ? type[exports.NG_INJ_DEF]
92
- : null;
93
- }
94
- exports.getInjectorDef = getInjectorDef;
95
- exports.NG_PROV_DEF = property_1.getClosureSafeProperty({
96
- ɵprov: property_1.getClosureSafeProperty,
97
- });
98
- exports.NG_INJ_DEF = property_1.getClosureSafeProperty({
99
- ɵinj: property_1.getClosureSafeProperty,
100
- });
101
- // We need to keep these around so we can read off old defs if new defs are unavailable
102
- exports.NG_INJECTABLE_DEF = property_1.getClosureSafeProperty({
103
- ngInjectableDef: property_1.getClosureSafeProperty,
104
- });
105
- exports.NG_INJECTOR_DEF = property_1.getClosureSafeProperty({
106
- ngInjectorDef: property_1.getClosureSafeProperty,
70
+ export const NG_PROV_DEF = getClosureSafeProperty({
71
+ ɵprov: getClosureSafeProperty,
107
72
  });
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @license
4
3
  * Copyright Google LLC All Rights Reserved.
@@ -6,14 +5,12 @@
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.InjectFlags = void 0;
11
8
  /**
12
9
  * Injection flags for DI.
13
10
  *
14
11
  * @publicApi
15
12
  */
16
- var InjectFlags;
13
+ export var InjectFlags;
17
14
  (function (InjectFlags) {
18
15
  // TODO(alxhub): make this 'const' (and remove `InternalInjectFlags` enum) when ngc no longer
19
16
  // writes exports of it into ngfactory files.
@@ -25,4 +22,4 @@ var InjectFlags;
25
22
  InjectFlags[InjectFlags["SkipSelf"] = 4] = "SkipSelf";
26
23
  /** Inject `defaultValue` instead if token not found. */
27
24
  InjectFlags[InjectFlags["Optional"] = 8] = "Optional";
28
- })(InjectFlags = exports.InjectFlags || (exports.InjectFlags = {}));
25
+ })(InjectFlags || (InjectFlags = {}));
@@ -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,47 +5,45 @@
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.SkipSelf = exports.Self = exports.Optional = exports.Inject = void 0;
11
- const decorators_1 = require("../util/decorators");
12
- const injector_compatibility_1 = require("./injector_compatibility");
8
+ import { makeParamDecorator } from '../util/decorators';
9
+ import { attachInjectFlag } from './injector_compatibility';
13
10
  /**
14
11
  * Inject decorator and metadata.
15
12
  *
16
13
  * @Annotation
17
14
  * @publicApi
18
15
  */
19
- exports.Inject = injector_compatibility_1.attachInjectFlag(
16
+ export const Inject = attachInjectFlag(
20
17
  // Disable tslint because `DecoratorFlags` is a const enum which gets inlined.
21
18
  // tslint:disable-next-line: no-toplevel-property-access
22
- decorators_1.makeParamDecorator('Inject', (token) => ({ token })), -1 /* Inject */);
19
+ makeParamDecorator('Inject', (token) => ({ token })), -1 /* Inject */);
23
20
  /**
24
21
  * Optional decorator and metadata.
25
22
  *
26
23
  * @Annotation
27
24
  * @publicApi
28
25
  */
29
- exports.Optional =
26
+ export const Optional =
30
27
  // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
31
28
  // tslint:disable-next-line: no-toplevel-property-access
32
- injector_compatibility_1.attachInjectFlag(decorators_1.makeParamDecorator('Optional'), 8 /* Optional */);
29
+ attachInjectFlag(makeParamDecorator('Optional'), 8 /* Optional */);
33
30
  /**
34
31
  * Self decorator and metadata.
35
32
  *
36
33
  * @Annotation
37
34
  * @publicApi
38
35
  */
39
- exports.Self =
36
+ export const Self =
40
37
  // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
41
38
  // tslint:disable-next-line: no-toplevel-property-access
42
- injector_compatibility_1.attachInjectFlag(decorators_1.makeParamDecorator('Self'), 2 /* Self */);
39
+ attachInjectFlag(makeParamDecorator('Self'), 2 /* Self */);
43
40
  /**
44
41
  * `SkipSelf` decorator and metadata.
45
42
  *
46
43
  * @Annotation
47
44
  * @publicApi
48
45
  */
49
- exports.SkipSelf =
46
+ export const SkipSelf =
50
47
  // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
51
48
  // tslint:disable-next-line: no-toplevel-property-access
52
- injector_compatibility_1.attachInjectFlag(decorators_1.makeParamDecorator('SkipSelf'), 4 /* SkipSelf */);
49
+ attachInjectFlag(makeParamDecorator('SkipSelf'), 4 /* SkipSelf */);
@@ -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
+ import { stringify } from "../util/stringify";
9
+ import { THROW_IF_NOT_FOUND } from "./injector_compatibility";
10
+ export class NullInjector {
11
+ get(token, notFoundValue = THROW_IF_NOT_FOUND) {
12
+ if (notFoundValue === THROW_IF_NOT_FOUND) {
13
+ const error = new Error(`NullInjectorError: No provider for ${stringify(token)}!`);
14
+ error.name = "NullInjectorError";
15
+ throw error;
16
+ }
17
+ return notFoundValue;
18
+ }
19
+ }