static-injector 2.1.0 → 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 (108) hide show
  1. package/import/commonjs/index.js +403 -211
  2. package/import/{es2015 → es2022}/di/create_injector.js +5 -3
  3. package/import/{es2015 → es2022}/di/forward_ref.js +32 -5
  4. package/import/{es2015 → es2022}/di/injection_token.js +20 -11
  5. package/import/{es2015 → es2022}/di/injector.js +15 -16
  6. package/import/{es2015 → es2022}/di/injector_compatibility.js +27 -13
  7. package/import/{es2015 → es2022}/di/injector_token.js +3 -3
  8. package/import/{es2015 → es2022}/di/interface/defs.js +22 -27
  9. package/import/{es2015 → es2022}/di/interface/injector.js +1 -1
  10. package/import/{es2015 → es2022}/di/interface/provider.js +3 -1
  11. package/import/{es2015 → es2022}/di/null_injector.js +3 -3
  12. package/import/es2022/di/provider_collection.js +104 -0
  13. package/import/{es2015 → es2022}/di/r3_injector.js +71 -37
  14. package/import/es2022/error_details_base_url.js +19 -0
  15. package/import/es2022/errors.js +44 -0
  16. package/import/es2022/interface/type.js +21 -0
  17. package/import/{es2015 → es2022}/render3/definition_factory.js +2 -3
  18. package/import/{es2015 → es2022}/render3/error_code.js +1 -0
  19. package/import/{es2015 → es2022}/render3/errors_di.js +2 -3
  20. package/import/es2022/render3/fields.js +22 -0
  21. package/import/{es2015 → es2022}/render3/instructions/di.js +0 -7
  22. package/import/{es2015 → es2022}/render3/util/stringify_utils.js +5 -5
  23. package/import/{es2015 → es2022}/util/array_utils.js +0 -7
  24. package/import/es2022/util/decorators.js +53 -0
  25. package/import/{es2015 → es2022}/util/empty.js +4 -0
  26. package/import/{es2015 → es2022}/util/stringify.js +5 -5
  27. package/import/{fesm2015 → fesm2022}/index.js +399 -209
  28. package/import/typings/di/create_injector.d.ts +3 -5
  29. package/import/typings/di/forward_ref.d.ts +30 -3
  30. package/import/typings/di/inject_switch.d.ts +1 -1
  31. package/import/typings/di/injectable.d.ts +4 -3
  32. package/import/typings/di/injection_token.d.ts +21 -6
  33. package/import/typings/di/injector.d.ts +19 -3
  34. package/import/typings/di/injector_compatibility.d.ts +12 -5
  35. package/import/typings/di/injector_token.d.ts +2 -2
  36. package/import/typings/di/interface/defs.d.ts +17 -9
  37. package/import/typings/di/interface/injector.d.ts +2 -2
  38. package/import/typings/di/interface/provider.d.ts +64 -4
  39. package/import/typings/di/metadata.d.ts +4 -4
  40. package/import/typings/di/null_injector.d.ts +1 -1
  41. package/import/typings/di/provider_collection.d.ts +53 -11
  42. package/import/typings/di/provider_token.d.ts +2 -2
  43. package/import/typings/di/r3_injector.d.ts +11 -14
  44. package/import/typings/di/scope.d.ts +1 -1
  45. package/import/typings/error_details_base_url.d.ts +19 -0
  46. package/import/typings/errors.d.ts +114 -0
  47. package/import/typings/interface/type.d.ts +45 -0
  48. package/import/typings/render3/errors_di.d.ts +7 -0
  49. package/import/typings/render3/fields.d.ts +9 -0
  50. package/import/typings/render3/instructions/di.d.ts +0 -7
  51. package/import/typings/util/array_utils.d.ts +15 -7
  52. package/import/typings/util/decorators.d.ts +3 -1
  53. package/import/typings/util/empty.d.ts +1 -0
  54. package/package.json +7 -7
  55. package/readme.md +4 -1
  56. package/transform/compiler/src/injectable_compiler_2.d.ts +0 -1
  57. package/transform/compiler/src/injectable_compiler_2.js +31 -16
  58. package/transform/compiler/src/output/output_ast.d.ts +53 -10
  59. package/transform/compiler/src/output/output_ast.js +211 -12
  60. package/transform/compiler/src/parse_util.js +10 -0
  61. package/transform/compiler/src/render3/partial/api.js +1 -1
  62. package/transform/compiler/src/render3/r3_factory.d.ts +0 -8
  63. package/transform/compiler/src/render3/r3_factory.js +5 -4
  64. package/transform/compiler/src/render3/r3_identifiers.js +37 -37
  65. package/transform/compiler/src/render3/view/util.js +1 -3
  66. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +2 -4
  67. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +1 -0
  68. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +1 -1
  69. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +5 -9
  70. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +2 -1
  71. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +12 -8
  72. package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +2 -2
  73. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +8 -4
  74. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +1 -1
  75. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +1 -2
  76. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +24 -173
  77. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +2 -51
  78. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +5 -3
  79. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +5 -10
  80. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +5 -23
  81. package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -21
  82. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +1 -2
  83. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +7 -0
  84. package/transform/compiler-cli/src/ngtsc/translator/src/context.js +1 -0
  85. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -2
  86. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +1 -0
  87. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +10 -4
  88. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +2 -1
  89. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +20 -16
  90. package/transform/injectable-transform.d.ts +2 -2
  91. package/transform/injectable-transform.js +32 -6
  92. package/import/es2015/di/provider_collection.js +0 -49
  93. package/import/es2015/interface/type.js +0 -8
  94. package/import/es2015/render3/fields.js +0 -11
  95. package/import/es2015/util/decorators.js +0 -30
  96. /package/import/{es2015 → es2022}/di/initializer_token.js +0 -0
  97. /package/import/{es2015 → es2022}/di/inject_switch.js +0 -0
  98. /package/import/{es2015 → es2022}/di/injectable.js +0 -0
  99. /package/import/{es2015 → es2022}/di/injector_marker.js +0 -0
  100. /package/import/{es2015 → es2022}/di/internal_tokens.js +0 -0
  101. /package/import/{es2015 → es2022}/di/metadata.js +0 -0
  102. /package/import/{es2015 → es2022}/di/provider_token.js +0 -0
  103. /package/import/{es2015 → es2022}/di/scope.js +0 -0
  104. /package/import/{es2015 → es2022}/index.js +0 -0
  105. /package/import/{es2015 → es2022}/interface/lifecycle_hooks.js +0 -0
  106. /package/import/{es2015 → es2022}/render3/di.js +0 -0
  107. /package/import/{es2015 → es2022}/util/closure.js +0 -0
  108. /package/import/{es2015 → es2022}/util/property.js +0 -0
