static-injector 1.0.10 → 2.1.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 (111) hide show
  1. package/import/commonjs/index.js +337 -124
  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/di/injection_token.js +6 -0
  6. package/import/es2015/di/injector.js +6 -8
  7. package/import/es2015/di/injector_compatibility.js +90 -34
  8. package/import/es2015/di/injector_token.js +1 -1
  9. package/import/es2015/di/interface/defs.js +39 -0
  10. package/import/es2015/di/interface/injector.js +1 -0
  11. package/import/es2015/di/internal_tokens.js +9 -0
  12. package/import/es2015/di/metadata.js +4 -4
  13. package/import/es2015/di/provider_collection.js +49 -0
  14. package/import/es2015/di/r3_injector.js +102 -72
  15. package/import/es2015/di/scope.js +2 -2
  16. package/import/es2015/index.js +1 -1
  17. package/import/es2015/render3/errors_di.js +1 -1
  18. package/import/fesm2015/index.js +328 -114
  19. package/import/typings/di/create_injector.d.ts +23 -0
  20. package/import/typings/di/initializer_token.d.ts +15 -0
  21. package/import/typings/di/inject_switch.d.ts +7 -2
  22. package/import/typings/{decorator → di}/injectable.d.ts +2 -2
  23. package/import/typings/di/injection_token.d.ts +4 -0
  24. package/import/typings/di/injector.d.ts +20 -7
  25. package/import/typings/di/injector_compatibility.d.ts +42 -21
  26. package/import/typings/di/interface/defs.d.ts +10 -0
  27. package/import/typings/di/interface/injector.d.ts +26 -0
  28. package/import/typings/di/interface/provider.d.ts +3 -8
  29. package/import/typings/di/internal_tokens.d.ts +10 -0
  30. package/import/typings/di/provider_collection.d.ts +30 -0
  31. package/import/typings/di/provider_token.d.ts +1 -1
  32. package/import/typings/di/r3_injector.d.ts +68 -37
  33. package/import/typings/di/scope.d.ts +3 -2
  34. package/import/typings/index.d.ts +1 -1
  35. package/import/typings/render3/definition_factory.d.ts +1 -1
  36. package/package.json +5 -3
  37. package/{import/es2015/decorator/interface/provider.js → transform/compiler/compiler.d.ts} +1 -1
  38. package/transform/compiler/compiler.js +28 -0
  39. package/transform/compiler/index.d.ts +8 -5
  40. package/transform/compiler/index.js +17 -6
  41. package/transform/compiler/public_api.d.ts +13 -0
  42. package/transform/compiler/public_api.js +30 -0
  43. package/transform/compiler/src/compiler.d.ts +27 -0
  44. package/transform/compiler/src/compiler.js +47 -0
  45. package/transform/compiler/src/injectable_compiler_2.d.ts +7 -36
  46. package/transform/compiler/src/injectable_compiler_2.js +20 -23
  47. package/transform/compiler/src/output/output_ast.d.ts +30 -109
  48. package/transform/compiler/src/output/output_ast.js +66 -188
  49. package/transform/compiler/src/render3/partial/api.d.ts +1 -1
  50. package/transform/compiler/src/render3/partial/api.js +7 -0
  51. package/transform/compiler/src/render3/r3_factory.d.ts +8 -15
  52. package/transform/compiler/src/render3/r3_factory.js +46 -61
  53. package/transform/compiler/src/render3/util.d.ts +64 -0
  54. package/transform/compiler/src/render3/util.js +52 -9
  55. package/transform/compiler/src/render3/view/util.d.ts +0 -8
  56. package/transform/compiler/src/render3/view/util.js +5 -9
  57. package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +10 -0
  58. package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +26 -0
  59. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +37 -0
  60. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +197 -0
  61. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.d.ts +3 -3
  62. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.js +3 -3
  63. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.d.ts +4 -34
  64. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +181 -0
  65. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +3 -4
  66. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +46 -53
  67. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +6 -2
  68. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +9 -2
  69. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +12 -1
  70. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +7 -0
  71. package/transform/compiler-cli/src/ngtsc/imports/index.js +12 -1
  72. package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +19 -0
  73. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +28 -0
  74. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +10 -3
  75. package/transform/compiler-cli/src/ngtsc/reflection/index.js +12 -1
  76. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +13 -14
  77. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +8 -25
  78. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -2
  79. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +44 -55
  80. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +1 -1
  81. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +55 -69
  82. package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +2 -2
  83. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +7 -23
  84. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +9 -2
  85. package/transform/compiler-cli/src/ngtsc/transform/index.js +12 -1
  86. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +4 -4
  87. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +2 -2
  88. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +16 -31
  89. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +12 -5
  90. package/transform/compiler-cli/src/ngtsc/translator/index.js +12 -1
  91. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +5 -5
  92. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +4 -4
  93. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +5 -21
  94. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +2 -6
  95. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +6 -18
  96. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +3 -6
  97. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +83 -90
  98. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +4 -4
  99. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +8 -0
  100. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +24 -0
  101. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +45 -0
  102. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +86 -0
  103. package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +1 -8
  104. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +4 -27
  105. package/transform/index.js +5 -1
  106. package/transform/injectable-transform.js +59 -38
  107. package/import/typings/decorator/interface/provider.d.ts +0 -312
  108. package/transform/compiler/src/render3/partial/util.d.ts +0 -16
  109. package/transform/compiler/src/render3/partial/util.js +0 -44
  110. package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +0 -370
  111. /package/import/es2015/{decorator → di}/injectable.js +0 -0
