@lppedd/di-wise-neo 0.17.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,6 @@
1
+ type ClassDecorator<Class extends object> = (target: Constructor<Class>) => Constructor<Class> | void;
2
+ type ParameterDecorator = (target: object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
3
+
1
4
  declare const Scope: {
2
5
  /**
3
6
  * Creates a new value every time the token is resolved.
@@ -126,11 +129,8 @@ declare function createType<T>(typeName: string, provider: Provider<T>, options?
126
129
  interface ClassRef<Instance extends object> {
127
130
  readonly getRefClass: () => Constructor<Instance>;
128
131
  }
129
- interface TokensRef<Value> {
130
- readonly getRefTokens: () => Set<Token<Value>>;
131
- }
132
132
  interface TokenRef<Value> {
133
- readonly getRefToken: () => Token<Value>;
133
+ readonly getRefTokens: () => Set<Token<Value>>;
134
134
  }
135
135
  /**
136
136
  * Allows referencing a class declared later in the file by wrapping it
@@ -140,15 +140,12 @@ interface TokenRef<Value> {
140
140
  */
141
141
  declare function classRef<Instance extends object>(Class: () => Constructor<Instance>): ClassRef<Instance>;
142
142
  /**
143
- * Allows referencing tokens declared later in the file by wrapping them
144
- * in a lazily evaluated function.
145
- */
146
- declare function tokenRef<Value>(token: () => Tokens<Value>): TokensRef<Value>;
147
- /**
148
- * Allows referencing a token declared later in the file by wrapping it
149
- * in a lazily evaluated function.
143
+ * Allows referencing one or multiple tokens declared later in the file by wrapping them
144
+ * into a lazily evaluated function.
145
+ *
146
+ * @__NO_SIDE_EFFECTS__
150
147
  */
151
- declare function tokenRef<Value>(token: () => Token<Value>): TokenRef<Value>;
148
+ declare function tokenRef<Value>(token: () => Token<Value> | Tokens<Value>): TokenRef<Value>;
152
149
 
153
150
  /**
154
151
  * Provides a class instance for a token via a class constructor.
@@ -290,6 +287,13 @@ interface ContainerOptions {
290
287
  * @defaultValue false
291
288
  */
292
289
  readonly autoRegister: boolean;
290
+ /**
291
+ * Whether to also dispose values provided via {@link ValueProvider}, which are not
292
+ * created or managed by the container, when the container itself is disposed.
293
+ *
294
+ * @defaultValue false
295
+ */
296
+ readonly disposeUnmanaged: boolean;
293
297
  }
294
298
  /**
295
299
  * Child container creation options.
@@ -308,19 +312,20 @@ interface ChildContainerOptions extends ContainerOptions {
308
312
  interface ContainerHook {
309
313
  /**
310
314
  * Called when the container provides a value for a {@link Token}.
311
- * - For **Container** scoped tokens, it is called only once when the token is first resolved and cached.
312
- * - For **Resolution** scoped tokens, it is called once per token resolution graph.
313
- * - For **Transient** scoped tokens, it is called each time the token is resolved,
315
+ * - For **Container**-scoped tokens, it is called only once when the token is first resolved and cached.
316
+ * - For **Resolution**-scoped tokens, it is called once per token resolution graph.
317
+ * - For **Transient**-scoped tokens, it is called each time the token is resolved,
314
318
  * which might mean multiple times per resolution graph.
315
319
  *
316
- * @param value The provided value.
317
- * @param scope The {@link Scope} of the provided value.
320
+ * @param value - The provided value.
321
+ * @param scope - The {@link Scope} of the provided value.
318
322
  */
319
323
  readonly onProvide?: (value: unknown, scope: Scope) => void;
320
324
  /**
321
325
  * Called after the container has been disposed.
322
326
  *
323
- * @param values The values that were cached by the container.
327
+ * @param values - All distinct values that were cached by the disposed container.
328
+ * Currently, only **Container**-scoped token values are cached.
324
329
  */
325
330
  readonly onDispose?: (values: unknown[]) => void;
326
331
  }