@@ -8,13 +8,10 @@
8
8
  import { Injector } from './injector';
9
9
  import { InjectorType } from './interface/defs';
10
10
  import { InjectFlags, InjectOptions } from './interface/injector';
11
- import { ClassProvider, ConstructorProvider, ExistingProvider, FactoryProvider, Provider, StaticClassProvider, TypeProvider, ValueProvider } from './interface/provider';
11
+ import { EnvironmentProviders, Provider } from './interface/provider';
12
+ import { SingleProvider } from './provider_collection';
12
13
  import { ProviderToken } from './provider_token';
13
14
  import { InjectorScope } from './scope';
14
- /**
15
- * Internal type for a single provider in a deep provider array.
16
- */
17
- type SingleProvider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | StaticClassProvider;
18
15
  export declare function getNullInjector(): Injector;
19
16
  /**
20
17
  * An `Injector` that's part of the environment injector hierarchy, which exists outside of the
@@ -56,19 +53,20 @@ export declare abstract class EnvironmentInjector implements Injector {
56
53
  /**
57
54
  * Runs the given function in the context of this `EnvironmentInjector`.
58
55
  *
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.
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.
62
59
  *
63
60
  * @param fn the closure to be run in the context of this injector
64
61
  * @returns the return value of the function, if any
62
+ * @deprecated use the standalone function `runInInjectionContext` instead
65
63
  */
66
64
  abstract runInContext<ReturnT>(fn: () => ReturnT): ReturnT;
67
65
  abstract destroy(): void;
68
66
  /**
69
67
  * @internal
70
68
  */
71
- abstract onDestroy(callback: () => void): void;
69
+ abstract onDestroy(callback: () => void): () => void;
72
70
  }