@@ -0,0 +1,23 @@
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 { Injector } from './injector';
9
+ import { StaticProvider } from './interface/provider';
10
+ import { R3Injector } from './r3_injector';
11
+ import { InjectorScope } from './scope';
12
+ /**
13
+ * Create a new `Injector` which is configured using a `defType` of `InjectorType<any>`s.
14
+ *
15
+ * @publicApi
16
+ */
17
+ export declare function createInjector(defType: any, parent?: Injector | null, additionalProviders?: StaticProvider[] | null, name?: string): Injector;
18
+ /**
19
+ * Creates a new injector without eagerly resolving its injector types. Can be used in places
20
+ * where resolving the injector types immediately can lead to an infinite loop. The injector types
21
+ * should be resolved at a later point by calling `_resolveInjectorDefTypes`.
22
+ */
23
+ export declare function createInjectorWithoutInjectorInstances(defType: any, parent?: Injector | null, additionalProviders?: StaticProvider[] | null, name?: string, scopes?: Set<InjectorScope>): R3Injector;
@@ -0,0 +1,15 @@
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 { InjectionToken } from './injection_token';
9
+ /**
10
+ * A multi-provider token for initialization functions that will run upon construction of an
11
+ * environment injector.
12
+ *
13
+ * @publicApi
14
+ */
15
+ export declare const ENVIRONMENT_INITIALIZER: InjectionToken<() => void>;
@@ -5,8 +5,13 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { InjectFlags } from "./interface/injector";
9
- import { ProviderToken } from "./provider_token";
8
+ import { InjectFlags } from './interface/injector';
9
+ import { ProviderToken } from './provider_token';
10
+ export declare function getInjectImplementation(): <T>(token: ProviderToken<T>, flags?: InjectFlags) => T;
11
+ /**
12
+ * Sets the current inject implementation.
13
+ */
14
+ export declare function setInjectImplementation(impl: (<T>(token: ProviderToken<T>, flags?: InjectFlags) => T | null) | undefined): (<T>(token: ProviderToken<T>, flags?: InjectFlags) => T | null) | undefined;
10
15
  /**
11
16
  * Injects `root` tokens in limp mode.
12
17
  *
@@ -5,15 +5,15 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
+ import { ValueSansProvider, ExistingSansProvider, StaticClassSansProvider, ConstructorSansProvider, FactorySansProvider, ClassSansProvider } from './interface/provider';
8
9
  import { Type } from '../interface/type';
9
10
  import { TypeDecorator } from '../util/decorators';
10
- import { ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, FactorySansProvider, StaticClassSansProvider, ValueSansProvider } from './interface/provider';
11
11
  /**
12
12
  * Injectable providers used in `@Injectable` decorator.
13
13
  *
14
14
  * @publicApi
15
15
  */