@@ -347,10 +352,10 @@ interface Container {
347
352
  */
348
353
  createChild(options?: Partial<ChildContainerOptions>): Container;
349
354
  /**
350
- * Clears and returns all distinct cached values from this container's internal registry.
355
+ * Clears and returns all distinct values that were cached by this container.
351
356
  * Values from {@link ValueProvider} registrations are not included, as they are never cached.
352
357
  *
353
- * Note that only this container is affected. Parent containers, if any, remain unchanged.
358
+ * Note that only this container is affected. Parent or child containers, if any, remain unchanged.
354
359
  */
355
360
  clearCache(): unknown[];
356
361
  /**
@@ -380,10 +385,11 @@ interface Container {
380
385
  /**
381
386
  * Removes all registrations from this container's internal registry.
382
387
  *
383
- * Returns an array of distinct cached values that were stored within the removed registrations.
384
- * Values from {@link ValueProvider} registrations are not included, as they are not cached.
388
+ * Returns an array of the distinct values that were cached by this container for the
389
+ * removed registrations. Values from {@link ValueProvider} registrations are not included,
390
+ * as they are not cached.
385
391
  *
386
- * Note that only this container is affected. Parent containers, if any, remain unchanged.
392
+ * Note that only this container is affected. Parent or child containers, if any, remain unchanged.
387
393
  */
388
394
  resetRegistry(): unknown[];
389
395
  /**
@@ -432,10 +438,11 @@ interface Container {
432
438
  /**
433
439
  * Removes all registrations for the given token from the container's internal registry.
434
440
  *
435
- * Returns an array of distinct cached values that were stored within the removed registrations.
436
- * Values from {@link ValueProvider} registrations are not included, as they are not cached.
441
+ * Returns an array of the distinct values that were cached by this container for the
442
+ * removed registrations. Values from {@link ValueProvider} registrations are not included,
443
+ * as they are not cached.
437
444
  *
438
- * Note that only this container is affected. Parent containers, if any, remain unchanged.
445
+ * Note that only this container is affected. Parent or child containers, if any, remain unchanged.
439
446
  */
440
447
  unregister<Value>(token: Token<Value>, name?: string): Value[];
441
448
  /**
@@ -650,7 +657,7 @@ declare function createContainer(options?: Partial<ContainerOptions>): Container
650
657
  *
651
658
  * @__NO_SIDE_EFFECTS__
652
659
  */
653
- declare function AutoRegister(): ClassDecorator;
660
+ declare function AutoRegister<This extends object>(): ClassDecorator<This>;
654
661
 
655
662
  /**
656
663
  * Class decorator that sets the class scope to **Container** and enables
@@ -671,7 +678,7 @@ declare function AutoRegister(): ClassDecorator;
671
678
  *
672
679
  * @__NO_SIDE_EFFECTS__
673
680
  */
674
- declare function EagerInstantiate(): ClassDecorator;
681
+ declare function EagerInstantiate<This extends object>(): ClassDecorator<This>;
675
682
 
676
683
  /**
677
684
  * Parameter decorator that injects the instance associated with the given class.
@@ -725,7 +732,14 @@ declare function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;
725
732
  * class Wand {}
726
733
  * ```
727
734
  */
728
- declare function Injectable<This extends object, Value extends This>(...tokens: Tokens<Value>): ClassDecorator;
735
+ declare function Injectable<Value, This extends Value & object>(token: Token<Value>): ClassDecorator<This>;
736
+ declare function Injectable<VA, VB, This extends VA & VB & object>(tokenA: Token<VA>, //
737
+ tokenB: Token<VB>): ClassDecorator<This>;
738
+ declare function Injectable<VA, VB, VC, This extends VA & VB & VC & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>): ClassDecorator<This>;
739
+ declare function Injectable<VA, VB, VC, VD, This extends VA & VB & VC & VD & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>, tokenD: Token<VD>): ClassDecorator<This>;
740
+ declare function Injectable<VA, VB, VC, VD, VE, This extends VA & VB & VC & VD & VE & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>, tokenD: Token<VD>, tokenE: Token<VE>): ClassDecorator<This>;
741
+ declare function Injectable<VA, VB, VC, VD, VE, VF, This extends VA & VB & VC & VD & VE & VF & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>, tokenD: Token<VD>, tokenE: Token<VE>, tokenF: Token<VF>): ClassDecorator<This>;
742
+ declare function Injectable<This extends object>(...tokens: Tokens<unknown>): ClassDecorator<This>;
729
743
  /**
730
744
  * Class decorator that registers additional aliasing tokens for the decorated type
731
745
  * when the type is first registered in the container.
@@ -743,7 +757,7 @@ declare function Injectable<This extends object, Value extends This>(...tokens:
743
757
  * class Weapon {}
744
758
  * ```
745
759
  */
