@lppedd/di-wise-neo 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -82,7 +82,7 @@ class KeyedStack {
82
82
  };
83
83
  }
84
84
  constructor(){
85
- this.myEntries = new Array();
85
+ this.myEntries = [];
86
86
  this.myKeys = new WeakSet();
87
87
  }
88
88
  }
@@ -115,6 +115,7 @@ class WeakRefMap {
115
115
  // @internal
116
116
  function createResolution() {
117
117
  return {
118
+ tokenStack: [],
118
119
  stack: new KeyedStack(),
119
120
  values: new WeakRefMap(),
120
121
  dependents: new WeakRefMap()
@@ -550,7 +551,7 @@ function isDisposable(value) {
550
551
  }
551
552
  // Eager-instantiate only if the class is container-scoped
552
553
  if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {
553
- this.resolveProviderValue(registration, registration.provider);
554
+ this.resolveProviderValue(Class, registration);
554
555
  }
555
556
  } else {
556
557
  const [token, provider, options] = args;
@@ -573,7 +574,7 @@ function isDisposable(value) {
573
574
  this.myTokenRegistry.set(token, registration);
574
575
  // Eager-instantiate only if the provided class is container-scoped
575
576
  if (metadata.eagerInstantiate && registration.options?.scope === Scope.Container) {
576
- this.resolveProviderValue(registration, registration.provider);
577
+ this.resolveProviderValue(token, registration);
577
578
  }
578
579
  } else {
579
580
  if (existingProvider) {
@@ -663,17 +664,15 @@ function isDisposable(value) {
663
664
  }
664
665
  resolveRegistration(token, registration, name) {
665
666
  let currRegistration = registration;
666
- let currProvider = currRegistration.provider;
667
- while(isExistingProvider(currProvider)){
668
- const targetToken = currProvider.useExisting;
667
+ while(isExistingProvider(currRegistration.provider)){
668
+ const targetToken = currRegistration.provider.useExisting;
669
669
  currRegistration = this.myTokenRegistry.get(targetToken, name);
670
670
  if (!currRegistration) {
671
671
  throwExistingUnregisteredError(token, targetToken);
672
672
  }
673
- currProvider = currRegistration.provider;
674
673
  }
675
674
  try {
676
- return this.resolveProviderValue(currRegistration, currProvider);
675
+ return this.resolveProviderValue(token, currRegistration);
677
676
  } catch (e) {
678
677
  // If we were trying to resolve a token registered via ExistingProvider,
679
678
  // we must add the cause of the error to the message
@@ -700,16 +699,16 @@ function isDisposable(value) {
700
699
  }
701
700
  return undefined;
702
701
  }
703
- resolveProviderValue(registration, provider) {
704
- check(registration.provider === provider, "internal error: mismatching provider");
702
+ resolveProviderValue(token, registration) {
703
+ const provider = registration.provider;
705
704
  if (isClassProvider(provider)) {
706
705
  const Class = provider.useClass;
707
706
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
708
- return this.resolveScopedValue(registration, (args)=>new Class(...args));
707
+ return this.resolveScopedValue(token, registration, (args)=>new Class(...args));
709
708
  }
710
709
  if (isFactoryProvider(provider)) {
711
710
  const factory = provider.useFactory;
712
- return this.resolveScopedValue(registration, factory);
711
+ return this.resolveScopedValue(token, registration, factory);
713
712
  }
714
713
  if (isValueProvider(provider)) {
715
714
  return provider.useValue;
@@ -717,7 +716,7 @@ function isDisposable(value) {
717
716
  check(!isExistingProvider(provider), "internal error: unexpected ExistingProvider");
718
717
  expectNever(provider);
719
718
  }
720
- resolveScopedValue(registration, factory) {
719
+ resolveScopedValue(token, registration, factory) {
721
720
  let context = useInjectionContext();
722
721
  if (!context || context.container !== this) {
723
722
  context = {
@@ -730,12 +729,16 @@ function isDisposable(value) {
730
729
  const options = registration.options;
731
730
  if (resolution.stack.has(provider)) {
732
731
  const dependentRef = resolution.dependents.get(provider);
733
- check(dependentRef, "circular dependency detected");
732
+ check(dependentRef, ()=>{
733
+ const tokenStack = resolution.tokenStack.map((t)=>t.name).concat(token.name).join(" → ");
734
+ return `circular dependency detected while resolving ${tokenStack}`;
735
+ });
734
736
  return dependentRef.current;
735
737
  }
736
738
  const scope = this.resolveScope(options?.scope, context);
737
739
  const cleanups = [
738
740
  provideInjectionContext(context),
741
+ resolution.tokenStack.push(token) && (()=>resolution.tokenStack.pop()),
739
742
  !isBuilder(provider) && resolution.stack.push(provider, {
740
743
  provider,
741
744
  scope