static-injector 2.1.1 → 2.2.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.
- package/import/commonjs/index.js +127 -197
- package/import/{es2015 → es2022}/di/create_injector.js +0 -2
- package/import/{es2015 → es2022}/di/forward_ref.js +29 -2
- package/import/{es2015 → es2022}/di/injection_token.js +5 -3
- package/import/{es2015 → es2022}/di/injector.js +15 -16
- package/import/{es2015 → es2022}/di/injector_compatibility.js +8 -3
- package/import/{es2015 → es2022}/di/interface/defs.js +2 -16
- package/import/{es2015 → es2022}/di/interface/injector.js +1 -1
- package/import/es2022/di/provider_collection.js +104 -0
- package/import/{es2015 → es2022}/di/r3_injector.js +46 -15
- package/import/{es2015 → es2022}/errors.js +4 -2
- package/import/{es2015 → es2022}/render3/error_code.js +1 -0
- package/import/es2022/render3/fields.js +22 -0
- package/import/{fesm2015 → fesm2022}/index.js +127 -198
- package/import/typings/di/create_injector.d.ts +3 -5
- package/import/typings/di/forward_ref.d.ts +29 -2
- package/import/typings/di/inject_switch.d.ts +1 -1
- package/import/typings/di/injection_token.d.ts +1 -1
- package/import/typings/di/injector.d.ts +3 -3
- package/import/typings/di/injector_compatibility.d.ts +1 -0
- package/import/typings/di/interface/defs.d.ts +2 -1
- package/import/typings/di/interface/injector.d.ts +2 -2
- package/import/typings/di/interface/provider.d.ts +7 -7
- package/import/typings/di/metadata.d.ts +4 -4
- package/import/typings/di/provider_collection.d.ts +1 -12
- package/import/typings/di/r3_injector.d.ts +8 -6
- package/import/typings/di/scope.d.ts +1 -1
- package/import/typings/errors.d.ts +28 -3
- package/import/typings/render3/fields.d.ts +9 -0
- package/import/typings/util/decorators.d.ts +1 -0
- package/package.json +7 -7
- package/readme.md +4 -1
- package/transform/compiler/src/injectable_compiler_2.d.ts +0 -1
- package/transform/compiler/src/injectable_compiler_2.js +31 -16
- package/transform/compiler/src/output/output_ast.d.ts +53 -10
- package/transform/compiler/src/output/output_ast.js +211 -12
- package/transform/compiler/src/parse_util.js +10 -0
- package/transform/compiler/src/render3/partial/api.js +1 -1
- package/transform/compiler/src/render3/r3_factory.d.ts +0 -8
- package/transform/compiler/src/render3/r3_factory.js +5 -4
- package/transform/compiler/src/render3/r3_identifiers.js +37 -37
- package/transform/compiler/src/render3/view/util.js +1 -3
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +2 -4
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +1 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +5 -9
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +2 -1
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +12 -8
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +8 -4
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +1 -1
- package/transform/compiler-cli/src/ngtsc/imports/src/default.js +1 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +24 -173
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +2 -51
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +5 -3
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +5 -10
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +5 -23
- package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -21
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +1 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +7 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/context.js +1 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +1 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +10 -4
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +2 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +20 -16
- package/transform/injectable-transform.d.ts +2 -2
- package/transform/injectable-transform.js +32 -6
- package/import/es2015/di/provider_collection.js +0 -244
- package/import/es2015/render3/fields.js +0 -11
- /package/import/{es2015 → es2022}/di/initializer_token.js +0 -0
- /package/import/{es2015 → es2022}/di/inject_switch.js +0 -0
- /package/import/{es2015 → es2022}/di/injectable.js +0 -0
- /package/import/{es2015 → es2022}/di/injector_marker.js +0 -0
- /package/import/{es2015 → es2022}/di/injector_token.js +0 -0
- /package/import/{es2015 → es2022}/di/interface/provider.js +0 -0
- /package/import/{es2015 → es2022}/di/internal_tokens.js +0 -0
- /package/import/{es2015 → es2022}/di/metadata.js +0 -0
- /package/import/{es2015 → es2022}/di/null_injector.js +0 -0
- /package/import/{es2015 → es2022}/di/provider_token.js +0 -0
- /package/import/{es2015 → es2022}/di/scope.js +0 -0
- /package/import/{es2015 → es2022}/error_details_base_url.js +0 -0
- /package/import/{es2015 → es2022}/index.js +0 -0
- /package/import/{es2015 → es2022}/interface/lifecycle_hooks.js +0 -0
- /package/import/{es2015 → es2022}/interface/type.js +0 -0
- /package/import/{es2015 → es2022}/render3/definition_factory.js +0 -0
- /package/import/{es2015 → es2022}/render3/di.js +0 -0
- /package/import/{es2015 → es2022}/render3/errors_di.js +0 -0
- /package/import/{es2015 → es2022}/render3/instructions/di.js +0 -0
- /package/import/{es2015 → es2022}/render3/util/stringify_utils.js +0 -0
- /package/import/{es2015 → es2022}/util/array_utils.js +0 -0
- /package/import/{es2015 → es2022}/util/closure.js +0 -0
- /package/import/{es2015 → es2022}/util/decorators.js +0 -0
- /package/import/{es2015 → es2022}/util/empty.js +0 -0
- /package/import/{es2015 → es2022}/util/property.js +0 -0
- /package/import/{es2015 → es2022}/util/stringify.js +0 -0
|
@@ -11,6 +11,7 @@ import { ProviderToken } from './provider_token';
|
|
|
11
11
|
export declare const THROW_IF_NOT_FOUND: {};
|
|
12
12
|
export declare const NG_TEMP_TOKEN_PATH = "ngTempTokenPath";
|
|
13
13
|
export declare const SOURCE = "__source";
|
|
14
|
+
export declare function getCurrentInjector(): Injector | undefined | null;
|
|
14
15
|
export declare function setCurrentInjector(injector: Injector | null | undefined): Injector | undefined | null;
|
|
15
16
|
export declare function injectInjectorOnly<T>(token: ProviderToken<T>): T;
|
|
16
17
|
export declare function injectInjectorOnly<T>(token: ProviderToken<T>, flags?: InjectFlags): T | null;
|
|
@@ -114,7 +114,8 @@ export interface InjectorTypeWithProviders<T> {
|
|
|
114
114
|
* with an `@NgModule` or other `InjectorType`, or by specifying that this injectable should be
|
|
115
115
|
* provided in the `'root'` injector, which will be the application-level injector in most apps.
|
|
116
116
|
* * `factory` gives the zero argument function which will create an instance of the injectable.
|
|
117
|
-
* The factory can call `inject` to access the `Injector` and request injection
|
|
117
|
+
* The factory can call [`inject`](api/core/inject) to access the `Injector` and request injection
|
|
118
|
+
* of dependencies.
|
|
118
119
|
*
|
|
119
120
|
* @codeGenApi
|
|
120
121
|
* @publicApi This instruction has been emitted by ViewEngine for some time and is deployed to npm.
|
|
@@ -17,7 +17,7 @@ export declare const enum DecoratorFlags {
|
|
|
17
17
|
* Injection flags for DI.
|
|
18
18
|
*
|
|
19
19
|
* @publicApi
|
|
20
|
-
* @deprecated use an options object for `inject` instead.
|
|
20
|
+
* @deprecated use an options object for [`inject`](api/core/inject) instead.
|
|
21
21
|
*/
|
|
22
22
|
export declare enum InjectFlags {
|
|
23
23
|
/** Check self and check parent injector if needed */
|
|
@@ -48,7 +48,7 @@ export declare const enum InternalInjectFlags {
|
|
|
48
48
|
Optional = 8
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* Type of the options argument to `inject
|
|
51
|
+
* Type of the options argument to [`inject`](api/core/inject).
|
|
52
52
|
*
|
|
53
53
|
* @publicApi
|
|
54
54
|
*/
|
|
@@ -141,7 +141,7 @@ export interface ConstructorProvider extends ConstructorSansProvider {
|
|
|
141
141
|
/**
|
|
142
142
|
* Configures the `Injector` to return a value of another `useExisting` token.
|
|
143
143
|
*
|
|
144
|
-
* @see
|
|
144
|
+
* @see {@link ExistingProvider}
|
|
145
145
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
146
146
|
*
|
|
147
147
|
* @publicApi
|
|
@@ -181,7 +181,7 @@ export interface ExistingProvider extends ExistingSansProvider {
|
|
|
181
181
|
/**
|
|
182
182
|
* Configures the `Injector` to return a value by invoking a `useFactory` function.
|
|
183
183
|
*
|
|
184
|
-
* @see
|
|
184
|
+
* @see {@link FactoryProvider}
|
|
185
185
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
186
186
|
*
|
|
187
187
|
* @publicApi
|
|
@@ -231,7 +231,7 @@ export interface FactoryProvider extends FactorySansProvider {
|
|
|
231
231
|
* Describes how an `Injector` should be configured as static (that is, without reflection).
|
|
232
232
|
* A static provider provides tokens to an injector for various types of dependencies.
|
|
233
233
|
*
|
|
234
|
-
* @see
|
|
234
|
+
* @see {@link Injector.create()}
|
|
235
235
|
* @see ["Dependency Injection Guide"](guide/dependency-injection-providers).
|
|
236
236
|
*
|
|
237
237
|
* @publicApi
|
|
@@ -300,7 +300,7 @@ export interface ClassProvider extends ClassSansProvider {
|
|
|
300
300
|
* Describes how the `Injector` should be configured.
|
|
301
301
|
* @see ["Dependency Injection Guide"](guide/dependency-injection).
|
|
302
302
|
*
|
|
303
|
-
* @see
|
|
303
|
+
* @see {@link StaticProvider}
|
|
304
304
|
*
|
|
305
305
|
* @publicApi
|
|
306
306
|
*/
|
|
@@ -315,8 +315,8 @@ export type Provider = TypeProvider | ValueProvider | ClassProvider | Constructo
|
|
|
315
315
|
*
|
|
316
316
|
* This wrapper type prevents access to the `Provider`s inside.
|
|
317
317
|
*
|
|
318
|
-
* @see
|
|
319
|
-
* @see
|
|
318
|
+
* @see {@link makeEnvironmentProviders}
|
|
319
|
+
* @see {@link importProvidersFrom}
|
|
320
320
|
*
|
|
321
321
|
* @publicApi
|
|
322
322
|
*/
|
|
@@ -359,7 +359,7 @@ export interface ModuleWithProviders<T> {
|
|
|
359
359
|
* This type cannot be directly implemented. It's returned from the `importProvidersFrom` function
|
|
360
360
|
* and serves to prevent the extracted NgModule providers from being used in the wrong contexts.
|
|
361
361
|
*
|
|
362
|
-
* @see
|
|
362
|
+
* @see {@link importProvidersFrom}
|
|
363
363
|
*
|
|
364
364
|
* @publicApi
|
|
365
365
|
* @deprecated replaced by `EnvironmentProviders`
|
|
@@ -111,8 +111,8 @@ export interface SelfDecorator {
|
|
|
111
111
|
* <code-example path="core/di/ts/metadata_spec.ts" region="Self">
|
|
112
112
|
* </code-example>
|
|
113
113
|
*
|
|
114
|
-
* @see
|
|
115
|
-
* @see
|
|
114
|
+
* @see {@link SkipSelf}
|
|
115
|
+
* @see {@link Optional}
|
|
116
116
|
*
|
|
117
117
|
*/
|
|
118
118
|
(): any;
|
|
@@ -153,8 +153,8 @@ export interface SkipSelfDecorator {
|
|
|
153
153
|
* </code-example>
|
|
154
154
|
*
|
|
155
155
|
* @see [Dependency Injection guide](guide/dependency-injection-in-action#skip).
|
|
156
|
-
* @see
|
|
157
|
-
* @see
|
|
156
|
+
* @see {@link Self}
|
|
157
|
+
* @see {@link Optional}
|
|
158
158
|
*
|
|
159
159
|
*/
|
|
160
160
|
(): any;
|
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
import { Type } from '../interface/type';
|
|
9
|
-
import { InjectorTypeWithProviders } from './interface/defs';
|
|
10
9
|
import { ClassProvider, ConstructorProvider, EnvironmentProviders, ExistingProvider, FactoryProvider, ModuleWithProviders, Provider, StaticClassProvider, TypeProvider, ValueProvider } from './interface/provider';
|
|
11
10
|
/**
|
|
12
11
|
* Wrap an array of `Provider`s into `EnvironmentProviders`, preventing them from being accidentally
|
|
13
|
-
* referenced in `@Component in a component injector.
|
|
12
|
+
* referenced in `@Component` in a component injector.
|
|
14
13
|
*/
|
|
15
14
|
export declare function makeEnvironmentProviders(providers: (Provider | EnvironmentProviders)[]): EnvironmentProviders;
|
|
16
15
|
/**
|
|
@@ -65,16 +64,6 @@ export declare function internalImportProvidersFrom(checkForStandaloneCmp: boole
|
|
|
65
64
|
* Internal type for a single provider in a deep provider array.
|
|
66
65
|
*/
|
|
67
66
|
export type SingleProvider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | StaticClassProvider;
|
|
68
|
-
/**
|
|
69
|
-
* The logic visits an `InjectorType`, an `InjectorTypeWithProviders`, or a standalone
|
|
70
|
-
* `ComponentType`, and all of its transitive providers and collects providers.
|
|
71
|
-
*
|
|
72
|
-
* If an `InjectorTypeWithProviders` that declares providers besides the type is specified,
|
|
73
|
-
* the function will return "true" to indicate that the providers of the type definition need
|
|
74
|
-
* to be processed. This allows us to process providers of injector types after all imports of
|
|
75
|
-
* an injector definition are processed. (following View Engine semantics: see FW-1349)
|
|
76
|
-
*/
|
|
77
|
-
export declare function walkProviderTree(container: Type<unknown> | InjectorTypeWithProviders<unknown>, providersOut: SingleProvider[], parents: Type<unknown>[], dedup: Set<Type<unknown>>): container is InjectorTypeWithProviders<unknown>;
|
|
78
67
|
export declare const USE_VALUE: string;
|
|
79
68
|
export declare function isValueProvider(value: SingleProvider): value is ValueProvider;
|
|
80
69
|
export declare function isExistingProvider(value: SingleProvider): value is ExistingProvider;
|
|
@@ -53,19 +53,20 @@ export declare abstract class EnvironmentInjector implements Injector {
|
|
|
53
53
|
/**
|
|
54
54
|
* Runs the given function in the context of this `EnvironmentInjector`.
|
|
55
55
|
*
|
|
56
|
-
* Within the function's stack frame, `inject` can be used to inject
|
|
57
|
-
* injector. Note that `inject` is only usable synchronously, and cannot be
|
|
58
|
-
* asynchronous callbacks or after any `await` points.
|
|
56
|
+
* Within the function's stack frame, [`inject`](api/core/inject) can be used to inject
|
|
57
|
+
* dependencies from this injector. Note that `inject` is only usable synchronously, and cannot be
|
|
58
|
+
* used in any asynchronous callbacks or after any `await` points.
|
|
59
59
|
*
|
|
60
60
|
* @param fn the closure to be run in the context of this injector
|
|
61
61
|
* @returns the return value of the function, if any
|
|
62
|
+
* @deprecated use the standalone function `runInInjectionContext` instead
|
|
62
63
|
*/
|
|
63
64
|
abstract runInContext<ReturnT>(fn: () => ReturnT): ReturnT;
|
|
64
65
|
abstract destroy(): void;
|
|
65
66
|
/**
|
|
66
67
|
* @internal
|
|
67
68
|
*/
|
|
68
|
-
abstract onDestroy(callback: () => void): void;
|
|
69
|
+
abstract onDestroy(callback: () => void): () => void;
|
|
69
70
|
}
|
|
70
71
|
export declare class R3Injector extends EnvironmentInjector {
|
|
71
72
|
readonly parent: Injector;
|
|
@@ -96,19 +97,20 @@ export declare class R3Injector extends EnvironmentInjector {
|
|
|
96
97
|
* hook was found.
|
|
97
98
|
*/
|
|
98
99
|
destroy(): void;
|
|
99
|
-
onDestroy(callback: () => void): void;
|
|
100
|
+
onDestroy(callback: () => void): () => void;
|
|
100
101
|
runInContext<ReturnT>(fn: () => ReturnT): ReturnT;
|
|
101
102
|
get<T>(token: ProviderToken<T>, notFoundValue?: any, flags?: InjectFlags | InjectOptions): T;
|
|
102
103
|
/** @internal */
|
|
103
104
|
resolveInjectorInitializers(): void;
|
|
104
105
|
toString(): string;
|
|
105
|
-
|
|
106
|
+
assertNotDestroyed(): void;
|
|
106
107
|
/**
|
|
107
108
|
* Process a `SingleProvider` and add it.
|
|
108
109
|
*/
|
|
109
110
|
private processProvider;
|
|
110
111
|
private hydrate;
|
|
111
112
|
private injectableDefInScope;
|
|
113
|
+
private removeOnDestroy;
|
|
112
114
|
}
|
|
113
115
|
/**
|
|
114
116
|
* Converts a `SingleProvider` into a factory function.
|
|
@@ -12,4 +12,4 @@ export type InjectorScope = 'root' | 'platform' | 'environment';
|
|
|
12
12
|
* as a root scoped injector when processing requests for unknown tokens which may indicate
|
|
13
13
|
* they are provided in the root scope.
|
|
14
14
|
*/
|
|
15
|
-
export declare const INJECTOR_SCOPE: InjectionToken<InjectorScope>;
|
|
15
|
+
export declare const INJECTOR_SCOPE: InjectionToken<InjectorScope | null>;
|
|
@@ -14,10 +14,19 @@
|
|
|
14
14
|
* error codes which have guides, which might leak into runtime code.
|
|
15
15
|
*
|
|
16
16
|
* Full list of available error guides can be found at https://angular.io/errors.
|
|
17
|
+
*
|
|
18
|
+
* Error code ranges per package:
|
|
19
|
+
* - core (this package): 100-999
|
|
20
|
+
* - forms: 1000-1999
|
|
21
|
+
* - common: 2000-2999
|
|
22
|
+
* - animations: 3000-3999
|
|
23
|
+
* - router: 4000-4999
|
|
24
|
+
* - platform-browser: 5000-5500
|
|
17
25
|
*/
|
|
18
26
|
export declare const enum RuntimeErrorCode {
|
|
19
27
|
EXPRESSION_CHANGED_AFTER_CHECKED = -100,
|
|
20
28
|
RECURSIVE_APPLICATION_REF_TICK = 101,
|
|
29
|
+
RECURSIVE_APPLICATION_RENDER = 102,
|
|
21
30
|
CYCLIC_DI_DEPENDENCY = -200,
|
|
22
31
|
PROVIDER_NOT_FOUND = -201,
|
|
23
32
|
INVALID_FACTORY_DEPENDENCY = 202,
|
|
@@ -27,6 +36,7 @@ export declare const enum RuntimeErrorCode {
|
|
|
27
36
|
PROVIDER_IN_WRONG_CONTEXT = 207,
|
|
28
37
|
MISSING_INJECTION_TOKEN = 208,
|
|
29
38
|
INVALID_MULTI_PROVIDER = -209,
|
|
39
|
+
MISSING_DOCUMENT = 210,
|
|
30
40
|
MULTIPLE_COMPONENTS_MATCH = -300,
|
|
31
41
|
EXPORT_NOT_FOUND = -301,
|
|
32
42
|
PIPE_NOT_FOUND = -302,
|
|
@@ -40,14 +50,25 @@ export declare const enum RuntimeErrorCode {
|
|
|
40
50
|
HOST_DIRECTIVE_COMPONENT = 310,
|
|
41
51
|
HOST_DIRECTIVE_UNDEFINED_BINDING = 311,
|
|
42
52
|
HOST_DIRECTIVE_CONFLICTING_ALIAS = 312,
|
|
53
|
+
MULTIPLE_MATCHING_PIPES = 313,
|
|
43
54
|
MULTIPLE_PLATFORMS = 400,
|
|
44
55
|
PLATFORM_NOT_FOUND = 401,
|
|
45
|
-
|
|
56
|
+
MISSING_REQUIRED_INJECTABLE_IN_BOOTSTRAP = 402,
|
|
46
57
|
BOOTSTRAP_COMPONENTS_NOT_FOUND = -403,
|
|
47
58
|
PLATFORM_ALREADY_DESTROYED = 404,
|
|
48
59
|
ASYNC_INITIALIZERS_STILL_RUNNING = 405,
|
|
49
60
|
APPLICATION_REF_ALREADY_DESTROYED = 406,
|
|
50
61
|
RENDERER_NOT_FOUND = 407,
|
|
62
|
+
HYDRATION_NODE_MISMATCH = -500,
|
|
63
|
+
HYDRATION_MISSING_SIBLINGS = -501,
|
|
64
|
+
HYDRATION_MISSING_NODE = -502,
|
|
65
|
+
UNSUPPORTED_PROJECTION_DOM_NODES = -503,
|
|
66
|
+
INVALID_SKIP_HYDRATION_HOST = -504,
|
|
67
|
+
MISSING_HYDRATION_ANNOTATIONS = -505,
|
|
68
|
+
HYDRATION_STABLE_TIMEDOUT = -506,
|
|
69
|
+
MISSING_SSR_CONTENT_INTEGRITY_MARKER = -507,
|
|
70
|
+
SIGNAL_WRITE_FROM_ILLEGAL_CONTEXT = 600,
|
|
71
|
+
REQUIRE_SYNC_WITHOUT_SYNC_EMIT = 601,
|
|
51
72
|
INVALID_I18N_STRUCTURE = 700,
|
|
52
73
|
MISSING_LOCALE_DATA = 701,
|
|
53
74
|
IMPORT_PROVIDERS_FROM_STANDALONE = 800,
|
|
@@ -61,7 +82,10 @@ export declare const enum RuntimeErrorCode {
|
|
|
61
82
|
TYPE_IS_NOT_STANDALONE = 907,
|
|
62
83
|
MISSING_ZONEJS = 908,
|
|
63
84
|
UNEXPECTED_ZONE_STATE = 909,
|
|
64
|
-
UNSAFE_IFRAME_ATTRS = -910
|
|
85
|
+
UNSAFE_IFRAME_ATTRS = -910,
|
|
86
|
+
VIEW_ALREADY_DESTROYED = 911,
|
|
87
|
+
COMPONENT_ID_COLLISION = -912,
|
|
88
|
+
RUNTIME_DEPS_INVALID_IMPORTED_TYPE = 1000
|
|
65
89
|
}
|
|
66
90
|
/**
|
|
67
91
|
* Class that represents a runtime error.
|
|
@@ -76,7 +100,8 @@ export declare const enum RuntimeErrorCode {
|
|
|
76
100
|
*
|
|
77
101
|
* Note: the `message` argument contains a descriptive error message as a string in development
|
|
78
102
|
* mode (when the `ngDevMode` is defined). In production mode (after tree-shaking pass), the
|
|
79
|
-
* `message` argument becomes `false`, thus we account for it in the typings and the runtime
|
|
103
|
+
* `message` argument becomes `false`, thus we account for it in the typings and the runtime
|
|
104
|
+
* logic.
|
|
80
105
|
*/
|
|
81
106
|
export declare class RuntimeError<T extends number = RuntimeErrorCode> extends Error {
|
|
82
107
|
code: T;
|
|
@@ -6,3 +6,12 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
export declare const NG_FACTORY_DEF: string;
|
|
9
|
+
/**
|
|
10
|
+
* The `NG_ENV_ID` field on a DI token indicates special processing in the `EnvironmentInjector`:
|
|
11
|
+
* getting such tokens from the `EnvironmentInjector` will bypass the standard DI resolution
|
|
12
|
+
* strategy and instead will return implementation produced by the `NG_ENV_ID` factory function.
|
|
13
|
+
*
|
|
14
|
+
* This particular retrieval of DI tokens is mostly done to eliminate circular dependencies and
|
|
15
|
+
* improve tree-shaking.
|
|
16
|
+
*/
|
|
17
|
+
export declare const NG_ENV_ID: string;
|
|
@@ -23,6 +23,7 @@ export interface TypeDecorator {
|
|
|
23
23
|
*/
|
|
24
24
|
<T extends Type<any>>(type: T): T;
|
|
25
25
|
(target: Object, propertyKey?: string | symbol, parameterIndex?: number): void;
|
|
26
|
+
(target: unknown, context: unknown): void;
|
|
26
27
|
}
|
|
27
28
|
export declare const PARAMETERS = "__parameters__";
|
|
28
29
|
export declare function makeParamDecorator(name: string, props?: (...args: any[]) => any, parentClass?: any): any;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "static-injector",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Angular的静态注入器独立使用版本",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
7
7
|
"injector",
|
|
8
8
|
"typescript",
|
|
9
|
-
"typescript
|
|
9
|
+
"typescript 5.1.6",
|
|
10
10
|
"injectable",
|
|
11
11
|
"static-inject"
|
|
12
12
|
],
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
},
|
|
20
20
|
"homepage": "https://github.com/wszgrcy/static-injector#readme",
|
|
21
21
|
"main": "import/commonjs/index.js",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"module": "import/
|
|
22
|
+
"es2022": "import/fesm2022/index.js",
|
|
23
|
+
"fesm2022": "import/fesm2022/index.js",
|
|
24
|
+
"esm2022": "import/esm2022/index.js",
|
|
25
|
+
"module": "import/fesm2022/index.js",
|
|
26
26
|
"typings": "import/typings/index.d.ts",
|
|
27
27
|
"private": false,
|
|
28
28
|
"scripts": {},
|
|
29
29
|
"author": "wszgrcy",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"typescript": "
|
|
32
|
+
"typescript": ">=5.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {},
|
|
35
35
|
"sideEffects": false
|
package/readme.md
CHANGED
|
@@ -11,7 +11,6 @@ import { MaybeForwardRefExpression, R3CompiledExpression, R3Reference } from './
|
|
|
11
11
|
export interface R3InjectableMetadata {
|
|
12
12
|
name: string;
|
|
13
13
|
type: R3Reference;
|
|
14
|
-
internalType: o.Expression;
|
|
15
14
|
typeArgumentCount: number;
|
|
16
15
|
providedIn: MaybeForwardRefExpression;
|
|
17
16
|
useClass?: MaybeForwardRefExpression;
|
|
@@ -41,7 +41,6 @@ function compileInjectable(meta, resolveForwardRefs) {
|
|
|
41
41
|
const factoryMeta = {
|
|
42
42
|
name: meta.name,
|
|
43
43
|
type: meta.type,
|
|
44
|
-
internalType: meta.internalType,
|
|
45
44
|
typeArgumentCount: meta.typeArgumentCount,
|
|
46
45
|
deps: [],
|
|
47
46
|
target: r3_factory_1.FactoryTarget.Injectable,
|
|
@@ -53,14 +52,19 @@ function compileInjectable(meta, resolveForwardRefs) {
|
|
|
53
52
|
//
|
|
54
53
|
// A special case exists for useClass: Type where Type is the injectable type itself and no
|
|
55
54
|
// deps are specified, in which case 'useClass' is effectively ignored.
|
|
56
|
-
const useClassOnSelf = meta.useClass.expression.isEquivalent(meta.
|
|
55
|
+
const useClassOnSelf = meta.useClass.expression.isEquivalent(meta.type.value);
|
|
57
56
|
let deps = undefined;
|
|
58
57
|
if (meta.deps !== undefined) {
|
|
59
58
|
deps = meta.deps;
|
|
60
59
|
}
|
|
61
60
|
if (deps !== undefined) {
|
|
62
61
|
// factory: () => new meta.useClass(...deps)
|
|
63
|
-
result = (0, r3_factory_1.compileFactoryFunction)(
|
|
62
|
+
result = (0, r3_factory_1.compileFactoryFunction)({
|
|
63
|
+
...factoryMeta,
|
|
64
|
+
delegate: meta.useClass.expression,
|
|
65
|
+
delegateDeps: deps,
|
|
66
|
+
delegateType: r3_factory_1.R3FactoryDelegateType.Class,
|
|
67
|
+
});
|
|
64
68
|
}
|
|
65
69
|
else if (useClassOnSelf) {
|
|
66
70
|
result = (0, r3_factory_1.compileFactoryFunction)(factoryMeta);
|
|
@@ -74,7 +78,12 @@ function compileInjectable(meta, resolveForwardRefs) {
|
|
|
74
78
|
}
|
|
75
79
|
else if (meta.useFactory !== undefined) {
|
|
76
80
|
if (meta.deps !== undefined) {
|
|
77
|
-
result = (0, r3_factory_1.compileFactoryFunction)(
|
|
81
|
+
result = (0, r3_factory_1.compileFactoryFunction)({
|
|
82
|
+
...factoryMeta,
|
|
83
|
+
delegate: meta.useFactory,
|
|
84
|
+
delegateDeps: meta.deps || [],
|
|
85
|
+
delegateType: r3_factory_1.R3FactoryDelegateType.Function,
|
|
86
|
+
});
|
|
78
87
|
}
|
|
79
88
|
else {
|
|
80
89
|
result = {
|
|
@@ -87,21 +96,27 @@ function compileInjectable(meta, resolveForwardRefs) {
|
|
|
87
96
|
// Note: it's safe to use `meta.useValue` instead of the `USE_VALUE in meta` check used for
|
|
88
97
|
// client code because meta.useValue is an Expression which will be defined even if the actual
|
|
89
98
|
// value is undefined.
|
|
90
|
-
result = (0, r3_factory_1.compileFactoryFunction)(
|
|
99
|
+
result = (0, r3_factory_1.compileFactoryFunction)({
|
|
100
|
+
...factoryMeta,
|
|
101
|
+
expression: meta.useValue.expression,
|
|
102
|
+
});
|
|
91
103
|
}
|
|
92
104
|
else if (meta.useExisting !== undefined) {
|
|
93
105
|
// useExisting is an `inject` call on the existing token.
|
|
94
|
-
result = (0, r3_factory_1.compileFactoryFunction)(
|
|
106
|
+
result = (0, r3_factory_1.compileFactoryFunction)({
|
|
107
|
+
...factoryMeta,
|
|
108
|
+
expression: o
|
|
95
109
|
.importExpr(r3_identifiers_1.Identifiers.inject)
|
|
96
|
-
.callFn([meta.useExisting.expression])
|
|
110
|
+
.callFn([meta.useExisting.expression]),
|
|
111
|
+
});
|
|
97
112
|
}
|
|
98
113
|
else {
|
|
99
114
|
result = {
|
|
100
115
|
statements: [],
|
|
101
|
-
expression: delegateToFactory(meta.type.value, meta.
|
|
116
|
+
expression: delegateToFactory(meta.type.value, meta.type.value, resolveForwardRefs),
|
|
102
117
|
};
|
|
103
118
|
}
|
|
104
|
-
const token = meta.
|
|
119
|
+
const token = meta.type.value;
|
|
105
120
|
const injectableProps = new util_2.DefinitionMap();
|
|
106
121
|
injectableProps.set('token', token);
|
|
107
122
|
injectableProps.set('factory', result.expression);
|
|
@@ -125,30 +140,30 @@ function createInjectableType(meta) {
|
|
|
125
140
|
]));
|
|
126
141
|
}
|
|
127
142
|
exports.createInjectableType = createInjectableType;
|
|
128
|
-
function delegateToFactory(type,
|
|
129
|
-
if (type.node ===
|
|
143
|
+
function delegateToFactory(type, useType, unwrapForwardRefs) {
|
|
144
|
+
if (type.node === useType.node) {
|
|
130
145
|
// The types are the same, so we can simply delegate directly to the type's factory.
|
|
131
146
|
// ```
|
|
132
147
|
// factory: type.ɵfac
|
|
133
148
|
// ```
|
|
134
|
-
return
|
|
149
|
+
return useType.prop('ɵfac');
|
|
135
150
|
}
|
|
136
151
|
if (!unwrapForwardRefs) {
|
|
137
152
|
// The type is not wrapped in a `forwardRef()`, so we create a simple factory function that
|
|
138
153
|
// accepts a sub-type as an argument.
|
|
139
154
|
// ```
|
|
140
|
-
// factory: function(t) { return
|
|
155
|
+
// factory: function(t) { return useType.ɵfac(t); }
|
|
141
156
|
// ```
|
|
142
|
-
return createFactoryFunction(
|
|
157
|
+
return createFactoryFunction(useType);
|
|
143
158
|
}
|
|
144
|
-
// The
|
|
159
|
+
// The useType is actually wrapped in a `forwardRef()` so we need to resolve that before
|
|
145
160
|
// calling its factory.
|
|
146
161
|
// ```
|
|
147
162
|
// factory: function(t) { return core.resolveForwardRef(type).ɵfac(t); }
|
|
148
163
|
// ```
|
|
149
164
|
const unwrappedType = o
|
|
150
165
|
.importExpr(r3_identifiers_1.Identifiers.resolveForwardRef)
|
|
151
|
-
.callFn([
|
|
166
|
+
.callFn([useType]);
|
|
152
167
|
return createFactoryFunction(unwrappedType);
|
|
153
168
|
}
|
|
154
169
|
function createFactoryFunction(type) {
|