16
- export declare type InjectableProvider = ValueSansProvider | ExistingSansProvider | StaticClassSansProvider | ConstructorSansProvider | FactorySansProvider | ClassSansProvider;
16
+ export type InjectableProvider = ValueSansProvider | ExistingSansProvider | StaticClassSansProvider | ConstructorSansProvider | FactorySansProvider | ClassSansProvider;
17
17
  /**
18
18
  * Type of the Injectable decorator / constructor function.
19
19
  *
@@ -53,5 +53,9 @@ export declare class InjectionToken<T> {
53
53
  providedIn?: Type<any> | 'root' | 'platform' | 'any' | null;
54
54
  factory: () => T;
55
55
  });
56
+ /**
57
+ * @internal
58
+ */
59
+ get multi(): InjectionToken<Array<T>>;
56
60
  toString(): string;
57
61
  }
@@ -6,11 +6,9 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import { InjectorMarkers } from './injector_marker';
9
- import { InjectFlags } from './interface/injector';
9
+ import { InjectFlags, InjectOptions } from './interface/injector';
10
10
  import { StaticProvider } from './interface/provider';
11
11
  import { ProviderToken } from './provider_token';
12
- export declare function INJECTOR_IMPL__POST_R3__(providers: StaticProvider[], parent: Injector | undefined, name: string): Injector;
13
- export declare const INJECTOR_IMPL: typeof INJECTOR_IMPL__POST_R3__;
14
12
  /**
15
13
  * Concrete injectors implement this interface. Injectors are configured
16
14
  * with [providers](guide/glossary#provider) that associate
@@ -38,17 +36,32 @@ export declare const INJECTOR_IMPL: typeof INJECTOR_IMPL__POST_R3__;
38
36
  export declare abstract class Injector {
39
37
  static THROW_IF_NOT_FOUND: {};
40
38
  static NULL: Injector;
39
+ /**
40
+ * Internal note on the `options?: InjectOptions|InjectFlags` override of the `get`
41
+ * method: consider dropping the `InjectFlags` part in one of the major versions.
42
+ * It can **not** be done in minor/patch, since it's breaking for custom injectors
43
+ * that only implement the old `InjectorFlags` interface.
44
+ */
45
+ /**
46
+ * Retrieves an instance from the injector based on the provided token.
47
+ * @returns The instance from the injector if defined, otherwise the `notFoundValue`.
48
+ * @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
49
+ */
50
+ abstract get<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions & {
51
+ optional?: false;
52
+ }): T;
41
53
  /**
42
54
  * Retrieves an instance from the injector based on the provided token.
43
55
  * @returns The instance from the injector if defined, otherwise the `notFoundValue`.
44
56
  * @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
45
57
  */
46
- abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
58
+ abstract get<T>(token: ProviderToken<T>, notFoundValue: null | undefined, options: InjectOptions): T | null;
47
59
  /**
48
- * @deprecated from v4.0.0 use ProviderToken<T>
49
- * @suppress {duplicate}
60
+ * Retrieves an instance from the injector based on the provided token.
61
+ * @returns The instance from the injector if defined, otherwise the `notFoundValue`.
62
+ * @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
50
63
  */
