static-injector 1.0.10 → 2.0.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 (78) hide show
  1. package/import/commonjs/index.js +331 -118
  2. package/import/es2015/di/create_injector.js +30 -0
  3. package/import/es2015/di/initializer_token.js +15 -0
  4. package/import/es2015/di/inject_switch.js +27 -6
  5. package/import/es2015/{decorator → di}/injectable.js +0 -0
  6. package/import/es2015/di/injection_token.js +6 -0
  7. package/import/es2015/di/injector.js +6 -8
  8. package/import/es2015/di/injector_compatibility.js +90 -34
  9. package/import/es2015/di/injector_token.js +1 -1
  10. package/import/es2015/di/interface/defs.js +39 -0
  11. package/import/es2015/di/interface/injector.js +1 -0
  12. package/import/es2015/di/internal_tokens.js +9 -0
  13. package/import/es2015/di/metadata.js +4 -4
  14. package/import/es2015/di/provider_collection.js +49 -0
  15. package/import/es2015/di/r3_injector.js +96 -66
  16. package/import/es2015/di/scope.js +2 -2
  17. package/import/es2015/index.js +1 -1
  18. package/import/es2015/render3/errors_di.js +1 -1
  19. package/import/fesm2015/index.js +322 -108
  20. package/import/typings/di/create_injector.d.ts +23 -0
  21. package/import/typings/di/initializer_token.d.ts +15 -0
  22. package/import/typings/di/inject_switch.d.ts +7 -2
  23. package/import/typings/{decorator → di}/injectable.d.ts +1 -1
  24. package/import/typings/di/injection_token.d.ts +4 -0
  25. package/import/typings/di/injector.d.ts +20 -7
  26. package/import/typings/di/injector_compatibility.d.ts +42 -21
  27. package/import/typings/di/interface/defs.d.ts +10 -0
  28. package/import/typings/di/interface/injector.d.ts +26 -0
  29. package/import/typings/di/interface/provider.d.ts +1 -6
  30. package/import/typings/di/internal_tokens.d.ts +10 -0
  31. package/import/typings/di/provider_collection.d.ts +30 -0
  32. package/import/typings/di/r3_injector.d.ts +67 -36
  33. package/import/typings/di/scope.d.ts +3 -2
  34. package/import/typings/index.d.ts +1 -1
  35. package/package.json +4 -2
  36. package/transform/compiler/index.js +5 -1
  37. package/transform/compiler/src/injectable_compiler_2.d.ts +7 -36
  38. package/transform/compiler/src/injectable_compiler_2.js +20 -23
  39. package/transform/compiler/src/output/output_ast.d.ts +29 -108
  40. package/transform/compiler/src/output/output_ast.js +66 -188
  41. package/transform/compiler/src/render3/r3_factory.js +11 -7
  42. package/transform/compiler/src/render3/util.d.ts +64 -0
  43. package/transform/compiler/src/render3/util.js +52 -9
  44. package/transform/compiler/src/render3/view/util.js +5 -1
  45. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.d.ts +5 -4
  46. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.js +32 -23
  47. package/transform/compiler-cli/src/ngtsc/annotations/src/factory.js +1 -1
  48. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +33 -21
  49. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +6 -2
  50. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +5 -1
  51. package/transform/compiler-cli/src/ngtsc/imports/index.js +5 -1
  52. package/transform/compiler-cli/src/ngtsc/reflection/index.js +5 -1
  53. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +1 -1
  54. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +6 -2
  55. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -2
  56. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +36 -23
  57. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +18 -13
  58. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +5 -1
  59. package/transform/compiler-cli/src/ngtsc/transform/index.js +5 -1
  60. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +2 -2
  61. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +13 -8
  62. package/transform/compiler-cli/src/ngtsc/translator/index.js +5 -1
  63. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +3 -3
  64. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +7 -3
  65. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +0 -4
  66. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +5 -17
  67. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +3 -6
  68. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +67 -55
  69. package/{import/es2015/decorator/interface/provider.js → transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts} +1 -1
  70. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +24 -0
  71. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +151 -0
  72. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +210 -0
  73. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +5 -1
  74. package/transform/index.js +5 -1
  75. package/transform/injectable-transform.js +30 -38
  76. package/import/typings/decorator/interface/provider.d.ts +0 -312
  77. package/transform/compiler/src/render3/partial/util.d.ts +0 -16
  78. package/transform/compiler/src/render3/partial/util.js +0 -44
@@ -1,312 +0,0 @@
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 { Type } from '../../interface/type';
9
- /**
10
- * Configures the `Injector` to return a value for a token.
11
- * Base for `ValueProvider` decorator.
12
- *
13
- * @publicApi
14
- */
15
- export interface ValueSansProvider {
16
- /**
17
- * The value to inject.
18
- */
19
- useValue: any;
20
- }
21
- /**
22
- * Configures the `Injector` to return a value for a token.
23
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
24
- *
25
- * @usageNotes
26
- *
27
- * ### Example
28
- *
29
- * {@example core/di/ts/provider_spec.ts region='ValueProvider'}
30
- *
31
- * ### Multi-value example
32
- *
33
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
34
- *
35
- * @publicApi
36
- */
37
- export interface ValueProvider extends ValueSansProvider {
38
- /**
39
- * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
40
- */
41
- provide: any;
42
- /**
43
- * When true, injector returns an array of instances. This is useful to allow multiple
44
- * providers spread across many files to provide configuration information to a common token.
45
- */
46
- multi?: boolean;
47
- }
48
- /**
49
- * Configures the `Injector` to return an instance of `useClass` for a token.
50
- * Base for `StaticClassProvider` decorator.
51
- *
52
- * @publicApi
53
- */
54
- export interface StaticClassSansProvider {
55
- /**
56
- * An optional class to instantiate for the `token`. By default, the `provide`
57
- * class is instantiated.
58
- */
59
- useClass: Type<any>;
60
- /**
61
- * A list of `token`s to be resolved by the injector. The list of values is then
62
- * used as arguments to the `useClass` constructor.
63
- */
64
- deps: any[];
65
- }
66
- /**
67
- * Configures the `Injector` to return an instance of `useClass` for a token.
68
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
69
- *
70
- * @usageNotes
71
- *
72
- * {@example core/di/ts/provider_spec.ts region='StaticClassProvider'}
73
- *
74
- * Note that following two providers are not equal:
75
- *
76
- * {@example core/di/ts/provider_spec.ts region='StaticClassProviderDifference'}
77
- *
78
- * ### Multi-value example
79
- *
80
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
81
- *
82
- * @publicApi
83
- */
84
- export interface StaticClassProvider extends StaticClassSansProvider {
85
- /**
86
- * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
87
- */
88
- provide: any;
89
- /**
90
- * When true, injector returns an array of instances. This is useful to allow multiple
91
- * providers spread across many files to provide configuration information to a common token.
92
- */
93
- multi?: boolean;
94
- }
95
- /**
96
- * Configures the `Injector` to return an instance of a token.
97
- *
98
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
99
- *
100
- * @usageNotes
101
- *
102
- * ```ts
103
- * @Injectable(SomeModule, {deps: []})
104
- * class MyService {}
105
- * ```
106
- *
107
- * @publicApi
108
- */
109
- export interface ConstructorSansProvider {
110
- /**
111
- * A list of `token`s to be resolved by the injector.
112
- */
113
- deps?: any[];
114
- }
115
- /**
116
- * Configures the `Injector` to return an instance of a token.
117
- *
118
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
119
- *
120
- * @usageNotes
121
- *
122
- * {@example core/di/ts/provider_spec.ts region='ConstructorProvider'}
123
- *
124
- * ### Multi-value example
125
- *
126
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
127
- *
128
- * @publicApi
129
- */
130
- export interface ConstructorProvider extends ConstructorSansProvider {
131
- /**
132
- * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
133
- */
134
- provide: Type<any>;
135
- /**
136
- * When true, injector returns an array of instances. This is useful to allow multiple
137
- * providers spread across many files to provide configuration information to a common token.
138
- */
139
- multi?: boolean;
140
- }
141
- /**
142
- * Configures the `Injector` to return a value of another `useExisting` token.
143
- *
144
- * @see `ExistingProvider`
145
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
146
- *
147
- * @publicApi
148
- */
149
- export interface ExistingSansProvider {
150
- /**
151
- * Existing `token` to return. (Equivalent to `injector.get(useExisting)`)
152
- */
153
- useExisting: any;
154
- }
155
- /**
156
- * Configures the `Injector` to return a value of another `useExisting` token.
157
- *
158
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
159
- *
160
- * @usageNotes
161
- *
162
- * {@example core/di/ts/provider_spec.ts region='ExistingProvider'}
163
- *
164
- * ### Multi-value example
165
- *
166
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
167
- *
168
- * @publicApi
169
- */
170
- export interface ExistingProvider extends ExistingSansProvider {
171
- /**
172
- * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
173
- */
174
- provide: any;
175
- /**
176
- * When true, injector returns an array of instances. This is useful to allow multiple
177
- * providers spread across many files to provide configuration information to a common token.
178
- */
179
- multi?: boolean;
180
- }
181
- /**
182
- * Configures the `Injector` to return a value by invoking a `useFactory` function.
183
- *
184
- * @see `FactoryProvider`
185
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
186
- *
187
- * @publicApi
188
- */
189
- export interface FactorySansProvider {
190
- /**
191
- * A function to invoke to create a value for this `token`. The function is invoked with
192
- * resolved values of `token`s in the `deps` field.
193
- */
194
- useFactory: Function;
195
- /**
196
- * A list of `token`s to be resolved by the injector. The list of values is then
197
- * used as arguments to the `useFactory` function.
198
- */
199
- deps?: any[];
200
- }
201
- /**
202
- * Configures the `Injector` to return a value by invoking a `useFactory` function.
203
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
204
- *
205
- * @usageNotes
206
- *
207
- * {@example core/di/ts/provider_spec.ts region='FactoryProvider'}
208
- *
209
- * Dependencies can also be marked as optional:
210
- *
211
- * {@example core/di/ts/provider_spec.ts region='FactoryProviderOptionalDeps'}
212
- *
213
- * ### Multi-value example
214
- *
215
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
216
- *
217
- * @publicApi
218
- */
219
- export interface FactoryProvider extends FactorySansProvider {
220
- /**
221
- * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
222
- */
223
- provide: any;
224
- /**
225
- * When true, injector returns an array of instances. This is useful to allow multiple
226
- * providers spread across many files to provide configuration information to a common token.
227
- */
228
- multi?: boolean;
229
- }
230
- /**
231
- * Describes how an `Injector` should be configured as static (that is, without reflection).
232
- * A static provider provides tokens to an injector for various types of dependencies.
233
- *
234
- * @see `Injector.create()`.
235
- * @see ["Dependency Injection Guide"](guide/dependency-injection-providers).
236
- *
237
- * @publicApi
238
- */
239
- export declare type StaticProvider = ValueProvider | ExistingProvider | StaticClassProvider | ConstructorProvider | FactoryProvider | any[];
240
- /**
241
- * Configures the `Injector` to return an instance of `Type` when `Type' is used as the token.
242
- *
243
- * Create an instance by invoking the `new` operator and supplying additional arguments.
244
- * This form is a short form of `TypeProvider`;
245
- *
246
- * For more details, see the ["Dependency Injection Guide"](guide/dependency-injection).
247
- *
248
- * @usageNotes
249
- *
250
- * {@example core/di/ts/provider_spec.ts region='TypeProvider'}
251
- *
252
- * @publicApi
253
- */
254
- export interface TypeProvider extends Type<any> {
255
- }
256
- /**
257
- * Configures the `Injector` to return a value by invoking a `useClass` function.
258
- * Base for `ClassProvider` decorator.
259
- *
260
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
261
- *
262
- * @publicApi
263
- */
264
- export interface ClassSansProvider {
265
- /**
266
- * Class to instantiate for the `token`.
267
- */
268
- useClass: Type<any>;
269
- }
270
- /**
271
- * Configures the `Injector` to return an instance of `useClass` for a token.
272
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
273
- *
274
- * @usageNotes
275
- *
276
- * {@example core/di/ts/provider_spec.ts region='ClassProvider'}
277
- *
278
- * Note that following two providers are not equal:
279
- *
280
- * {@example core/di/ts/provider_spec.ts region='ClassProviderDifference'}
281
- *
282
- * ### Multi-value example
283
- *
284
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
285
- *
286
- * @publicApi
287
- */
288
- export interface ClassProvider extends ClassSansProvider {
289
- /**
290
- * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
291
- */
292
- provide: any;
293
- /**
294
- * When true, injector returns an array of instances. This is useful to allow multiple
295
- * providers spread across many files to provide configuration information to a common token.
296
- */
297
- multi?: boolean;
298
- }
299
- /**
300
- * Describes how the `Injector` should be configured.
301
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
302
- *
303
- * @see `StaticProvider`
304
- *
305
- * @publicApi
306
- */
307
- export declare type Provider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | any[];
308
- /**
309
- * Describes a function that is used to process provider lists (such as provider
310
- * overrides).
311
- */
312
- export declare type ProcessProvidersFunction = (providers: Provider[]) => Provider[];
@@ -1,16 +0,0 @@
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 * as o from "../../output/output_ast";
9
- /**
10
- * Generate an expression that has the given `expr` wrapped in the following form:
11
- *
12
- * ```
13
- * forwardRef(() => expr)
14
- * ```
15
- */
16
- export declare function generateForwardRef(expr: o.Expression): o.Expression;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.generateForwardRef = void 0;
23
- /**
24
- * @license
25
- * Copyright Google LLC All Rights Reserved.
26
- *
27
- * Use of this source code is governed by an MIT-style license that can be
28
- * found in the LICENSE file at https://angular.io/license
29
- */
30
- const o = __importStar(require("../../output/output_ast"));
31
- const r3_identifiers_1 = require("../r3_identifiers");
32
- /**
33
- * Generate an expression that has the given `expr` wrapped in the following form:
34
- *
35
- * ```
36
- * forwardRef(() => expr)
37
- * ```
38
- */
39
- function generateForwardRef(expr) {
40
- return o
41
- .importExpr(r3_identifiers_1.Identifiers.forwardRef)
42
- .callFn([o.fn([], [new o.ReturnStatement(expr)])]);
43
- }
44
- exports.generateForwardRef = generateForwardRef;