746
- declare function Injectable<This extends object, Value extends This>(tokens: TokenRef<Value> | TokensRef<Value>): ClassDecorator;
760
+ declare function Injectable<Value, This extends Value & object>(tokens: TokenRef<Value>): ClassDecorator<This>;
747
761
 
748
762
  /**
749
763
  * Parameter decorator that injects all instances provided by the registrations
@@ -803,7 +817,7 @@ declare function InjectAll<Value>(tokens: TokenRef<Value>): ParameterDecorator;
803
817
  *
804
818
  * @__NO_SIDE_EFFECTS__
805
819
  */
806
- declare function Named(name: string): ClassDecorator & ParameterDecorator;
820
+ declare function Named<This extends object>(name: string): ClassDecorator<This> & ParameterDecorator;
807
821
 
808
822
  /**
809
823
  * Parameter decorator that injects the instance associated with the given class,
@@ -901,7 +915,7 @@ declare function OptionalAll<Value>(tokens: TokenRef<Value>): ParameterDecorator
901
915
  *
902
916
  * @__NO_SIDE_EFFECTS__
903
917
  */
904
- declare function Scoped(scope: Scope): ClassDecorator;
918
+ declare function Scoped<This extends object>(scope: Scope): ClassDecorator<This>;
905
919
 
906
920
  /**
907
921
  * Injects the instance associated with the given class.
@@ -992,7 +1006,7 @@ declare function injectBy<Value>(thisArg: any, token: Token<Value>, name?: strin
992
1006
  * Asserts that the current stack frame is within an injection context,
993
1007
  * meaning it has access to injection functions (`inject`, `optional`, etc.).
994
1008
  *
995
- * @param fn The function performing the assertion, or a string name used in the error message.
1009
+ * @param fn - The function performing the assertion, or a string name used in the error message.
996
1010
  * @throws {Error} If the current stack frame is not within an injection context.
997
1011
  */
998
1012
  declare function assertInjectionContext(fn: Function | string): void;
@@ -1103,14 +1117,14 @@ declare const Injector: Type<Injector>;
1103
1117
  * This allows libraries or consumers that manipulate constructors, such as through
1104
1118
  * class decorators, to inform the DI system about the real "identity" of a class.
1105
1119
  *
1106
- * @param transformedClass - The constructor function returned by a class decorator or factory.
1107
- * @param originalClass - The original constructor function.
1108
- *
1109
- * @remarks
1110
- * This API affects the core class identity resolution mechanism of the DI system.
1120
+ * **IMPORTANT**:
1121
+ * this API affects the core class identity resolution mechanism of the DI system.
1111
1122
  * Incorrect usage may cause metadata to be misassociated, leading to subtle errors.
1112
1123
  * Use only when manipulating constructors (e.g., via decorators or proxies),
1113
1124
  * and ensure the mapping is correct.
1125
+ *
1126
+ * @param transformedClass - The constructor function returned by a class decorator or factory.
1127
+ * @param originalClass - The original constructor function.
1114
1128
  */
1115
1129
  declare function setClassIdentityMapping<T extends object>(transformedClass: Constructor<T>, originalClass: Constructor<T>): void;
1116
1130
 
@@ -1172,4 +1186,4 @@ declare function optionalBy<Instance extends object>(thisArg: any, Class: Constr
1172
1186
  declare function optionalBy<Value>(thisArg: any, token: Token<Value>, name?: string): Value | undefined;
1173
1187
 
1174
1188
  export { AutoRegister, EagerInstantiate, Inject, InjectAll, Injectable, Injector, Named, Optional, OptionalAll, Scope, Scoped, assertInjectionContext, build, classRef, createContainer, createType, inject, injectAll, injectBy, optional, optionalAll, optionalBy, setClassIdentityMapping, tokenRef };
1175
- export type { ChildContainerOptions, ClassProvider, ClassRef, Constructor, Container, ContainerHook, ContainerOptions, ExistingProvider, FactoryProvider, Provider, ProviderType, RegistrationOptions, Token, TokenRef, Tokens, TokensRef, Type, ValueProvider };
1189
+ export type { ChildContainerOptions, ClassProvider, ClassRef, Constructor, Container, ContainerHook, ContainerOptions, ExistingProvider, FactoryProvider, Provider, ProviderType, RegistrationOptions, Token, TokenRef, Tokens, Type, ValueProvider };
package/dist/es/index.mjs CHANGED
@@ -31,8 +31,9 @@ function throwResolutionError(tokenInfo, aliases, cause) {
31
31
  // @internal
32
32
  function throwParameterResolutionError(ctor, methodKey, dependency, cause) {
33
33
  const location = getLocation(ctor, methodKey);
34
+ const [token] = dependency.tokenRef.getRefTokens();
34
35
  const tokenName = getFullTokenName([
35
- dependency.tokenRef?.getRefToken(),
36
+ token,
36
37
  dependency.name
37
38
  ]);
38
39
  const msg = tag(`failed to resolve dependency for ${location}(parameter #${dependency.index}: ${tokenName})`);
@@ -165,7 +166,7 @@ function ensureInjectionContext(name) {
165
166
  * Asserts that the current stack frame is within an injection context,
166
167
  * meaning it has access to injection functions (`inject`, `optional`, etc.).
167
168
  *
168
- * @param fn The function performing the assertion, or a string name used in the error message.
169
+ * @param fn - The function performing the assertion, or a string name used in the error message.
169
170
  * @throws {Error} If the current stack frame is not within an injection context.
170
171
  */ function assertInjectionContext(fn) {
171
172
  const name = typeof fn === "function" ? `${fn.name || "<unnamed>"}()` : fn;
@@ -224,8 +225,12 @@ function injectBy(thisArg, token, name) {
224
225
  getRefClass: ()=>Class()
225
226
  };
226
227
  }
227
- // @__NO_SIDE_EFFECTS__
228
- function tokenRef(token) {
228
+ /**
229
+ * Allows referencing one or multiple tokens declared later in the file by wrapping them
230
+ * into a lazily evaluated function.
231
+ *
232
+ * @__NO_SIDE_EFFECTS__
233
+ */ function tokenRef(token) {
229
234
  return {
230
235
  getRefTokens: ()=>{
231
236
  // Normalize the single token here so that we don't have to do it at every getRefTokens call site
@@ -234,11 +239,6 @@ function tokenRef(token) {
234
239
  tokenOrTokens
235
240
  ];
236
241
  return new Set(tokensArray);
237
- },
238
- getRefToken: ()=>{
239
- const tokenOrTokens = token();
240
- check(!Array.isArray(tokenOrTokens), "internal error: ref tokens should be a single token");
241
- return tokenOrTokens;
242
242
  }
243
243
  };
244
244
  }
@@ -247,12 +247,8 @@ function isClassRef(value) {
247
247
  return value != null && typeof value === "object" && typeof value.getRefClass === "function";
248
248
  }
249
249
  // @internal
250
- function isTokensRef(value) {
251
- return value != null && typeof value === "object" && typeof value.getRefTokens === "function";
252
- }
253
- // @internal
254
250
  function isTokenRef(value) {
255
- return value != null && typeof value === "object" && typeof value.getRefToken === "function";
251
+ return value != null && typeof value === "object" && typeof value.getRefTokens === "function";
256
252
  }
257
253
 
258
254
  // @internal
@@ -262,7 +258,7 @@ class Metadata {
262
258
  ctor: [],
263
259
  methods: new Map()
264
260
  };
265
- this.tokensRef = {
261
+ this.tokenRef = {
266
262
  getRefTokens: ()=>new Set()
267
263
  };
268
264
  this.provider = {
@@ -333,14 +329,14 @@ function getMetadata(classOrRef) {
333
329
  * This allows libraries or consumers that manipulate constructors, such as through
334
330
  * class decorators, to inform the DI system about the real "identity" of a class.
335
331
  *
336
- * @param transformedClass - The constructor function returned by a class decorator or factory.
337
- * @param originalClass - The original constructor function.
338
- *
339
- * @remarks
340
- * This API affects the core class identity resolution mechanism of the DI system.
332
+ * **IMPORTANT**:
333
+ * this API affects the core class identity resolution mechanism of the DI system.
341
334
  * Incorrect usage may cause metadata to be misassociated, leading to subtle errors.
342
335
  * Use only when manipulating constructors (e.g., via decorators or proxies),
343
336
  * and ensure the mapping is correct.
337
+ *
338
+ * @param transformedClass - The constructor function returned by a class decorator or factory.
339
+ * @param originalClass - The original constructor function.
344
340
  */ function setClassIdentityMapping(transformedClass, originalClass) {
345
341
  classIdentityMap.set(transformedClass, originalClass);
346
342
  }
@@ -554,16 +550,12 @@ class TokenRegistry {
554
550
  clearCache() {
555
551
  const values = new Set();
556
552
  for (const registrations of this.myRegistrations.values()){
557
- for(let i = 0; i < registrations.length; i++){
558
- const registration = registrations[i];
559
- const value = registration.value;
560
- if (value) {
561
- values.add(value.current);
553
+ for (const registration of registrations){
554
+ const valueRef = registration.valueRef;
555
+ if (valueRef) {
556
+ values.add(valueRef.current);
562
557
  }
563
- registrations[i] = {
564
- ...registration,
565
- value: undefined
566
- };
558
+ registration.valueRef = undefined;
567
559
  }
568
560
  }
569
561
  return Array.from(values);
@@ -614,9 +606,11 @@ function isDisposable(value) {
614
606
  this.myParent = parent;
615
607
  this.myOptions = {
616
608
  defaultScope: options?.defaultScope ?? "Transient",
617
- autoRegister: options?.autoRegister ?? false
609
+ autoRegister: options?.autoRegister ?? false,
610
+ disposeUnmanaged: options?.disposeUnmanaged ?? false
618
611
  };
619
- this.myHookRegistry = new HookRegistry(parent?.myHookRegistry);
612
+ const copyHooks = options?.copyHooks ?? true;
613
+ this.myHookRegistry = new HookRegistry(copyHooks ? parent?.myHookRegistry : undefined);
620
614
  this.myTokenRegistry = new TokenRegistry(parent?.myTokenRegistry);
621
615
  }
622
616
  get registry() {
@@ -637,7 +631,9 @@ function isDisposable(value) {
637
631
  this.checkDisposed();
638
632
  const container = new ContainerImpl(this, {
639
633
  defaultScope: options?.defaultScope ?? this.myOptions.defaultScope,
640
- autoRegister: options?.autoRegister ?? this.myOptions.autoRegister
634
+ autoRegister: options?.autoRegister ?? this.myOptions.autoRegister,
635
+ disposeUnmanaged: options?.disposeUnmanaged ?? this.myOptions.disposeUnmanaged,
636
+ copyHooks: options?.copyHooks
641
637
  });
642
638
  this.myChildren.add(container);
643
639
  return container;
@@ -649,16 +645,15 @@ function isDisposable(value) {
649
645
  getCached(token) {
650
646
  this.checkDisposed();
651
647
  const registration = this.myTokenRegistry.get(token);
652
- return registration?.value?.current;
648
+ return registration?.valueRef?.current;
653
649
  }
654
650
  getAllCached(token) {
655
651
  this.checkDisposed();
656
652
  const registrations = this.myTokenRegistry.getAll(token);
657
653
  const values = new Set();
658
- for (const registration of registrations){
659
- const value = registration.value;
660
- if (value) {
661
- values.add(value.current);
654
+ for (const { valueRef } of registrations){
655
+ if (valueRef) {
656
+ values.add(valueRef.current);
662
657
  }
663
658
  }
664
659
  return Array.from(values);
@@ -667,10 +662,9 @@ function isDisposable(value) {
667
662
  this.checkDisposed();
668
663
  const [, registrations] = this.myTokenRegistry.deleteAll();
669
664
  const values = new Set();
670
- for (const registration of registrations){
671
- const value = registration.value;
672
- if (value) {
673
- values.add(value.current);
665
+ for (const { valueRef } of registrations){
666
+ if (valueRef) {
667
+ values.add(valueRef.current);
674
668
  }
675
669
  }
676
670
  return Array.from(values);
@@ -697,10 +691,9 @@ function isDisposable(value) {
697
691
  this.checkDisposed();
698
692
  const registrations = this.myTokenRegistry.delete(token, name);
699
693
  const values = new Set();
700
- for (const registration of registrations){
701
- const value = registration.value;
702
- if (value) {
703
- values.add(value.current);
694
+ for (const { valueRef } of registrations){
695
+ if (valueRef) {
696
+ values.add(valueRef.current);
704
697
  }
705
698
  }
706
699
  return Array.from(values);
@@ -739,18 +732,23 @@ function isDisposable(value) {
739
732
  this.myChildren.clear();
740
733
  this.myParent?.myChildren?.delete(this);
741
734
  const [, registrations] = this.myTokenRegistry.deleteAll();
742
- const values = new Set();
743
- for (const registration of registrations){
744
- // Only container-scoped registrations use 'registration.value'
745
- if (registration.value) {
746
- const value = registration.value.current;
747
- // Dispose all cached values that implement the Disposable interface
748
- if (!values.has(value) && values.add(value) && isDisposable(value)) {
749
- value.dispose();
750
- }
735
+ const disposeUnmanaged = this.myOptions.disposeUnmanaged;
736
+ const cacheValues = new Set();
737
+ const allValues = new Set();
738
+ for (const { provider, valueRef } of registrations){
739
+ if (valueRef) {
740
+ cacheValues.add(valueRef.current);
741
+ allValues.add(valueRef.current);
742
+ } else if (disposeUnmanaged && isValueProvider(provider)) {
743
+ allValues.add(provider.useValue);
744
+ }
745
+ }
746
+ for (const value of allValues){
747
+ if (isDisposable(value)) {
748
+ value.dispose();
751
749
  }
752
750
  }
753
- this.notifyDisposeHooks(Array.from(values));
751
+ this.notifyDisposeHooks(Array.from(cacheValues));
754
752
  this.myHookRegistry.clear();
755
753
  }
756
754
  registerClass(Class) {
@@ -769,7 +767,7 @@ function isDisposable(value) {
769
767
  this.myTokenRegistry.put(Class, registration);
770
768
  // Register the additional tokens specified via class decorators.
771
769
  // These tokens will point to the original Class token and will have the same scope.
772
- for (const token of metadata.tokensRef.getRefTokens()){
770
+ for (const token of metadata.tokenRef.getRefTokens()){
773
771
  this.myTokenRegistry.put(token, {
774
772
  name: name,
775
773
  provider: {
@@ -960,13 +958,13 @@ function isDisposable(value) {
960
958
  switch(scope){
961
959
  case "Container":
962
960
  {
963
- const valueRef = registration.value;
961
+ const valueRef = registration.valueRef;
964
962
  if (valueRef) {
965
963
  return valueRef.current;
966
964
  }
967
965
  const args = this.resolveCtorDependencies(registration);
968
966
  const value = this.injectMethodDependencies(registration, factory(args));
969
- registration.value = {
967
+ registration.valueRef = {
970
968
  current: value
971
969
  };
972
970
  this.notifyProvideHooks(value, scope);
@@ -1055,7 +1053,7 @@ function isDisposable(value) {
1055
1053
  }
1056
1054
  // Call context: decorator-based injection
1057
1055
  resolveDependency(dependency, instance) {
1058
- const token = dependency.tokenRef?.getRefToken();
1056
+ const [token] = dependency.tokenRef.getRefTokens();
1059
1057
  check(token, `token passed to @${dependency.appliedBy} was undefined (possible circular imports)`);
1060
1058
  const name = dependency.name;
1061
1059
  switch(dependency.appliedBy){
@@ -1131,12 +1129,11 @@ function isDisposable(value) {
1131
1129
  * @__NO_SIDE_EFFECTS__
1132
1130
  */ function EagerInstantiate() {
1133
1131
  return function(Class) {
1134
- const ctor = Class;
1135
- const metadata = getMetadata(ctor);
1132
+ const metadata = getMetadata(Class);
1136
1133
  const currentScope = metadata.scope;
1137
1134
  check(!currentScope || currentScope.value === "Container", ()=>{
1138
1135
  const { value, appliedBy } = currentScope;
1139
- const className = getTokenName(ctor);
1136
+ const className = getTokenName(Class);
1140
1137
  return `class ${className}: scope ${value} was already set by @${appliedBy},\n ` + `but @EagerInstantiate is trying to set a conflicting scope Container.\n ` + `Only one decorator should set the class scope, or all must agree on the same value.`;
1141
1138
  });
1142
1139
  metadata.eagerInstantiate = true;
@@ -1163,12 +1160,12 @@ function Injectable(...args) {
1163
1160
  return function(Class) {
1164
1161
  const metadata = getMetadata(Class);
1165
1162
  const arg0 = args[0];
1166
- const tokensRef = isTokensRef(arg0) ? arg0 : tokenRef(()=>args);
1167
- const existingTokensRef = metadata.tokensRef;
1168
- metadata.tokensRef = {
1163
+ const ref = isTokenRef(arg0) ? arg0 : tokenRef(()=>args);
1164
+ const existingTokensRef = metadata.tokenRef;
1165
+ metadata.tokenRef = {
1169
1166
  getRefTokens: ()=>{
1170
1167
  const existingTokens = existingTokensRef.getRefTokens();
1171
- for (const token of tokensRef.getRefTokens()){
1168
+ for (const token of ref.getRefTokens()){
1172
1169
  existingTokens.add(token);
1173
1170
  }
1174
1171
  return existingTokens;
@@ -1211,9 +1208,9 @@ function InjectAll(token) {
1211
1208
  return function(target, propertyKey, parameterIndex) {
1212
1209
  if (parameterIndex === undefined) {
1213
1210
  // The decorator has been applied to the class
1214
- const ctor = target;
1215
- const metadata = getMetadata(ctor);
1216
- const className = getTokenName(ctor);
1211
+ const Class = target;
1212
+ const metadata = getMetadata(Class);
1213
+ const className = getTokenName(Class);
1217
1214
  check(metadata.name === undefined, `multiple @Named decorators on class ${className}, but only one is allowed`);
1218
1215
  metadata.name = name;
1219
1216
  } else {
@@ -1276,13 +1273,12 @@ function OptionalAll(token) {
1276
1273
  * @__NO_SIDE_EFFECTS__
1277
1274
  */ function Scoped(scope) {
1278
1275
  return function(Class) {
1279
- const ctor = Class;
1280
- const metadata = getMetadata(ctor);
1276
+ const metadata = getMetadata(Class);
1281
1277
  const currentScope = metadata.scope;
1282
1278
  check(!currentScope || currentScope.value === scope, ()=>{
1283
1279
  const { value, appliedBy } = currentScope;
1284
1280
  const by = appliedBy === "Scoped" ? `another @${appliedBy} decorator` : `@${appliedBy}`;
1285
- const className = getTokenName(ctor);
1281
+ const className = getTokenName(Class);
1286
1282
  return `class ${className}: scope ${value} was already set by ${by},\n ` + `but @Scoped is trying to set a conflicting scope ${scope}.\n ` + `Only one decorator should set the class scope, or all must agree on the same value.`;
1287
1283
  });
1288
1284
  metadata.scope = {