static-injector 2.1.1 → 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 (96) hide show
  1. package/import/commonjs/index.js +127 -197
  2. package/import/{es2015 → es2022}/di/create_injector.js +0 -2
  3. package/import/{es2015 → es2022}/di/forward_ref.js +29 -2
  4. package/import/{es2015 → es2022}/di/injection_token.js +5 -3
  5. package/import/{es2015 → es2022}/di/injector.js +15 -16
  6. package/import/{es2015 → es2022}/di/injector_compatibility.js +8 -3
  7. package/import/{es2015 → es2022}/di/interface/defs.js +2 -16
  8. package/import/{es2015 → es2022}/di/interface/injector.js +1 -1
  9. package/import/es2022/di/provider_collection.js +104 -0
  10. package/import/{es2015 → es2022}/di/r3_injector.js +46 -15
  11. package/import/{es2015 → es2022}/errors.js +4 -2
  12. package/import/{es2015 → es2022}/render3/error_code.js +1 -0
  13. package/import/es2022/render3/fields.js +22 -0
  14. package/import/{fesm2015 → fesm2022}/index.js +127 -198
  15. package/import/typings/di/create_injector.d.ts +3 -5
  16. package/import/typings/di/forward_ref.d.ts +29 -2
  17. package/import/typings/di/inject_switch.d.ts +1 -1
  18. package/import/typings/di/injection_token.d.ts +1 -1
  19. package/import/typings/di/injector.d.ts +3 -3
  20. package/import/typings/di/injector_compatibility.d.ts +1 -0
  21. package/import/typings/di/interface/defs.d.ts +2 -1
  22. package/import/typings/di/interface/injector.d.ts +2 -2
  23. package/import/typings/di/interface/provider.d.ts +7 -7
  24. package/import/typings/di/metadata.d.ts +4 -4
  25. package/import/typings/di/provider_collection.d.ts +1 -12
  26. package/import/typings/di/r3_injector.d.ts +8 -6
  27. package/import/typings/di/scope.d.ts +1 -1
  28. package/import/typings/errors.d.ts +28 -3
  29. package/import/typings/render3/fields.d.ts +9 -0
  30. package/import/typings/util/decorators.d.ts +1 -0
  31. package/package.json +7 -7
  32. package/readme.md +4 -1
  33. package/transform/compiler/src/injectable_compiler_2.d.ts +0 -1
  34. package/transform/compiler/src/injectable_compiler_2.js +31 -16
  35. package/transform/compiler/src/output/output_ast.d.ts +53 -10
  36. package/transform/compiler/src/output/output_ast.js +211 -12
  37. package/transform/compiler/src/parse_util.js +10 -0
  38. package/transform/compiler/src/render3/partial/api.js +1 -1
  39. package/transform/compiler/src/render3/r3_factory.d.ts +0 -8
  40. package/transform/compiler/src/render3/r3_factory.js +5 -4
  41. package/transform/compiler/src/render3/r3_identifiers.js +37 -37
  42. package/transform/compiler/src/render3/view/util.js +1 -3
  43. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +2 -4
  44. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +1 -0
  45. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +1 -1
  46. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +5 -9
  47. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +2 -1
  48. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +12 -8
  49. package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +2 -2
  50. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +8 -4
  51. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +1 -1
  52. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +1 -2
  53. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +24 -173
  54. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +2 -51
  55. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +5 -3
  56. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +5 -10
  57. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +5 -23
  58. package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -21
  59. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +1 -2
  60. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +7 -0
  61. package/transform/compiler-cli/src/ngtsc/translator/src/context.js +1 -0
  62. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -2
  63. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +1 -0
  64. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +10 -4
  65. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +2 -1
  66. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +20 -16
  67. package/transform/injectable-transform.d.ts +2 -2
  68. package/transform/injectable-transform.js +32 -6
  69. package/import/es2015/di/provider_collection.js +0 -244
  70. package/import/es2015/render3/fields.js +0 -11
  71. /package/import/{es2015 → es2022}/di/initializer_token.js +0 -0
  72. /package/import/{es2015 → es2022}/di/inject_switch.js +0 -0
  73. /package/import/{es2015 → es2022}/di/injectable.js +0 -0
  74. /package/import/{es2015 → es2022}/di/injector_marker.js +0 -0
  75. /package/import/{es2015 → es2022}/di/injector_token.js +0 -0
  76. /package/import/{es2015 → es2022}/di/interface/provider.js +0 -0
  77. /package/import/{es2015 → es2022}/di/internal_tokens.js +0 -0
  78. /package/import/{es2015 → es2022}/di/metadata.js +0 -0
  79. /package/import/{es2015 → es2022}/di/null_injector.js +0 -0
  80. /package/import/{es2015 → es2022}/di/provider_token.js +0 -0
  81. /package/import/{es2015 → es2022}/di/scope.js +0 -0
  82. /package/import/{es2015 → es2022}/error_details_base_url.js +0 -0
  83. /package/import/{es2015 → es2022}/index.js +0 -0
  84. /package/import/{es2015 → es2022}/interface/lifecycle_hooks.js +0 -0
  85. /package/import/{es2015 → es2022}/interface/type.js +0 -0
  86. /package/import/{es2015 → es2022}/render3/definition_factory.js +0 -0
  87. /package/import/{es2015 → es2022}/render3/di.js +0 -0
  88. /package/import/{es2015 → es2022}/render3/errors_di.js +0 -0
  89. /package/import/{es2015 → es2022}/render3/instructions/di.js +0 -0
  90. /package/import/{es2015 → es2022}/render3/util/stringify_utils.js +0 -0
  91. /package/import/{es2015 → es2022}/util/array_utils.js +0 -0
  92. /package/import/{es2015 → es2022}/util/closure.js +0 -0
  93. /package/import/{es2015 → es2022}/util/decorators.js +0 -0
  94. /package/import/{es2015 → es2022}/util/empty.js +0 -0
  95. /package/import/{es2015 → es2022}/util/property.js +0 -0
  96. /package/import/{es2015 → es2022}/util/stringify.js +0 -0
