@lppedd/di-wise-neo 0.9.3 → 0.9.4

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
@@ -25,8 +25,8 @@ function throwExistingUnregisteredError(token, cause) {
25
25
  // @internal
26
26
  function throwParameterResolutionError(ctor, methodKey, dependency, cause) {
27
27
  const location = getLocation(ctor, methodKey);
28
- const token = dependency.tokenRef.getRefToken();
29
- const message = tag(`failed to resolve dependency for ${location}(parameter #${dependency.index}: ${token.name})`);
28
+ const tokenName = getTokenName(dependency.tokenRef.getRefToken());
29
+ const message = tag(`failed to resolve dependency for ${location}(parameter #${dependency.index}: ${tokenName})`);
30
30
  throw new Error(`${message}\n [cause] ${untag(cause.message)}`, {
31
31
  cause
32
32
  });
@@ -375,11 +375,14 @@ class TokenRegistry {
375
375
  set(token, registration) {
376
376
  check(!internals.has(token), `cannot register reserved token ${token.name}`);
377
377
  let registrations = this.myMap.get(token);
378
- if (!registrations) {
378
+ if (registrations) {
379
+ const name = registration.name;
380
+ if (name !== undefined) {
381
+ const existing = registrations.filter((r)=>r.name === name);
382
+ check(existing.length === 0, `token ${getTokenName(token)} with name '${name}' is already registered`);
383
+ }
384
+ } else {
379
385
  this.myMap.set(token, registrations = []);
380
- } else if (registration.name !== undefined) {
381
- const existing = registrations.filter((r)=>r.name === registration.name);
382
- check(existing.length === 0, `a ${token.name} token named '${registration.name}' is already registered`);
383
386
  }
384
387
  registrations.push(registration);
385
388
  }
@@ -594,7 +597,7 @@ function isDisposable(value) {
594
597
  }
595
598
  } else {
596
599
  if (existingProvider) {
597
- check(token !== provider.useExisting, `the useExisting token ${token.name} cannot be the same as the token being registered`);
600
+ check(token !== provider.useExisting, `token ${getTokenName(token)} cannot alias itself via useExisting`);
598
601
  }
599
602
  this.myTokenRegistry.set(token, {
600
603
  name: name,
@@ -745,8 +748,8 @@ function isDisposable(value) {
745
748
  if (resolution.stack.has(provider)) {
746
749
  const dependentRef = resolution.dependents.get(provider);
747
750
  check(dependentRef, ()=>{
748
- const path = resolution.tokenStack.map((t)=>t.name).join(" → ");
749
- return `circular dependency detected while resolving ${path} → ${token.name}`;
751
+ const path = resolution.tokenStack.map(getTokenName).join(" → ");
752
+ return `circular dependency detected while resolving ${path} → ${getTokenName(token)}`;
750
753
  });
751
754
  return dependentRef.current;
752
755
  }