static-injector 4.0.1 → 5.0.0-alpha.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 (179) hide show
  1. package/{import/commonjs → commonjs}/index.js +29 -197
  2. package/{import/es2022 → es2022}/di/interface/defs.js +5 -1
  3. package/{import/es2022 → es2022}/index.js +0 -1
  4. package/{transform/compiler/index.d.ts → es2022/interface/lifecycle_hooks.js} +1 -1
  5. package/{transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.js → es2022/render3/definition_factory.js} +3 -2
  6. package/es2022/util/decorators.js +31 -0
  7. package/{import/fesm2022 → fesm2022}/index.js +30 -196
  8. package/package.json +17 -14
  9. package/readme.md +33 -13
  10. package/{import/typings → typings}/di/injectable.d.ts +0 -7
  11. package/{import/typings → typings}/index.d.ts +0 -1
  12. package/import/es2022/di/injectable.js +0 -14
  13. package/import/es2022/error_details_base_url.js +0 -19
  14. package/import/es2022/render3/definition_factory.js +0 -14
  15. package/import/es2022/render3/di.js +0 -49
  16. package/import/es2022/render3/error_code.js +0 -30
  17. package/import/es2022/util/array_utils.js +0 -17
  18. package/import/es2022/util/decorators.js +0 -53
  19. package/import/typings/error_details_base_url.d.ts +0 -19
  20. package/import/typings/render3/di.d.ts +0 -12
  21. package/import/typings/render3/error_code.d.ts +0 -24
  22. package/import/typings/util/array_utils.d.ts +0 -25
  23. package/transform/compiler/compiler.d.ts +0 -8
  24. package/transform/compiler/compiler.js +0 -28
  25. package/transform/compiler/index.js +0 -28
  26. package/transform/compiler/public_api.d.ts +0 -13
  27. package/transform/compiler/public_api.js +0 -30
  28. package/transform/compiler/src/compiler.d.ts +0 -5
  29. package/transform/compiler/src/compiler.js +0 -21
  30. package/transform/compiler/src/core.d.ts +0 -25
  31. package/transform/compiler/src/core.js +0 -22
  32. package/transform/compiler/src/injectable_compiler_2.d.ts +0 -23
  33. package/transform/compiler/src/injectable_compiler_2.js +0 -171
  34. package/transform/compiler/src/output/output_ast.d.ts +0 -512
  35. package/transform/compiler/src/output/output_ast.js +0 -1109
  36. package/transform/compiler/src/parse_util.d.ts +0 -50
  37. package/transform/compiler/src/parse_util.js +0 -71
  38. package/transform/compiler/src/render3/partial/api.d.ts +0 -171
  39. package/transform/compiler/src/render3/partial/api.js +0 -18
  40. package/transform/compiler/src/render3/r3_factory.d.ts +0 -82
  41. package/transform/compiler/src/render3/r3_factory.js +0 -225
  42. package/transform/compiler/src/render3/r3_identifiers.d.ts +0 -20
  43. package/transform/compiler/src/render3/r3_identifiers.js +0 -55
  44. package/transform/compiler/src/render3/util.d.ts +0 -85
  45. package/transform/compiler/src/render3/util.js +0 -82
  46. package/transform/compiler/src/render3/view/util.d.ts +0 -24
  47. package/transform/compiler/src/render3/view/util.js +0 -59
  48. package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +0 -3
  49. package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +0 -19
  50. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +0 -37
  51. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +0 -195
  52. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.d.ts +0 -11
  53. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +0 -22
  54. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +0 -64
  55. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +0 -189
  56. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +0 -43
  57. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +0 -277
  58. package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +0 -24
  59. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +0 -84
  60. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.d.ts +0 -188
  61. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +0 -206
  62. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +0 -2
  63. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +0 -18
  64. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +0 -1
  65. package/transform/compiler-cli/src/ngtsc/imports/index.js +0 -17
  66. package/transform/compiler-cli/src/ngtsc/imports/src/core.d.ts +0 -36
  67. package/transform/compiler-cli/src/ngtsc/imports/src/core.js +0 -25
  68. package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +0 -19
  69. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +0 -27
  70. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +0 -3
  71. package/transform/compiler-cli/src/ngtsc/reflection/index.js +0 -19
  72. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +0 -522
  73. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +0 -34
  74. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +0 -25
  75. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +0 -271
  76. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +0 -53
  77. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +0 -393
  78. package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +0 -12
  79. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +0 -29
  80. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +0 -2
  81. package/transform/compiler-cli/src/ngtsc/transform/index.js +0 -18
  82. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +0 -115
  83. package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -29
  84. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +0 -15
  85. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +0 -79
  86. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +0 -5
  87. package/transform/compiler-cli/src/ngtsc/translator/index.js +0 -21
  88. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +0 -289
  89. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.d.ts +0 -27
  90. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.js +0 -9
  91. package/transform/compiler-cli/src/ngtsc/translator/src/context.d.ts +0 -18
  92. package/transform/compiler-cli/src/ngtsc/translator/src/context.js +0 -28
  93. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +0 -47
  94. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +0 -66
  95. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +0 -56
  96. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +0 -270
  97. package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.d.ts +0 -12
  98. package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.js +0 -27
  99. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +0 -53
  100. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +0 -250
  101. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +0 -13
  102. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.js +0 -21
  103. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +0 -8
  104. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +0 -24
  105. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +0 -45
  106. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +0 -86
  107. package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +0 -4
  108. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +0 -16
  109. package/transform/index.d.ts +0 -1
  110. package/transform/index.js +0 -17
  111. package/transform/injectable-transform.d.ts +0 -41
  112. package/transform/injectable-transform.js +0 -245
  113. package/transform/node-Iteration.d.ts +0 -2
  114. package/transform/node-Iteration.js +0 -12
  115. /package/{import/es2022 → es2022}/di/create_injector.js +0 -0
  116. /package/{import/es2022 → es2022}/di/forward_ref.js +0 -0
  117. /package/{import/es2022 → es2022}/di/index.js +0 -0
  118. /package/{import/es2022 → es2022}/di/initializer_token.js +0 -0
  119. /package/{import/es2022 → es2022}/di/inject_switch.js +0 -0
  120. /package/{import/es2022/di/injector_marker.js → es2022/di/injectable.js} +0 -0
  121. /package/{import/es2022 → es2022}/di/injection_token.js +0 -0
  122. /package/{import/es2022 → es2022}/di/injector.js +0 -0
  123. /package/{import/es2022 → es2022}/di/injector_compatibility.js +0 -0
  124. /package/{import/es2022/di/provider_token.js → es2022/di/injector_marker.js} +0 -0
  125. /package/{import/es2022 → es2022}/di/injector_token.js +0 -0
  126. /package/{import/es2022 → es2022}/di/interface/injector.js +0 -0
  127. /package/{import/es2022 → es2022}/di/interface/provider.js +0 -0
  128. /package/{import/es2022 → es2022}/di/internal_tokens.js +0 -0
  129. /package/{import/es2022 → es2022}/di/metadata.js +0 -0
  130. /package/{import/es2022 → es2022}/di/null_injector.js +0 -0
  131. /package/{import/es2022 → es2022}/di/provider_collection.js +0 -0
  132. /package/{import/es2022/interface/lifecycle_hooks.js → es2022/di/provider_token.js} +0 -0
  133. /package/{import/es2022 → es2022}/di/r3_injector.js +0 -0
  134. /package/{import/es2022 → es2022}/di/scope.js +0 -0
  135. /package/{import/es2022 → es2022}/di.js +0 -0
  136. /package/{import/es2022 → es2022}/errors.js +0 -0
  137. /package/{import/es2022 → es2022}/interface/type.js +0 -0
  138. /package/{import/es2022 → es2022}/render3/errors_di.js +0 -0
  139. /package/{import/es2022 → es2022}/render3/fields.js +0 -0
  140. /package/{import/es2022 → es2022}/render3/instructions/di.js +0 -0
  141. /package/{import/es2022 → es2022}/render3/util/stringify_utils.js +0 -0
  142. /package/{import/es2022 → es2022}/util/closure.js +0 -0
  143. /package/{import/es2022 → es2022}/util/empty.js +0 -0
  144. /package/{import/es2022 → es2022}/util/property.js +0 -0
  145. /package/{import/es2022 → es2022}/util/stringify.js +0 -0
  146. /package/{import/typings → typings}/di/create_injector.d.ts +0 -0
  147. /package/{import/typings → typings}/di/forward_ref.d.ts +0 -0
  148. /package/{import/typings → typings}/di/index.d.ts +0 -0
  149. /package/{import/typings → typings}/di/initializer_token.d.ts +0 -0
  150. /package/{import/typings → typings}/di/inject_switch.d.ts +0 -0
  151. /package/{import/typings → typings}/di/injection_token.d.ts +0 -0
  152. /package/{import/typings → typings}/di/injector.d.ts +0 -0
  153. /package/{import/typings → typings}/di/injector_compatibility.d.ts +0 -0
  154. /package/{import/typings → typings}/di/injector_marker.d.ts +0 -0
  155. /package/{import/typings → typings}/di/injector_token.d.ts +0 -0
  156. /package/{import/typings → typings}/di/interface/defs.d.ts +0 -0
  157. /package/{import/typings → typings}/di/interface/injector.d.ts +0 -0
  158. /package/{import/typings → typings}/di/interface/provider.d.ts +0 -0
  159. /package/{import/typings → typings}/di/internal_tokens.d.ts +0 -0
  160. /package/{import/typings → typings}/di/metadata.d.ts +0 -0
  161. /package/{import/typings → typings}/di/null_injector.d.ts +0 -0
  162. /package/{import/typings → typings}/di/provider_collection.d.ts +0 -0
  163. /package/{import/typings → typings}/di/provider_token.d.ts +0 -0
  164. /package/{import/typings → typings}/di/r3_injector.d.ts +0 -0
  165. /package/{import/typings → typings}/di/scope.d.ts +0 -0
  166. /package/{import/typings → typings}/di.d.ts +0 -0
  167. /package/{import/typings → typings}/errors.d.ts +0 -0
  168. /package/{import/typings → typings}/interface/lifecycle_hooks.d.ts +0 -0
  169. /package/{import/typings → typings}/interface/type.d.ts +0 -0
  170. /package/{import/typings → typings}/render3/definition_factory.d.ts +0 -0
  171. /package/{import/typings → typings}/render3/errors_di.d.ts +0 -0
  172. /package/{import/typings → typings}/render3/fields.d.ts +0 -0
  173. /package/{import/typings → typings}/render3/instructions/di.d.ts +0 -0
  174. /package/{import/typings → typings}/render3/util/stringify_utils.d.ts +0 -0
  175. /package/{import/typings → typings}/util/closure.d.ts +0 -0
  176. /package/{import/typings → typings}/util/decorators.d.ts +0 -0
  177. /package/{import/typings → typings}/util/empty.d.ts +0 -0
  178. /package/{import/typings → typings}/util/property.d.ts +0 -0
  179. /package/{import/typings → typings}/util/stringify.d.ts +0 -0