@@ -1,244 +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 { getFactoryDef } from '../render3/definition_factory';
9
- import { deepForEach } from '../util/array_utils';
10
- import { EMPTY_ARRAY } from '../util/empty';
11
- import { getClosureSafeProperty } from '../util/property';
12
- import { resolveForwardRef } from './forward_ref';
13
- import { ENVIRONMENT_INITIALIZER } from './initializer_token';
14
- import { ɵɵinject as inject } from './injector_compatibility';
15
- import { getInjectorDef, } from './interface/defs';
16
- import { isEnvironmentProviders, } from './interface/provider';
17
- import { INJECTOR_DEF_TYPES } from './internal_tokens';
18
- /**
19
- * Wrap an array of `Provider`s into `EnvironmentProviders`, preventing them from being accidentally
20
- * referenced in `@Component in a component injector.
21
- */
22
- export function makeEnvironmentProviders(providers) {
23
- return {
24
- ɵproviders: providers,
25
- };
26
- }
27
- /**
28
- * Collects providers from all NgModules and standalone components, including transitively imported
29
- * ones.
30
- *
31
- * Providers extracted via `importProvidersFrom` are only usable in an application injector or
32
- * another environment injector (such as a route injector). They should not be used in component
33
- * providers.
34
- *
35
- * More information about standalone components can be found in [this
36
- * guide](guide/standalone-components).
37
- *
38
- * @usageNotes
39
- * The results of the `importProvidersFrom` call can be used in the `bootstrapApplication` call:
40
- *
41
- * ```typescript
42
- * await bootstrapApplication(RootComponent, {
43
- * providers: [
44
- * importProvidersFrom(NgModuleOne, NgModuleTwo)
45
- * ]
46
- * });
47
- * ```
48
- *
49
- * You can also use the `importProvidersFrom` results in the `providers` field of a route, when a
50
- * standalone component is used:
51
- *
52
- * ```typescript
53
- * export const ROUTES: Route[] = [
54
- * {
55
- * path: 'foo',
56
- * providers: [
57
- * importProvidersFrom(NgModuleOne, NgModuleTwo)
58
- * ],
59
- * component: YourStandaloneComponent
60
- * }
61
- * ];
62
- * ```
63
- *
64
- * @returns Collected providers from the specified list of types.
65
- * @publicApi
66
- */
67
- export function importProvidersFrom(...sources) {
68
- return {
69
- ɵproviders: internalImportProvidersFrom(true, sources),
70
- ɵfromNgModule: true,
71
- };
72
- }
73
- export function internalImportProvidersFrom(checkForStandaloneCmp, ...sources) {
74
- const providersOut = [];
75
- const dedup = new Set(); // already seen types
76
- let injectorTypesWithProviders;
77
- // Collect all providers from `ModuleWithProviders` types.
78
- if (injectorTypesWithProviders !== undefined) {
79
- processInjectorTypesWithProviders(injectorTypesWithProviders, providersOut);
80
- }
81
- return providersOut;
82
- }
83
- /**
84
- * Collects all providers from the list of `ModuleWithProviders` and appends them to the provided
85
- * array.
86
- */
87
- function processInjectorTypesWithProviders(typesWithProviders, providersOut) {
88
- for (let i = 0; i < typesWithProviders.length; i++) {
89
- const { ngModule, providers } = typesWithProviders[i];
90
- }
91
- }
92
- /**
93
- * The logic visits an `InjectorType`, an `InjectorTypeWithProviders`, or a standalone
94
- * `ComponentType`, and all of its transitive providers and collects providers.
95
- *
96
- * If an `InjectorTypeWithProviders` that declares providers besides the type is specified,
97
- * the function will return "true" to indicate that the providers of the type definition need
98
- * to be processed. This allows us to process providers of injector types after all imports of
99
- * an injector definition are processed. (following View Engine semantics: see FW-1349)
100
- */
101
- export function walkProviderTree(container, providersOut, parents, dedup) {
102
- container = resolveForwardRef(container);
103
- if (!container)
104
- return false;
105
- // The actual type which had the definition. Usually `container`, but may be an unwrapped type
106
- // from `InjectorTypeWithProviders`.
107
- let defType = null;
108
- let injDef = getInjectorDef(container);
109
- const cmpDef = !injDef && null;
110
- if (!injDef && !cmpDef) {
111
- // `container` is not an injector type or a component type. It might be:
112
- // * An `InjectorTypeWithProviders` that wraps an injector type.
113
- // * A standalone directive or pipe that got pulled in from a standalone component's
114
- // dependencies.
115
- // Try to unwrap it as an `InjectorTypeWithProviders` first.
116
- const ngModule = container.ngModule;
117
- injDef = getInjectorDef(ngModule);
118
- if (injDef) {
119
- defType = ngModule;
120
- }
121
- else {
122
- // Not a component or injector type, so ignore it.
123
- return false;
124
- }
125
- }
126
- else if (cmpDef && !cmpDef.standalone) {
127
- return false;
128
- }
129
- else {
130
- defType = container;
131
- }
132
- // Check for circular dependencies.
133
- if (false) {
134
- }
135
- // Check for multiple imports of the same module
136
- const isDuplicate = dedup.has(defType);
137
- if (cmpDef) {
138
- if (isDuplicate) {
139
- // This component definition has already been processed.
140
- return false;
141
- }
142
- dedup.add(defType);
143
- if (cmpDef.dependencies) {
144
- const deps = typeof cmpDef.dependencies === 'function'
145
- ? cmpDef.dependencies()
146
- : cmpDef.dependencies;
147
- for (const dep of deps) {
148
- walkProviderTree(dep, providersOut, parents, dedup);
149
- }
150
- }
151
- }
152
- else if (injDef) {
153
- // First, include providers from any imports.
154
- if (injDef.imports != null && !isDuplicate) {
155
- // Before processing defType's imports, add it to the set of parents. This way, if it ends
156
- // up deeply importing itself, this can be detected.
157
- // Add it to the set of dedups. This way we can detect multiple imports of the same module
158
- dedup.add(defType);
159
- let importTypesWithProviders;
160
- try {
161
- deepForEach(injDef.imports, (imported) => {
162
- if (walkProviderTree(imported, providersOut, parents, dedup)) {
163
- importTypesWithProviders || (importTypesWithProviders = []);
164
- // If the processed import is an injector type with providers, we store it in the
165
- // list of import types with providers, so that we can process those afterwards.
166
- importTypesWithProviders.push(imported);
167
- }
168
- });
169
- }
170
- finally {
171
- // Remove it from the parents set when finished.
172
- }
173
- // Imports which are declared with providers (TypeWithProviders) need to be processed
174
- // after all imported modules are processed. This is similar to how View Engine
175
- // processes/merges module imports in the metadata resolver. See: FW-1349.
176
- if (importTypesWithProviders !== undefined) {
177
- processInjectorTypesWithProviders(importTypesWithProviders, providersOut);
178
- }
179
- }
180
- if (!isDuplicate) {
181
- // Track the InjectorType and add a provider for it.
182
- // It's important that this is done after the def's imports.
183
- const factory = getFactoryDef(defType) || (() => new defType());
184
- // Append extra providers to make more info available for consumers (to retrieve an injector
185
- // type), as well as internally (to calculate an injection scope correctly and eagerly
186
- // instantiate a `defType` when an injector is created).
187
- providersOut.push(
188
- // Provider to create `defType` using its factory.
189
- { provide: defType, useFactory: factory, deps: EMPTY_ARRAY },
190
- // Make this `defType` available to an internal logic that calculates injector scope.
191
- { provide: INJECTOR_DEF_TYPES, useValue: defType, multi: true },
192
- // Provider to eagerly instantiate `defType` via `ENVIRONMENT_INITIALIZER`.
193
- {
194
- provide: ENVIRONMENT_INITIALIZER,
195
- useValue: () => inject(defType),
196
- multi: true,
197
- } //
198
- );
199
- }
200
- // Next, include providers listed on the definition itself.
201
- const defProviders = injDef.providers;
202
- if (defProviders != null && !isDuplicate) {
203
- const injectorType = container;
204
- }
205
- }
206
- else {
207
- // Should not happen, but just in case.
208
- return false;
209
- }
210
- return (defType !== container &&
211
- container.providers !== undefined);
212
- }
213
- function deepForEachProvider(providers, fn) {
214
- for (let provider of providers) {
215
- if (isEnvironmentProviders(provider)) {
216
- provider = provider.ɵproviders;
217
- }
218
- if (Array.isArray(provider)) {
219
- deepForEachProvider(provider, fn);
220
- }
221
- else {
222
- fn(provider);
223
- }
224
- }
225
- }
226
- export const USE_VALUE = getClosureSafeProperty({
227
- provide: String,
228
- useValue: getClosureSafeProperty,
229
- });
230
- export function isValueProvider(value) {
231
- return value !== null && typeof value == 'object' && USE_VALUE in value;
232
- }
233
- export function isExistingProvider(value) {
234
- return !!(value && value.useExisting);
235
- }
236
- export function isFactoryProvider(value) {
237
- return !!(value && value.useFactory);
238
- }
239
- export function isTypeProvider(value) {
240
- return typeof value === 'function';
241
- }
242
- export function isClassProvider(value) {
243
- return !!value.useClass;
244
- }
@@ -1,11 +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 { getClosureSafeProperty } from '../util/property';
9
- export const NG_FACTORY_DEF = getClosureSafeProperty({
10
- ɵfac: getClosureSafeProperty,
11
- });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes