diff --git a/spec/core/HNamespace.spec.ts b/spec/core/HNamespace.spec.ts index 6d7bc7f..616f7ae 100644 --- a/spec/core/HNamespace.spec.ts +++ b/spec/core/HNamespace.spec.ts @@ -1938,11 +1938,9 @@ describe('HNamespace', function (): void { }) }) // #getContainmentRefs() - describe('#findContainmentRefs()', function (): void { - it('returns a list of all the containment refs for a def', function (): void { - expect( - defs.findContainmentRefs('site').map((def) => def.defName) - ).toEqual(['siteRef']) + describe('#findContainmentRef()', function (): void { + it('returns the containment ref for a def', function (): void { + expect(defs.findContainmentRef('site')?.defName).toEqual('siteRef') }) - }) // #findContainmentRefs() + }) // #findContainmentRef() }) diff --git a/src/core/HNamespace.ts b/src/core/HNamespace.ts index 0fea3be..8823b1a 100644 --- a/src/core/HNamespace.ts +++ b/src/core/HNamespace.ts @@ -1659,18 +1659,18 @@ export class HNamespace { } /** - * Return all the containment refs for the specified def. + * Return the first containment ref def that matches the specified name. * * Please note, this will filter out any defs that are marked as deprecated. * * @param name The name of the def to search the ref for. - * @returns The containment defs. + * @returns The containment ref def. */ - public findContainmentRefs(name: string | HSymbol): HDict[] { + public findContainmentRef(name: string | HSymbol): HDict | undefined { return this.getContainmentRefs().filter( (def) => !def.has('deprecated') && this.fits(name, def.get('containedBy') as HSymbol) - ) + )[0] } } diff --git a/src/core/util.ts b/src/core/util.ts index 6b61f01..f6eda7a 100644 --- a/src/core/util.ts +++ b/src/core/util.ts @@ -573,13 +573,13 @@ export function addContainmentRefs( dict.set('spaceRef', spaceRef) } - const refName = namespace.findContainmentRefs( - namespace.reflect(parent).type.defName - )?.[0]?.defName + const refName = + namespace.findContainmentRef(namespace.reflect(parent).type.defName) + ?.defName ?? '' if (refName && !dict.has(refName)) { dict.set(refName, parent.get('id') as HRef) } - return refName ?? '' + return refName }