@@ -1,18 +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
- /**
9
- * Injectable decorator and metadata.
10
- *
11
- * @Annotation
12
- * @publicApi
13
- */
14
- const Injectable = undefined;
15
-
16
1
  /**
17
2
  * @license
18
3
  * Copyright Google LLC All Rights Reserved.
@@ -40,7 +25,6 @@ function noSideEffects(fn) {
40
25
  * Use of this source code is governed by an MIT-style license that can be
41
26
  * found in the LICENSE file at https://angular.io/license
42
27
  */
43
- const PARAMETERS = '__parameters__';
44
28
  function makeMetadataCtor(props) {
45
29
  return function ctor(...args) {
46
30
  if (props) {
@@ -55,33 +39,9 @@ function makeParamDecorator(name, props, parentClass) {
55
39
  return noSideEffects(() => {
56
40
  const metaCtor = makeMetadataCtor(props);
57
41
  function ParamDecoratorFactory(...args) {
58
- if (this instanceof ParamDecoratorFactory) {
59
- metaCtor.apply(this, args);
60
- return this;
61
- }
62
- const annotationInstance = new ParamDecoratorFactory(...args);
63
- ParamDecorator.annotation = annotationInstance;
64
- return ParamDecorator;
65
- function ParamDecorator(cls, unusedKey, index) {
66
- // Use of Object.defineProperty is important since it creates non-enumerable property which
67
- // prevents the property is copied during subclassing.
68
- const parameters = cls.hasOwnProperty(PARAMETERS)
69
- ? cls[PARAMETERS]
70
- : Object.defineProperty(cls, PARAMETERS, { value: [] })[PARAMETERS];
71
- // there might be gaps if some in between parameters do not have annotations.
72
- // we pad with nulls.
73
- while (parameters.length <= index) {
74
- parameters.push(null);
75
- }
76
- (parameters[index] = parameters[index] || []).push(annotationInstance);
77
- return cls;
78
- }
79
- }
80
- if (parentClass) {
81
- ParamDecoratorFactory.prototype = Object.create(parentClass.prototype);
42
+ metaCtor.apply(this, args);
43
+ return this;
82
44
  }
83
- ParamDecoratorFactory.prototype.ngMetadataName = name;
84
- ParamDecoratorFactory.annotationCls = ParamDecoratorFactory;
85
45
  return ParamDecoratorFactory;
86
46
  });
87
47
  }
@@ -126,8 +86,6 @@ function formatRuntimeError(code, message) {
126
86
  // We also prepend `0` to non-compile-time errors.
127
87
  const fullCode = `NG0${Math.abs(code)}`;
128
88
  let errorMessage = `${fullCode}${message ? ': ' + message : ''}`;
129
- if (false) {
130
- }
131
89
  return errorMessage;
132
90
  }
133
91
 
@@ -161,21 +119,6 @@ function stringify(token) {
161
119
  const newLineIndex = res.indexOf('\n');
162
120
  return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
163
121
  }
164
- /**
165
- * Ellipses the string in the middle when longer than the max length
166
- *
167
- * @param string
168
- * @param maxLength of the output string
169
- * @returns ellipsed string with ... in the middle
170
- */
171
- function truncateMiddle(str, maxLength = 100) {
172
- if (!str || maxLength < 1 || str.length <= maxLength)
173
- return str;
174
- if (maxLength == 1)
175
- return str.substring(0, 1) + '...';
176
- const halfLimit = Math.round(maxLength / 2);
177
- return (str.substring(0, halfLimit) + '...' + str.substring(str.length - halfLimit));
178
- }
179
122
 
180
123
  /**
181
124
  * @license
@@ -345,7 +288,11 @@ function ɵɵdefineInjector(options) {
345
288
  * @param type A type which may have its own (non-inherited) `ɵprov`.
346
289
  */
347
290
  function getInjectableDef(type) {
348
- return getOwnDefinition(type, NG_PROV_DEF) || null;
291
+ return (getOwnDefinition(type, NG_PROV_DEF) || {
292
+ token: type,
293
+ factory: () => new type(),
294
+ ...type.injectOptions,
295
+ });
349
296
  }
350
297
  function isInjectable(type) {
351
298
  return getInjectableDef(type) !== null;
@@ -462,9 +409,7 @@ function injectRootLimpMode(token, notFoundValue, flags) {
462
409
  }
463
410
  if (flags & InjectFlags.Optional)
464
411
  return null;
465
- if (notFoundValue !== undefined)
466
- return notFoundValue;
467
- throwProviderNotFoundError(token, 'Injector');
412
+ throwProviderNotFoundError();
468
413
  }
469
414
 
470
415
  /**
@@ -754,7 +699,7 @@ makeParamDecorator('Inject', (token) => ({ token })), -1 /* DecoratorFlags.Injec
754
699
  const Optional =
755
700
  // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
756
701
  // tslint:disable-next-line: no-toplevel-property-access
757
- attachInjectFlag(makeParamDecorator('Optional'), 8 /* InternalInjectFlags.Optional */);
702
+ attachInjectFlag(makeParamDecorator(), 8 /* InternalInjectFlags.Optional */);
758
703
  /**
759
704
  * Self decorator and metadata.
760
705
  *
@@ -764,7 +709,7 @@ attachInjectFlag(makeParamDecorator('Optional'), 8 /* InternalInjectFlags.Option
764
709
  const Self =
765
710
  // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
766
711
  // tslint:disable-next-line: no-toplevel-property-access
767
- attachInjectFlag(makeParamDecorator('Self'), 2 /* InternalInjectFlags.Self */);
712
+ attachInjectFlag(makeParamDecorator(), 2 /* InternalInjectFlags.Self */);
768
713
  /**
769
714
  * `SkipSelf` decorator and metadata.
770
715
  *
@@ -774,7 +719,18 @@ attachInjectFlag(makeParamDecorator('Self'), 2 /* InternalInjectFlags.Self */);
774
719
  const SkipSelf =
775
720
  // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
776
721
  // tslint:disable-next-line: no-toplevel-property-access
777
- attachInjectFlag(makeParamDecorator('SkipSelf'), 4 /* InternalInjectFlags.SkipSelf */);
722
+ attachInjectFlag(makeParamDecorator(), 4 /* InternalInjectFlags.SkipSelf */);
723
+
724
+ /**
725
+ * @license
726
+ * Copyright Google LLC All Rights Reserved.
727
+ *
728
+ * Use of this source code is governed by an MIT-style license that can be
729
+ * found in the LICENSE file at https://angular.io/license
730
+ */
731
+ function getFactoryDef(type, throwNotFound) {
732
+ return () => new type();
733
+ }
778
734
 
779
735
  /**
780
736
  * @license
@@ -783,7 +739,7 @@ attachInjectFlag(makeParamDecorator('SkipSelf'), 4 /* InternalInjectFlags.SkipSe
783
739
  * Use of this source code is governed by an MIT-style license that can be
784
740
  * found in the LICENSE file at https://angular.io/license
785
741
  */
786
- const NG_FACTORY_DEF = getClosureSafeProperty({
742
+ getClosureSafeProperty({
787
743
  ɵfac: getClosureSafeProperty,
788
744
  });
789
745
  /**
@@ -798,20 +754,6 @@ const NG_ENV_ID = getClosureSafeProperty({
798
754
  __NG_ENV_ID__: getClosureSafeProperty,
799
755
  });
800
756
 
801
- /**
802
- * @license
803
- * Copyright Google LLC All Rights Reserved.
804
- *
805
- * Use of this source code is governed by an MIT-style license that can be
806
- * found in the LICENSE file at https://angular.io/license
807
- */
808
- function getFactoryDef(type, throwNotFound) {
809
- const hasFactoryDef = type.hasOwnProperty(NG_FACTORY_DEF);
810
- if (false) {
811
- }
812
- return hasFactoryDef ? type[NG_FACTORY_DEF] : null;
813
- }
814
-
815
757
  /**
816
758
  * @license
817
759
  * Copyright Google LLC All Rights Reserved.
@@ -825,11 +767,7 @@ function getFactoryDef(type, throwNotFound) {
825
767
  * allows for identity checks against these values to be consistently used by the framework
826
768
  * code.
827
769
  */
828
- const EMPTY_OBJ = {};
829
770
  const EMPTY_ARRAY = [];
830
- // freezing the values prevents any code from accidentally inserting new values in
831
- if (false) {
832
- }
833
771
 
834
772
  /**
835
773
  * @license
@@ -901,10 +839,7 @@ class InjectionToken {
901
839
  constructor(_desc, options) {
902
840
  this._desc = _desc;
903
841
  this.ɵprov = undefined;
904
- if (typeof options == 'number') {
905
- // This is a special hack to assign __NG_ELEMENT_ID__ to this instance.
906
- // See `InjectorMarkers`
907
- }
842
+ if (typeof options == 'number') ;
908
843
  else if (options !== undefined) {
909
844
  this.ɵprov = ɵɵdefineInjectable({
910
845
  token: this,
@@ -1004,15 +939,6 @@ class NullInjector {
1004
939
  * Use of this source code is governed by an MIT-style license that can be
1005
940
  * found in the LICENSE file at https://angular.io/license
1006
941
  */
1007
- /**
1008
- * Wrap an array of `Provider`s into `EnvironmentProviders`, preventing them from being accidentally
1009
- * referenced in `@Component` in a component injector.
1010
- */
1011
- function makeEnvironmentProviders(providers) {
1012
- return {
1013
- ɵproviders: providers,
1014
- };
1015
- }
1016
942
  /**
1017
943
  * Collects providers from all NgModules and standalone components, including transitively imported
1018
944
  * ones.
@@ -1061,26 +987,8 @@ function importProvidersFrom(...sources) {
1061
987
  }
1062
988
  function internalImportProvidersFrom(checkForStandaloneCmp, ...sources) {
1063
989
  const providersOut = [];
1064
- const dedup = new Set(); // already seen types
1065
- let injectorTypesWithProviders;
1066
- const collectProviders = (provider) => {
1067
- providersOut.push(provider);
1068
- };
1069
- // Collect all providers from `ModuleWithProviders` types.
1070
- if (injectorTypesWithProviders !== undefined) {
1071
- processInjectorTypesWithProviders(injectorTypesWithProviders, collectProviders);
1072
- }
1073
990
  return providersOut;
1074
991
  }
1075
- /**
1076
- * Collects all providers from the list of `ModuleWithProviders` and appends them to the provided
1077
- * array.
1078
- */
1079
- function processInjectorTypesWithProviders(typesWithProviders, visitor) {
1080
- for (let i = 0; i < typesWithProviders.length; i++) {
1081
- const { ngModule, providers } = typesWithProviders[i];
1082
- }
1083
- }
1084
992
  const USE_VALUE = getClosureSafeProperty({
1085
993
  provide: String,
1086
994
  useValue: getClosureSafeProperty,
@@ -1097,9 +1005,6 @@ function isFactoryProvider(value) {
1097
1005
  function isTypeProvider(value) {
1098
1006
  return typeof value === 'function';
1099
1007
  }
1100
- function isClassProvider(value) {
1101
- return !!value.useClass;
1102
- }
1103
1008
 
1104
1009
  /**
1105
1010
  * @license
@@ -1233,8 +1138,6 @@ class R3Injector extends EnvironmentInjector {
1233
1138
  this.assertNotDestroyed();
1234
1139
  const previousInjector = setCurrentInjector(this);
1235
1140
  const previousInjectImplementation = setInjectImplementation(undefined);
1236
- if (false) {
1237
- }
1238
1141
  try {
1239
1142
  return fn();
1240
1143
  }
@@ -1249,9 +1152,6 @@ class R3Injector extends EnvironmentInjector {
1249
1152
  return token[NG_ENV_ID](this);
1250
1153
  }
1251
1154
  flags = convertToBitFlags(flags);
1252
- // Set the injection context.
1253
- if (false) {
1254
- }
1255
1155
  const previousInjector = setCurrentInjector(this);
1256
1156
  const previousInjectImplementation = setInjectImplementation(undefined);
1257
1157
  try {
@@ -1266,8 +1166,7 @@ class R3Injector extends EnvironmentInjector {
1266
1166
  if (def && this.injectableDefInScope(def)) {
1267
1167
  // Found an injectable def and it's scoped to this injector. Pretend as if it was here
1268
1168
  // all along.
1269
- if (false) {
1270
- }
1169
+ if (false) ;
1271
1170
  record = makeRecord(injectableDefOrInjectorDefFactory(token), NOT_YET);
1272
1171
  }
1273
1172
  else {
@@ -1321,12 +1220,9 @@ class R3Injector extends EnvironmentInjector {
1321
1220
  resolveInjectorInitializers() {
1322
1221
  const previousInjector = setCurrentInjector(this);
1323
1222
  const previousInjectImplementation = setInjectImplementation(undefined);
1324
- if (false) {
1325
- }
1326
1223
  try {
1327
1224
  const initializers = this.get(ENVIRONMENT_INITIALIZER, EMPTY_ARRAY, InjectFlags.Self);
1328
- if (false) {
1329
- }
1225
+ if (false) ;
1330
1226
  for (const initializer of initializers) {
1331
1227
  initializer();
1332
1228
  }
@@ -1361,17 +1257,11 @@ class R3Injector extends EnvironmentInjector {
1361
1257
  : resolveForwardRef(provider && provider.provide);
1362
1258
  // Construct a `Record` for the provider.
1363
1259
  const record = providerToRecord(provider);
1364
- if (false) {
1365
- }
1366
1260
  if (!isTypeProvider(provider) && provider.multi === true) {
1367
1261
  // If the provider indicates that it's a multi-provider, process it specially.
1368
1262
  // First check whether it's been defined already.
1369
1263
  let multiRecord = this.records.get(token);
1370
- if (multiRecord) {
1371
- // It has. Throw a nice error if
1372
- if (false) {
1373
- }
1374
- }
1264
+ if (multiRecord) ;
1375
1265
  else {
1376
1266
  multiRecord = makeRecord(undefined, NOT_YET, true);
1377
1267
  multiRecord.factory = () => injectArgs(multiRecord.multi);
@@ -1380,20 +1270,14 @@ class R3Injector extends EnvironmentInjector {
1380
1270
  token = provider;
1381
1271
  multiRecord.multi.push(provider);
1382
1272
  }
1383
- else {
1384
- if (false) {
1385
- }
1386
- }
1387
1273
  this.records.set(token, record);
1388
1274
  }
1389
1275
  hydrate(token, record) {
1390
1276
  try {
1391
- if (false) {
1392
- }
1277
+ if (false) ;
1393
1278
  else if (record.value === NOT_YET) {
1394
1279
  record.value = CIRCULAR;
1395
- if (false) {
1396
- }
1280
+ if (false) ;
1397
1281
  else {
1398
1282
  record.value = record.factory();
1399
1283
  }
@@ -1481,8 +1365,6 @@ function providerToRecord(provider) {
1481
1365
  */
1482
1366
  function providerToFactory(provider, ngModuleType, providers) {
1483
1367
  let factory = undefined;
1484
- if (false) {
1485
- }
1486
1368
  if (isTypeProvider(provider)) {
1487
1369
  const unwrappedProvider = resolveForwardRef(provider);
1488
1370
  return (getFactoryDef(unwrappedProvider) ||
@@ -1502,8 +1384,6 @@ function providerToFactory(provider, ngModuleType, providers) {
1502
1384
  const classRef = resolveForwardRef(provider &&
1503
1385
  (provider.useClass ||
1504
1386
  provider.provide));
1505
- if (false) {
1506
- }
1507
1387
  if (hasDeps(provider)) {
1508
1388
  factory = () => new classRef(...injectArgs(provider.deps));
1509
1389
  }
@@ -1656,50 +1536,4 @@ function ɵɵinvalidFactory() {
1656
1536
  throw new Error(msg);
1657
1537
  }
1658
1538
 
1659
- /**
1660
- * @license
1661
- * Copyright Google LLC All Rights Reserved.
1662
- *
1663
- * Use of this source code is governed by an MIT-style license that can be
1664
- * found in the LICENSE file at https://angular.io/license
1665
- */
1666
- /**
1667
- * @codeGenApi
1668
- */
1669
- function ɵɵgetInheritedFactory(type) {
1670
- return noSideEffects(() => {
1671
- const ownConstructor = type.prototype.constructor;
1672
- const ownFactory = ownConstructor[NG_FACTORY_DEF] || getFactoryOf(ownConstructor);
1673
- const objectPrototype = Object.prototype;
1674
- let parent = Object.getPrototypeOf(type.prototype).constructor;
1675
- // Go up the prototype until we hit `Object`.
1676
- while (parent && parent !== objectPrototype) {
1677
- const factory = parent[NG_FACTORY_DEF] || getFactoryOf(parent);
1678
- // If we hit something that has a factory and the factory isn't the same as the type,
1679
- // we've found the inherited factory. Note the check that the factory isn't the type's
1680
- // own factory is redundant in most cases, but if the user has custom decorators on the
1681
- // class, this lookup will start one level down in the prototype chain, causing us to
1682
- // find the own factory first and potentially triggering an infinite loop downstream.
1683
- if (factory && factory !== ownFactory) {
1684
- return factory;
1685
- }
1686
- parent = Object.getPrototypeOf(parent);
1687
- }
1688
- // There is no factory defined. Either this was improper usage of inheritance
1689
- // (no Angular decorator on the superclass) or there is no constructor at all
1690
- // in the inheritance chain. Since the two cases cannot be distinguished, the
1691
- // latter has to be assumed.
1692
- return (t) => new t();
1693
- });
1694
- }
1695
- function getFactoryOf(type) {
1696
- if (isForwardRef(type)) {
1697
- return () => {
1698
- const factory = getFactoryOf(resolveForwardRef(type));
1699
- return factory && factory();
1700
- };
1701
- }
1702
- return getFactoryDef(type);
1703
- }
1704
-
1705
- export { EnvironmentInjector, INJECTOR_SCOPE, Inject, InjectFlags, Injectable, InjectionToken, Injector, NG_INJ_DEF, NG_PROV_DEF, NG_TEMP_TOKEN_PATH, NullInjector, Optional, R3Injector, SOURCE, Self, SkipSelf, THROW_IF_NOT_FOUND, attachInjectFlag, catchInjectorError, convertToBitFlags, formatError, getCurrentInjector, getInheritedInjectableDef, getInjectFlag, getInjectableDef, getInjectorDef, getNullInjector, inject, injectArgs, injectInjectorOnly, isInjectable, providerToFactory, setCurrentInjector, ɵɵdefineInjectable, ɵɵdefineInjector, ɵɵgetInheritedFactory, ɵɵinject, ɵɵinvalidFactory, ɵɵinvalidFactoryDep };
1539
+ export { EnvironmentInjector, INJECTOR_SCOPE, Inject, InjectFlags, InjectionToken, Injector, NG_INJ_DEF, NG_PROV_DEF, NG_TEMP_TOKEN_PATH, NullInjector, Optional, R3Injector, SOURCE, Self, SkipSelf, THROW_IF_NOT_FOUND, attachInjectFlag, catchInjectorError, convertToBitFlags, formatError, getCurrentInjector, getInheritedInjectableDef, getInjectFlag, getInjectableDef, getInjectorDef, getNullInjector, inject, injectArgs, injectInjectorOnly, isInjectable, providerToFactory, setCurrentInjector, ɵɵdefineInjectable, ɵɵdefineInjector, ɵɵinject, ɵɵinvalidFactory, ɵɵinvalidFactoryDep };
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "static-injector",
3
- "version": "4.0.1",
3
+ "version": "5.0.0-alpha.0",
4
4
  "description": "Angular 依赖注入独立版本;Angular dependency injection standalone version",
5
5
  "keywords": [
6
6
  "angular",
7
- "angular 17.3.1",
7
+ "angular 17.3.6",
8
8
  "injector",
9
9
  "typescript",
10
- "typescript 5.4.2",
11
10
  "injectable",
12
11
  "static-inject",
13
12
  "dependency injection",
14
- "injection-js"
13
+ "injection-js",
14
+ "dependency inversion",
15
+ "di",
16
+ "inversion of control container",
17
+ "ioc",
18
+ "javascript",
19
+ "node"
15
20
  ],
16
21
  "repository": {
17
22
  "type": "git",
@@ -21,19 +26,17 @@
21
26
  "url": "https://github.com/wszgrcy/static-injector/issues"
22
27
  },
23
28
  "homepage": "https://github.com/wszgrcy/static-injector#readme",
24
- "main": "import/commonjs/index.js",
25
- "es2022": "import/fesm2022/index.js",
26
- "fesm2022": "import/fesm2022/index.js",
27
- "esm2022": "import/esm2022/index.js",
28
- "module": "import/fesm2022/index.js",
29
- "typings": "import/typings/index.d.ts",
29
+ "main": "commonjs/index.js",
30
+ "es2022": "fesm2022/index.js",
31
+ "fesm2022": "fesm2022/index.js",
32
+ "esm2022": "esm2022/index.js",
33
+ "module": "fesm2022/index.js",
34
+ "typings": "typings/index.d.ts",
30
35
  "private": false,
31
36
  "scripts": {},
32
37
  "author": "wszgrcy",
33
38
  "license": "MIT",
34
- "peerDependencies": {
35
- "typescript": ">=5.0.0"
36
- },
39
+ "peerDependencies": {},
37
40
  "devDependencies": {},
38
41
  "sideEffects": false
39
- }
42
+ }
package/readme.md CHANGED
@@ -1,41 +1,61 @@
1
- | [中文](https://github.com/wszgrcy/cyia-localize/blob/master/readme.zh-Hans.md) | [English](./readme.md) |
2
- |-|-|
1
+ | [中文](https://github.com/wszgrcy/static-injector/blob/main/readme.zh-Hans.md) | [English](./readme.md) |
2
+ | ------------------------------------------------------------------------------ | ---------------------- |
3
3
 
4
4
  # Introduction
5
5
 
6
6
  - Angular dependency injection standalone version
7
7
  - The usage method is completely consistent with Angular's dependency injection
8
+ - No transformer required
9
+ - 0 dependencies
10
+ - Remove Decorator
11
+ > `@Injectable()`=>`static injectOptions={}`
12
+ > `@Inject() xx`=>`xx=inject()`
13
+ > `@Optional()`=>`xx=inject(token,{optional:true})`
14
+ - `JS`/`TS` Support
8
15
 
9
16
  # Source
10
- - Angular 17.3.1
11
17
 
12
- # dependency
13
- - ts 5.4.2
18
+ - Angular 17.3.6
14
19
 
15
20
  # Usage
16
21
 
17
22
  - Create a first level dependency injector with `Injector.create`
18
- - Declare as a dependency injection class using the `@Injectable` decorator
23
+ ```ts
24
+ import { Injector } from 'static-injector';
25
+
26
+ export class FirstClass {
27
+ constructor() {}
28
+ hello() {
29
+ return 'hello';
30
+ }
31
+ }
32
+
33
+ let injector = Injector.create({
34
+ providers: [{ provide: FirstClass }],
35
+ });
36
+ let instance = injector.get(FirstClass);
37
+ console.log(instance.hello());
38
+
39
+ ```
19
40
 
20
41
  # Different from `injection-js`
21
42
 
22
43
  - `injection-js` belongs to dynamic dependency injection and is a version used before Angular5. After Angular5, it has been converted to static dependency injection
23
44
  - In theory, it would be faster than `injection-js` (otherwise Angular wouldn't do the replacement...), but there was no benchmark done
24
- - Need to use `typescript` to call the transformer for conversion/use webpack's ts loader to pass in the converter/roll up/ts node/other conversion tools support typescript and custom converters that support typescript
25
45
  - The two are basically interchangeable (the details need to be adjusted)
26
46
 
27
47
  - Support the use of `inject` during construction
28
48
 
49
+ # No Decorator
50
+
51
+ - The original use of `@Injectable()` to pass parameters has been changed to `static injectOptions={}`. If there are no parameters, there is no need to set them
52
+ - Originally, `@Optional`, `@SkipSelf`, `@Self`, please use the second pass parameter of `inject` instead
53
+
29
54
  # Test
30
55
 
31
56
  - Partially conducted unit testing to ensure that most functions are functioning properly
32
57
  - Because most of the code itself is extracted from Angular, stability is definitely guaranteed
33
58
 
34
59
  # Sync
35
- - Currently, the synchronization logic has been refactored and modified using `@code recycle/cli` to ensure consistency with the official version of `angular`
36
60
 
37
- # Template
38
-
39
- - [Used under typescript (using Typescript Compiler API)](https://github.com/wszgrcy/static-injector-typescript-template)
40
- - [Used under webpack](https://github.com/wszgrcy/static-injector-webpack-template)
41
- - [Using Rollup](https://github.com/wszgrcy/static-injector-rollup-template)
61
+ - Currently, the synchronization logic has been refactored and modified using `@code recycle/cli` to ensure consistency with the official version of `angular`
@@ -74,10 +74,3 @@ export interface Injectable {
74
74
  */
75
75
  providedIn?: Type<any> | 'root' | 'platform' | 'any' | null;
76
76
  }
77
- /**
78
- * Injectable decorator and metadata.
79
- *
80
- * @Annotation
81
- * @publicApi
82
- */
83
- export declare const Injectable: InjectableDecorator;
@@ -9,4 +9,3 @@ export * from './di/injector';
9
9
  export * from './di/interface/injector';
10
10
  export * from './di/scope';
11
11
  export * from './render3/instructions/di';
12
- export * from './render3/di';
@@ -1,14 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Google LLC All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
- /**
9
- * Injectable decorator and metadata.
10
- *
11
- * @Annotation
12
- * @publicApi
13
- */
14
- export const Injectable = undefined;
@@ -1,19 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Google LLC All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
- /**
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 const ERROR_DETAILS_PAGE_BASE_URL = 'https://angular.io/errors';
16
- /**
17
- * URL for the XSS security documentation.
18
- */
19
- export const XSS_SECURITY_URL = 'https://g.co/ng/security#xss';
@@ -1,14 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Google LLC All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
- import { NG_FACTORY_DEF } from './fields';
9
- export function getFactoryDef(type, throwNotFound) {
10
- const hasFactoryDef = type.hasOwnProperty(NG_FACTORY_DEF);
11
- if (false) {
12
- }
13
- return hasFactoryDef ? type[NG_FACTORY_DEF] : null;
14
- }
@@ -1,49 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Google LLC All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
- import { isForwardRef, resolveForwardRef } from '../di/forward_ref';
9
- import { noSideEffects } from '../util/closure';
10
- import { getFactoryDef } from './definition_factory';
11
- import { NG_FACTORY_DEF } from './fields';
12
- /**
13
- * @codeGenApi
14
- */
15
- export function ɵɵgetInheritedFactory(type) {
16
- return noSideEffects(() => {
17
- const ownConstructor = type.prototype.constructor;
18
- const ownFactory = ownConstructor[NG_FACTORY_DEF] || getFactoryOf(ownConstructor);
19
- const objectPrototype = Object.prototype;
20
- let parent = Object.getPrototypeOf(type.prototype).constructor;
21
- // Go up the prototype until we hit `Object`.
22
- while (parent && parent !== objectPrototype) {
23
- const factory = parent[NG_FACTORY_DEF] || getFactoryOf(parent);
24
- // If we hit something that has a factory and the factory isn't the same as the type,
25
- // we've found the inherited factory. Note the check that the factory isn't the type's
26
- // own factory is redundant in most cases, but if the user has custom decorators on the
27
- // class, this lookup will start one level down in the prototype chain, causing us to
28
- // find the own factory first and potentially triggering an infinite loop downstream.
29
- if (factory && factory !== ownFactory) {
30
- return factory;
31
- }
32
- parent = Object.getPrototypeOf(parent);
33
- }
34
- // There is no factory defined. Either this was improper usage of inheritance
35
- // (no Angular decorator on the superclass) or there is no constructor at all
36
- // in the inheritance chain. Since the two cases cannot be distinguished, the
37
- // latter has to be assumed.
38
- return (t) => new t();
39
- });
40
- }
41
- function getFactoryOf(type) {
42
- if (isForwardRef(type)) {
43
- return () => {
44
- const factory = getFactoryOf(resolveForwardRef(type));
45
- return factory && factory();
46
- };
47
- }
48
- return getFactoryDef(type);
49
- }