diff --git a/packages/context/src/binding-filter.ts b/packages/context/src/binding-filter.ts index 8fd7d0868061..200a2cbaa1a5 100644 --- a/packages/context/src/binding-filter.ts +++ b/packages/context/src/binding-filter.ts @@ -4,7 +4,7 @@ // License text available at https://opensource.org/licenses/MIT import {Binding, BindingTag} from './binding'; -import {BindingAddress} from './binding-key'; +import {BindingAddress, BindingKey} from './binding-key'; import {MapObject} from './value-promise'; /** @@ -52,12 +52,14 @@ export type BindingSelector = /** * Type guard for binding address - * @param bindingSelector + * @param bindingSelector - Binding key or filter function */ export function isBindingAddress( bindingSelector: BindingSelector, ): bindingSelector is BindingAddress { - return typeof bindingSelector !== 'function'; + return ( + typeof bindingSelector === 'string' || bindingSelector instanceof BindingKey + ); } /** diff --git a/packages/context/src/binding.ts b/packages/context/src/binding.ts index 4671849feddd..ff2931789f0c 100644 --- a/packages/context/src/binding.ts +++ b/packages/context/src/binding.ts @@ -210,6 +210,7 @@ export class Binding extends EventEmitter { private _valueConstructor?: Constructor; private _providerConstructor?: Constructor>; + private _alias?: BindingAddress; /** * For bindings bound via `toClass()`, this property contains the constructor @@ -595,6 +596,7 @@ export class Binding extends EventEmitter { debug('Bind %s to alias %s', this.key, keyWithPath); } this._type = BindingType.ALIAS; + this._alias = keyWithPath; this._setValueGetter((ctx, options) => { return ctx.getValueOrPromise(keyWithPath, options); }); @@ -649,6 +651,9 @@ export class Binding extends EventEmitter { if (this._providerConstructor != null) { json.providerConstructor = this._providerConstructor.name; } + if (this._alias != null) { + json.alias = this._alias.toString(); + } return json; } diff --git a/packages/context/src/resolution-session.ts b/packages/context/src/resolution-session.ts index 0527d91cb970..01feea51f585 100644 --- a/packages/context/src/resolution-session.ts +++ b/packages/context/src/resolution-session.ts @@ -155,9 +155,7 @@ export class ResolutionSession { * Describe the injection for debugging purpose * @param injection - Injection object */ - static describeInjection(injection?: Readonly) { - /* istanbul ignore if */ - if (injection == null) return {}; + static describeInjection(injection: Readonly) { const name = getTargetName( injection.target, injection.member, @@ -166,8 +164,7 @@ export class ResolutionSession { return { targetName: name, bindingSelector: injection.bindingSelector, - // Cast to Object so that we don't have to expose InjectionMetadata - metadata: injection.metadata as object, + metadata: injection.metadata, }; } @@ -300,14 +297,14 @@ export class ResolutionSession { */ getInjectionPath() { return this.injectionStack - .map(i => ResolutionSession.describeInjection(i)!.targetName) + .map(i => ResolutionSession.describeInjection(i).targetName) .join(' --> '); } private static describe(e: ResolutionElement) { switch (e.type) { case 'injection': - return '@' + ResolutionSession.describeInjection(e.value)!.targetName; + return '@' + ResolutionSession.describeInjection(e.value).targetName; case 'binding': return e.value.key; }