51
- abstract get(token: any, notFoundValue?: any): any;
64
+ abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, options?: InjectOptions | InjectFlags): T;
52
65
  /**
53
66
  * Creates a new injector instance that provides one or more dependencies,
54
67
  * according to a given type or types of `StaticProvider`.
@@ -5,9 +5,9 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { Injector } from "./injector";
9
- import { DecoratorFlags, InjectFlags, InternalInjectFlags } from "./interface/injector";
10
- import { ProviderToken } from "./provider_token";
8
+ import { Injector } from './injector';
9
+ import { DecoratorFlags, InjectFlags, InjectOptions, InternalInjectFlags } from './interface/injector';
10
+ 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";
@@ -31,30 +31,51 @@ export declare function injectInjectorOnly<T>(token: ProviderToken<T>, flags?: I
31
31
  export declare function ɵɵinject<T>(token: ProviderToken<T>): T;
32
32
  export declare function ɵɵinject<T>(token: ProviderToken<T>, flags?: InjectFlags): T | null;
33
33
  /**
34
- * Injects a token from the currently active injector.
34
+ * @param token A token that represents a dependency that should be injected.
35
+ * @returns the injected value if operation is successful, `null` otherwise.
36
+ * @throws if called outside of a supported context.
35
37
  *
36
- * Must be used in the context of a factory function such as one defined for an
37
- * `InjectionToken`. Throws an error if not called from such a context.
38
- *
39
- * Within such a factory function, using this function to request injection of a dependency
40
- * is faster and more type-safe than providing an additional array of dependencies
41
- * (as has been common with `useFactory` providers).
42
- *
43
- * @param token The injection token for the dependency to be injected.
44
- * @param flags Optional flags that control how injection is executed.
45
- * The flags correspond to injection strategies that can be specified with
46
- * parameter decorators `@Host`, `@Self`, `@SkipSef`, and `@Optional`.
47
- * @returns the injected value if injection is successful, `null` otherwise.
48
- *
49
- * @usageNotes
38
+ * @publicApi
39
+ */
40
+ export declare function inject<T>(token: ProviderToken<T>): T;
41
+ /**
42
+ * @param token A token that represents a dependency that should be injected.
43
+ * @param flags Control how injection is executed. The flags correspond to injection strategies that
44
+ * can be specified with parameter decorators `@Host`, `@Self`, `@SkipSelf`, and `@Optional`.
45
+ * @returns the injected value if operation is successful, `null` otherwise.
46
+ * @throws if called outside of a supported context.
50
47
  *
51
- * ### Example
48
+ * @publicApi
49
+ * @deprecated prefer an options object instead of `InjectFlags`
50
+ */
51
+ export declare function inject<T>(token: ProviderToken<T>, flags?: InjectFlags): T | null;
52
+ /**
53
+ * @param token A token that represents a dependency that should be injected.
54
+ * @param options Control how injection is executed. Options correspond to injection strategies
55
+ * that can be specified with parameter decorators `@Host`, `@Self`, `@SkipSelf`, and
56
+ * `@Optional`.
57
+ * @returns the injected value if operation is successful.
58
+ * @throws if called outside of a supported context, or if the token is not found.
52
59
  *
53
- * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
60
+ * @publicApi
61
+ */
62
+ export declare function inject<T>(token: ProviderToken<T>, options: InjectOptions & {
63
+ optional?: false;
64
+ }): T;
65
+ /**
66
+ * @param token A token that represents a dependency that should be injected.
67
+ * @param options Control how injection is executed. Options correspond to injection strategies
68
+ * that can be specified with parameter decorators `@Host`, `@Self`, `@SkipSelf`, and
69
+ * `@Optional`.
70
+ * @returns the injected value if operation is successful, `null` if the token is not
71
+ * found and optional injection has been requested.
72
+ * @throws if called outside of a supported context, or if the token is not found and optional
73
+ * injection was not requested.
54
74
  *
55
75
  * @publicApi
56
76
  */
57
- export declare const inject: typeof ɵɵinject;
77
+ export declare function inject<T>(token: ProviderToken<T>, options: InjectOptions): T | null;
78
+ export declare function convertToBitFlags(flags: InjectOptions | InjectFlags | undefined): InjectFlags | undefined;
58
79
  export declare function injectArgs(types: (ProviderToken<any> | any[])[]): any[];