73
71
  export declare class R3Injector extends EnvironmentInjector {
74
72
  readonly parent: Injector;
@@ -91,7 +89,7 @@ export declare class R3Injector extends EnvironmentInjector {
91
89
  get destroyed(): boolean;
92
90
  private _destroyed;
93
91
  private injectorDefTypes;
94
- constructor(providers: Array<Provider>, parent: Injector, source: string | null, scopes: Set<InjectorScope>);
92
+ constructor(providers: Array<Provider | EnvironmentProviders>, parent: Injector, source: string | null, scopes: Set<InjectorScope>);
95
93
  /**
96
94
  * Destroy the injector and release references to every instance or provider associated with it.
97
95
  *
@@ -99,19 +97,20 @@ export declare class R3Injector extends EnvironmentInjector {
99
97
  * hook was found.
100
98
  */
101
99
  destroy(): void;
102
- onDestroy(callback: () => void): void;
100
+ onDestroy(callback: () => void): () => void;
103
101
  runInContext<ReturnT>(fn: () => ReturnT): ReturnT;
104
102
  get<T>(token: ProviderToken<T>, notFoundValue?: any, flags?: InjectFlags | InjectOptions): T;
105
103
  /** @internal */
106
104
  resolveInjectorInitializers(): void;
107
105
  toString(): string;
108
- private assertNotDestroyed;
106
+ assertNotDestroyed(): void;
109
107
  /**
110
108
  * Process a `SingleProvider` and add it.
111
109
  */
112
110
  private processProvider;
113
111
  private hydrate;
114
112
  private injectableDefInScope;
113
+ private removeOnDestroy;
115
114
  }
116
115
  /**
117
116
  * Converts a `SingleProvider` into a factory function.
@@ -119,5 +118,3 @@ export declare class R3Injector extends EnvironmentInjector {
119
118
  * @param provider provider to convert to factory
120
119
  */
121
120
  export declare function providerToFactory(provider: SingleProvider, ngModuleType?: InjectorType<any>, providers?: any[]): () => any;
122
- export declare function isTypeProvider(value: SingleProvider): value is TypeProvider;
123
- export {};
@@ -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>;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /**
9
+ * Base URL for the error details page.
10
+ *
11
+ * Keep this constant in sync across:
12
+ * - packages/compiler-cli/src/ngtsc/diagnostics/src/error_details_base_url.ts
13
+ * - packages/core/src/error_details_base_url.ts
14
+ */
15
+ export declare const ERROR_DETAILS_PAGE_BASE_URL = "https://angular.io/errors";
16
+ /**
17
+ * URL for the XSS security documentation.
18
+ */
19
+ export declare const XSS_SECURITY_URL = "https://g.co/ng/security#xss";
@@ -0,0 +1,114 @@
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
+ /**
9
+ * The list of error codes used in runtime code of the `core` package.
10
+ * Reserved error code range: 100-999.
11
+ *
12
+ * Note: the minus sign denotes the fact that a particular code has a detailed guide on
13
+ * angular.io. This extra annotation is needed to avoid introducing a separate set to store
14
+ * error codes which have guides, which might leak into runtime code.
15
+ *
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
25
+ */
26
+ export declare const enum RuntimeErrorCode {
27
+ EXPRESSION_CHANGED_AFTER_CHECKED = -100,
28
+ RECURSIVE_APPLICATION_REF_TICK = 101,
29
+ RECURSIVE_APPLICATION_RENDER = 102,
30
+ CYCLIC_DI_DEPENDENCY = -200,
31
+ PROVIDER_NOT_FOUND = -201,
32
+ INVALID_FACTORY_DEPENDENCY = 202,
33
+ MISSING_INJECTION_CONTEXT = -203,
34
+ INVALID_INJECTION_TOKEN = 204,
35
+ INJECTOR_ALREADY_DESTROYED = 205,
36
+ PROVIDER_IN_WRONG_CONTEXT = 207,
37
+ MISSING_INJECTION_TOKEN = 208,
38
+ INVALID_MULTI_PROVIDER = -209,
39
+ MISSING_DOCUMENT = 210,
40
+ MULTIPLE_COMPONENTS_MATCH = -300,
41
+ EXPORT_NOT_FOUND = -301,
42
+ PIPE_NOT_FOUND = -302,
43
+ UNKNOWN_BINDING = 303,
44
+ UNKNOWN_ELEMENT = 304,
45
+ TEMPLATE_STRUCTURE_ERROR = 305,
46
+ INVALID_EVENT_BINDING = 306,
47
+ HOST_DIRECTIVE_UNRESOLVABLE = 307,
48
+ HOST_DIRECTIVE_NOT_STANDALONE = 308,
49
+ DUPLICATE_DIRECTITVE = 309,
50
+ HOST_DIRECTIVE_COMPONENT = 310,
51
+ HOST_DIRECTIVE_UNDEFINED_BINDING = 311,
52
+ HOST_DIRECTIVE_CONFLICTING_ALIAS = 312,
53
+ MULTIPLE_MATCHING_PIPES = 313,
54
+ MULTIPLE_PLATFORMS = 400,
55
+ PLATFORM_NOT_FOUND = 401,
56
+ MISSING_REQUIRED_INJECTABLE_IN_BOOTSTRAP = 402,
57
+ BOOTSTRAP_COMPONENTS_NOT_FOUND = -403,
58
+ PLATFORM_ALREADY_DESTROYED = 404,
59
+ ASYNC_INITIALIZERS_STILL_RUNNING = 405,
60
+ APPLICATION_REF_ALREADY_DESTROYED = 406,
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,
72
+ INVALID_I18N_STRUCTURE = 700,
73
+ MISSING_LOCALE_DATA = 701,
74
+ IMPORT_PROVIDERS_FROM_STANDALONE = 800,
75
+ INVALID_DIFFER_INPUT = 900,
76
+ NO_SUPPORTING_DIFFER_FACTORY = 901,
77
+ VIEW_ALREADY_ATTACHED = 902,
78
+ INVALID_INHERITANCE = 903,
79
+ UNSAFE_VALUE_IN_RESOURCE_URL = 904,
80
+ UNSAFE_VALUE_IN_SCRIPT = 905,
81
+ MISSING_GENERATED_DEF = 906,
82
+ TYPE_IS_NOT_STANDALONE = 907,
83
+ MISSING_ZONEJS = 908,
84
+ UNEXPECTED_ZONE_STATE = 909,
85
+ UNSAFE_IFRAME_ATTRS = -910,
86
+ VIEW_ALREADY_DESTROYED = 911,
87
+ COMPONENT_ID_COLLISION = -912,
88
+ RUNTIME_DEPS_INVALID_IMPORTED_TYPE = 1000
89
+ }
90
+ /**
91
+ * Class that represents a runtime error.
92
+ * Formats and outputs the error message in a consistent way.
93
+ *
94
+ * Example:
95
+ * ```
96
+ * throw new RuntimeError(
97
+ * RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
98
+ * ngDevMode && 'Injector has already been destroyed.');
99
+ * ```
100
+ *
101
+ * Note: the `message` argument contains a descriptive error message as a string in development
102
+ * mode (when the `ngDevMode` is defined). In production mode (after tree-shaking pass), the
103
+ * `message` argument becomes `false`, thus we account for it in the typings and the runtime
104
+ * logic.
105
+ */
106
+ export declare class RuntimeError<T extends number = RuntimeErrorCode> extends Error {
107
+ code: T;
108
+ constructor(code: T, message: null | false | string);
109
+ }
110
+ /**
111
+ * Called to format a runtime error.
112
+ * See additional info on the `message` argument type in the `RuntimeError` class description.
113
+ */
114
+ export declare function formatRuntimeError<T extends number = RuntimeErrorCode>(code: T, message: null | false | string): string;
@@ -5,6 +5,18 @@
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
+ /**
9
+ * @description
10
+ *
11
+ * Represents a type that a Component or other object is instances of.
12
+ *
13
+ * An example of a `Type` is `MyCustomComponent` class, which in JavaScript is represented by
14
+ * the `MyCustomComponent` constructor function.
15
+ *
16
+ * @publicApi
17
+ */
18
+ export declare const Type: FunctionConstructor;
19
+ export declare function isType(v: any): v is Type<any>;
8
20
  /**
9
21
  * @description
10
22
  *
@@ -19,3 +31,36 @@ export interface AbstractType<T> extends Function {
19
31
  export interface Type<T> extends Function {
20
32
  new (...args: any[]): T;
21
33
  }
34
+ export type Mutable<T extends {
35
+ [x: string]: any;
36
+ }, K extends string> = {
37
+ [P in K]: T[P];
38
+ };
39
+ /**
40
+ * Returns a writable type version of type.
41
+ *
42
+ * USAGE:
43
+ * Given:
44
+ * ```
45
+ * interface Person {readonly name: string}
46
+ * ```
47
+ *
48
+ * We would like to get a read/write version of `Person`.
49
+ * ```
50
+ * const WritablePerson = Writable<Person>;
51
+ * ```
52
+ *
53
+ * The result is that you can do:
54
+ *
55
+ * ```
56
+ * const readonlyPerson: Person = {name: 'Marry'};
57
+ * readonlyPerson.name = 'John'; // TypeError
58
+ * (readonlyPerson as WritablePerson).name = 'John'; // OK
59
+ *
60
+ * // Error: Correctly detects that `Person` did not have `age` property.
61
+ * (readonlyPerson as WritablePerson).age = 30;
62
+ * ```
63
+ */
64
+ export type Writable<T> = {
65
+ -readonly [K in keyof T]: T[K];
66
+ };
@@ -1,2 +1,9 @@
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
+ */
1
8
  /** Throws an error when a token is not found in DI. */
2
9
  export declare function throwProviderNotFoundError(token: any, injectorName?: string): never;
@@ -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;
@@ -1,10 +1,3 @@
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
1
  /**
9
2
  * Throws an error indicating that a factory function could not be generated by the compiler for a
10
3
  * particular class.
@@ -1,10 +1,18 @@
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
1
  export declare function deepForEach<T>(input: (T | any[])[], fn: (value: T) => void): void;
9
2
  export declare function newArray<T = any>(size: number): T[];
10
3
  export declare function newArray<T>(size: number, value: T): T[];
4
+ /**
5
+ * `KeyValueArray` is an array where even positions contain keys and odd positions contain values.
6
+ *
7
+ * `KeyValueArray` provides a very efficient way of iterating over its contents. For small
8
+ * sets (~10) the cost of binary searching an `KeyValueArray` has about the same performance
9
+ * characteristics that of a `Map` with significantly better memory footprint.
10
+ *
11
+ * If used as a `Map` the keys are stored in alphabetical order so that they can be binary searched
12
+ * for retrieval.
13
+ *
14
+ * See: `keyValueArraySet`, `keyValueArrayGet`, `keyValueArrayIndexOf`, `keyValueArrayDelete`.
15
+ */
16
+ export interface KeyValueArray<VALUE> extends Array<VALUE | string> {
17
+ __brand__: 'array-map';
18
+ }
@@ -23,5 +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
- export declare function makeParamDecorator(name: string, props?: (...args: any[]) => any): any;
28
+ export declare const PARAMETERS = "__parameters__";
29
+ export declare function makeParamDecorator(name: string, props?: (...args: any[]) => any, parentClass?: any): any;
@@ -11,4 +11,5 @@
11
11
  * allows for identity checks against these values to be consistently used by the framework
12
12
  * code.
13
13
  */
14
+ export declare const EMPTY_OBJ: {};
14
15
  export declare const EMPTY_ARRAY: any[];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "static-injector",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Angular的静态注入器独立使用版本",
5
5
  "keywords": [
6
6
  "angular",
7
7
  "injector",
8
8
  "typescript",
9
- "typescript 4.9",
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
- "es2015": "import/fesm2015/index.js",
23
- "fesm2015": "import/fesm2015/index.js",
24
- "esm2015": "import/esm2015/index.js",
25
- "module": "import/fesm2015/index.js",
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": "^4.9.3"
32
+ "typescript": "~5.1.6"
33
33
  },
34
34
  "devDependencies": {},
35
35
  "sideEffects": false
package/readme.md CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  - 这是 Angualr 依赖注入的独立版本,初始版本逻辑为从 Angular 源码中提取出来,并修复了一些已知 bug
4
4
  - 使用方法与 Angular 的依赖注入完全一致
5
-
5
+ # 来源
6
+ - Angular 16.2.2
7
+ # 兼容
8
+ - ts 5.1.6
6
9
  # 使用方法
7
10
 
8
11
  - 以`Injector.create`创建第一级依赖注入器
@@ -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.internalType);
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)(Object.assign(Object.assign({}, factoryMeta), { delegate: meta.useClass.expression, delegateDeps: deps, delegateType: r3_factory_1.R3FactoryDelegateType.Class }));
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)(Object.assign(Object.assign({}, factoryMeta), { delegate: meta.useFactory, delegateDeps: meta.deps || [], delegateType: r3_factory_1.R3FactoryDelegateType.Function }));
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)(Object.assign(Object.assign({}, factoryMeta), { expression: meta.useValue.expression }));
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)(Object.assign(Object.assign({}, factoryMeta), { expression: o
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.internalType, resolveForwardRefs),
116
+ expression: delegateToFactory(meta.type.value, meta.type.value, resolveForwardRefs),
102
117
  };
103
118
  }
104
- const token = meta.internalType;
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, internalType, unwrapForwardRefs) {
129
- if (type.node === internalType.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 internalType.prop('ɵfac');
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 internalType.ɵfac(t); }
155
+ // factory: function(t) { return useType.ɵfac(t); }
141
156
  // ```
142
- return createFactoryFunction(internalType);
157
+ return createFactoryFunction(useType);
143
158
  }
144
- // The internalType is actually wrapped in a `forwardRef()` so we need to resolve that before
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([internalType]);
166
+ .callFn([useType]);
152
167
  return createFactoryFunction(unwrappedType);
153
168
  }
154
169
  function createFactoryFunction(type) {