59
80
  /**
60
81
  * Attaches a given InjectFlag to a given decorator using monkey-patching.
@@ -153,3 +153,13 @@ export declare function ɵɵdefineInjector(options: {
153
153
  */
154
154
  export declare function getInjectableDef<T>(type: any): ɵɵInjectableDeclaration<T> | null;
155
155
  export declare const NG_PROV_DEF: string;
156
+ /**
157
+ * Read the injectable def (`ɵprov`) for `type` or read the `ɵprov` from one of its ancestors.
158
+ *
159
+ * @param type A type which may have `ɵprov`, via inheritance.
160
+ *
161
+ * @deprecated Will be removed in a future version of Angular, where an error will occur in the
162
+ * scenario if we find the `ɵprov` on an ancestor only.
163
+ */
164
+ export declare function getInheritedInjectableDef<T>(type: any): ɵɵInjectableDeclaration<T> | null;
165
+ export declare const NG_INJECTABLE_DEF: string;
@@ -17,6 +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
21
  */
21
22
  export declare enum InjectFlags {
22
23
  /** Check self and check parent injector if needed */
@@ -46,3 +47,28 @@ export declare const enum InternalInjectFlags {
46
47
  /** Inject `defaultValue` instead if token not found. */
47
48
  Optional = 8
48
49
  }
50
+ /**
51
+ * Type of the options argument to `inject`.
52
+ *
53
+ * @publicApi
54
+ */
55
+ export interface InjectOptions {
56
+ /**
57
+ * Use optional injection, and return `null` if the requested token is not found.
58
+ */
59
+ optional?: boolean;
60
+ /**
61
+ * Start injection at the parent of the current injector.
62
+ */
63
+ skipSelf?: boolean;
64
+ /**
65
+ * Only query the current injector for the token, and don't fall back to the parent injector if
66
+ * it's not found.
67
+ */
68
+ self?: boolean;
69
+ /**
70
+ * Stop injection at the host component's injector. Only relevant when injecting from an element
71
+ * injector, and a no-op for environment injectors.
72
+ */
73
+ host?: boolean;
74
+ }
@@ -5,7 +5,7 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { Type } from "../../interface/type";
8
+ import { Type } from '../../interface/type';
9
9
  /**
10
10
  * Configures the `Injector` to return a value for a token.
11
11
  * Base for `ValueProvider` decorator.
@@ -236,7 +236,7 @@ export interface FactoryProvider extends FactorySansProvider {
236
236
  *
237
237
  * @publicApi
238
238
  */
239
- export declare type StaticProvider = ValueProvider | ExistingProvider | StaticClassProvider | ConstructorProvider | FactoryProvider | any[];
239
+ export type StaticProvider = ValueProvider | ExistingProvider | StaticClassProvider | ConstructorProvider | FactoryProvider | any[];
240
240
  /**
241
241
  * Configures the `Injector` to return an instance of `Type` when `Type' is used as the token.
242
242
  *
@@ -304,9 +304,4 @@ export interface ClassProvider extends ClassSansProvider {
304
304
  *
305
305
  * @publicApi
306
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[];
307
+ export type Provider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | any[];
@@ -0,0 +1,10 @@
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
+ import { InjectionToken } from './injection_token';
10
+ export declare const INJECTOR_DEF_TYPES: InjectionToken<Type<unknown>>;
@@ -0,0 +1,30 @@
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
+ import { InjectorTypeWithProviders } from './interface/defs';
10
+ import { ClassProvider, ConstructorProvider, ExistingProvider, FactoryProvider, StaticClassProvider, TypeProvider, ValueProvider } from './interface/provider';
11
+ /**
12
+ * Internal type for a single provider in a deep provider array.
13
+ */
14
+ export type SingleProvider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | StaticClassProvider;
15
+ /**
16
+ * The logic visits an `InjectorType`, an `InjectorTypeWithProviders`, or a standalone
17
+ * `ComponentType`, and all of its transitive providers and collects providers.
18
+ *
19
+ * If an `InjectorTypeWithProviders` that declares providers besides the type is specified,
20
+ * the function will return "true" to indicate that the providers of the type definition need
21
+ * to be processed. This allows us to process providers of injector types after all imports of
22
+ * an injector definition are processed. (following View Engine semantics: see FW-1349)
23
+ */
24
+ export declare function walkProviderTree(container: Type<unknown> | InjectorTypeWithProviders<unknown>, providersOut: SingleProvider[], parents: Type<unknown>[], dedup: Set<Type<unknown>>): container is InjectorTypeWithProviders<unknown>;
25
+ export declare const USE_VALUE: string;
26
+ export declare function isValueProvider(value: SingleProvider): value is ValueProvider;
27
+ export declare function isExistingProvider(value: SingleProvider): value is ExistingProvider;
28
+ export declare function isFactoryProvider(value: SingleProvider): value is FactoryProvider;
29
+ export declare function isTypeProvider(value: SingleProvider): value is TypeProvider;
30
+ export declare function isClassProvider(value: SingleProvider): value is ClassProvider;
@@ -14,4 +14,4 @@ import { InjectionToken } from "./injection_token";
14
14
  *
15
15
  * @publicApi
16
16
  */
17
- export declare type ProviderToken<T> = Type<T> | AbstractType<T> | InjectionToken<T>;
17
+ export type ProviderToken<T> = Type<T> | AbstractType<T> | InjectionToken<T>;
@@ -7,53 +7,91 @@
7
7
  */
8
8
  import { Injector } from './injector';
9
9
  import { InjectorType } from './interface/defs';
10
- import { InjectFlags } from './interface/injector';
11
- import { ClassProvider, ConstructorProvider, ExistingProvider, FactoryProvider, StaticClassProvider, StaticProvider, TypeProvider, ValueProvider } from './interface/provider';
10
+ import { InjectFlags, InjectOptions } from './interface/injector';
11
+ import { ClassProvider, ConstructorProvider, ExistingProvider, FactoryProvider, Provider, StaticClassProvider, TypeProvider, ValueProvider } from './interface/provider';
12
12
  import { ProviderToken } from './provider_token';
13
+ import { InjectorScope } from './scope';
13
14
  /**
14
15
  * Internal type for a single provider in a deep provider array.
15
16
  */
16
- declare type SingleProvider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | StaticClassProvider;
17
+ type SingleProvider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | StaticClassProvider;
18
+ export declare function getNullInjector(): Injector;
17
19
  /**
18
- * Create a new `Injector` which is configured using a `defType` of `InjectorType<any>`s.
19
- *
20
- * @publicApi
21
- */
22
- export declare function createInjector(defType: any, parent?: Injector | null, additionalProviders?: StaticProvider[] | null, name?: string): Injector;
23
- /**
24
- * Creates a new injector without eagerly resolving its injector types. Can be used in places
25
- * where resolving the injector types immediately can lead to an infinite loop. The injector types
26
- * should be resolved at a later point by calling `_resolveInjectorDefTypes`.
20
+ * An `Injector` that's part of the environment injector hierarchy, which exists outside of the
21
+ * component tree.
27
22
  */
28
- export declare function createInjectorWithoutInjectorInstances(defType: any, parent?: Injector | null, additionalProviders?: StaticProvider[] | null, name?: string): R3Injector;
29
- export declare class R3Injector {
23
+ export declare abstract class EnvironmentInjector implements Injector {
24
+ /**
25
+ * Retrieves an instance from the injector based on the provided token.
26
+ * @returns The instance from the injector if defined, otherwise the `notFoundValue`.
27
+ * @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
28
+ */
29
+ abstract get<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions & {
30
+ optional?: false;
31
+ }): T;
32
+ /**
33
+ * Retrieves an instance from the injector based on the provided token.
34
+ * @returns The instance from the injector if defined, otherwise the `notFoundValue`.
35
+ * @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
36
+ */
37
+ abstract get<T>(token: ProviderToken<T>, notFoundValue: null | undefined, options: InjectOptions): T | null;
38
+ /**
39
+ * Retrieves an instance from the injector based on the provided token.
40
+ * @returns The instance from the injector if defined, otherwise the `notFoundValue`.
41
+ * @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
42
+ */
43
+ abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, options?: InjectOptions): T;
44
+ /**
45
+ * Retrieves an instance from the injector based on the provided token.
46
+ * @returns The instance from the injector if defined, otherwise the `notFoundValue`.
47
+ * @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
48
+ * @deprecated use object-based flags (`InjectOptions`) instead.
49
+ */
50
+ abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
51
+ /**
52
+ * @deprecated from v4.0.0 use ProviderToken<T>
53
+ * @suppress {duplicate}
54
+ */
55
+ abstract get(token: any, notFoundValue?: any): any;
56
+ /**
57
+ * Runs the given function in the context of this `EnvironmentInjector`.
58
+ *
59
+ * Within the function's stack frame, `inject` can be used to inject dependencies from this
60
+ * injector. Note that `inject` is only usable synchronously, and cannot be used in any
61
+ * asynchronous callbacks or after any `await` points.
62
+ *
63
+ * @param fn the closure to be run in the context of this injector
64
+ * @returns the return value of the function, if any
65
+ */
66
+ abstract runInContext<ReturnT>(fn: () => ReturnT): ReturnT;
67
+ abstract destroy(): void;
68
+ /**
69
+ * @internal
70
+ */
71
+ abstract onDestroy(callback: () => void): void;
72
+ }
73
+ export declare class R3Injector extends EnvironmentInjector {
30
74
  readonly parent: Injector;
75
+ readonly source: string | null;
76
+ readonly scopes: Set<InjectorScope>;
31
77
  /**
32
78
  * Map of tokens to records which contain the instances of those tokens.
33
79
  * - `null` value implies that we don't have the record. Used by tree-shakable injectors
34
80
  * to prevent further searches.
35
81
  */
36
82
  private records;
37
- /**
38
- * The transitive set of `InjectorType`s which define this injector.
39
- */
40
- private injectorDefTypes;
41
83
  /**
42
84
  * Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
43
85
  */
44
- private onDestroy;
45
- /**
46
- * Flag indicating this injector provides the APP_ROOT_SCOPE token, and thus counts as the
47
- * root scope.
48
- */
49
- private readonly scope;
50
- readonly source: string | null;
86
+ private _ngOnDestroyHooks;
87
+ private _onDestroyHooks;
51
88
  /**
52
89
  * Flag indicating that this injector was previously destroyed.
53
90
  */
54
91
  get destroyed(): boolean;
55
92
  private _destroyed;
56
- constructor(def: InjectorType<any>, additionalProviders: StaticProvider[] | null, parent: Injector, source?: string | null);
93
+ private injectorDefTypes;
94
+ constructor(providers: Array<Provider>, parent: Injector, source: string | null, scopes: Set<InjectorScope>);
57
95
  /**
58
96
  * Destroy the injector and release references to every instance or provider associated with it.
59
97
  *
@@ -61,20 +99,13 @@ export declare class R3Injector {
61
99
  * hook was found.
62
100
  */
63
101
  destroy(): void;
64
- get<T>(token: ProviderToken<T>, notFoundValue?: any, flags?: InjectFlags): T;
102
+ onDestroy(callback: () => void): void;
103
+ runInContext<ReturnT>(fn: () => ReturnT): ReturnT;
104
+ get<T>(token: ProviderToken<T>, notFoundValue?: any, flags?: InjectFlags | InjectOptions): T;
65
105
  /** @internal */
66
- _resolveInjectorDefTypes(): void;
106
+ resolveInjectorInitializers(): void;
67
107
  toString(): string;
68
108
  private assertNotDestroyed;
69
- /**
70
- * Add an `InjectorType` or `InjectorTypeWithProviders` and all of its transitive providers
71
- * to this injector.
72
- *
73
- * If an `InjectorTypeWithProviders` that declares providers besides the type is specified,
74
- * the function will return "true" to indicate that the providers of the type definition need
75
- * to be processed. This allows us to process providers of injector types after all imports of
76
- * an injector definition are processed. (following View Engine semantics: see FW-1349)
77
- */
78
109
  /**
79
110
  * Process a `SingleProvider` and add it.
80
111
  */
@@ -5,10 +5,11 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { InjectionToken } from "./injection_token";
8
+ import { InjectionToken } from './injection_token';
9
+ export type InjectorScope = 'root' | 'platform' | 'environment';
9
10
  /**
10
11
  * An internal token whose presence in an injector indicates that the injector should treat itself
11
12
  * as a root scoped injector when processing requests for unknown tokens which may indicate
12
13
  * they are provided in the root scope.
13
14
  */
14
- export declare const INJECTOR_SCOPE: InjectionToken<"root" | "platform">;
15
+ export declare const INJECTOR_SCOPE: InjectionToken<InjectorScope>;
@@ -1,4 +1,4 @@
1
- export * from './decorator/injectable';
1
+ export * from './di/injectable';
2
2
  export * from './di/metadata';
3
3
  export * from './di/r3_injector';
4
4
  export * from './di/interface/defs';
@@ -9,7 +9,7 @@ import { Type } from '../interface/type';
9
9
  /**
10
10
  * Definition of what a factory function should look like.
11
11
  */
12
- export declare type FactoryFn<T> = {
12
+ export type FactoryFn<T> = {
13
13
  /**
14
14
  * Subclasses without an explicit constructor call through to the factory of their base
15
15
  * definition, providing it with their own constructor to instantiate.
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "static-injector",
3
- "version": "1.0.10",
3
+ "version": "2.1.0",
4
4
  "description": "Angular的静态注入器独立使用版本",
5
5
  "keywords": [
6
6
  "angular",
7
7
  "injector",
8
8
  "typescript",
9
- "injectable"
9
+ "typescript 4.9",
10
+ "injectable",
11
+ "static-inject"
10
12
  ],
11
13
  "repository": {
12
14
  "type": "git",
@@ -27,7 +29,7 @@
27
29
  "author": "wszgrcy",
28
30
  "license": "MIT",
29
31
  "peerDependencies": {
30
- "typescript": "^4.0.0"
32
+ "typescript": "^4.9.3"
31
33
  },
32
34
  "devDependencies": {},
33
35
  "sideEffects": false
@@ -5,4 +5,4 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- export {};
8
+ export * from './public_api';
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ // This file is not used to build this module. It is only used during editing
25
+ // by the TypeScript language service and during build for verification. `ngc`
26
+ // replaces this file with production index.ts when it rewrites private symbol
27
+ // names.
28
+ __exportStar(require("./public_api"), exports);
@@ -1,5 +1,8 @@
1
- export * from './src/injectable_compiler_2';
2
- export * from './src/render3/r3_factory';
3
- export * from './src/output/output_ast';
4
- export * from './src/render3/util';
5
- export * from './src/parse_util';
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
+ export * from './compiler';
@@ -1,7 +1,18 @@
1
1
  "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
2
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
10
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
5
16
  }) : (function(o, m, k, k2) {
6
17
  if (k2 === undefined) k2 = k;
7
18
  o[k2] = m[k];
@@ -10,8 +21,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
21
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
22
  };
12
23
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./src/injectable_compiler_2"), exports);
14
- __exportStar(require("./src/render3/r3_factory"), exports);
15
- __exportStar(require("./src/output/output_ast"), exports);
16
- __exportStar(require("./src/render3/util"), exports);
17
- __exportStar(require("./src/parse_util"), exports);
24
+ // This file is not used to build this module. It is only used during editing
25
+ // by the TypeScript language service and during build for verification. `ngc`
26
+ // replaces this file with production index.ts when it rewrites private symbol
27
+ // names.
28
+ __exportStar(require("./compiler"), exports);