11// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22// See LICENSE in the project root for license information.
33
4+ import { DeclarationReference } from '@microsoft/tsdoc/lib/beta/DeclarationReference' ;
45import { Constructor , PropertiesOf } from '../mixins/Mixin' ;
56import { ApiPackage } from '../model/ApiPackage' ;
67import { ApiParameterListMixin } from '../mixins/ApiParameterListMixin' ;
78import { DeserializerContext } from '../model/DeserializerContext' ;
9+ import { InternalError } from '@microsoft/node-core-library' ;
810
911/**
1012 * The type returned by the {@link ApiItem.kind} property, which can be used to easily distinguish subclasses of
@@ -46,12 +48,10 @@ export interface IApiItemJson {
4648 kind : ApiItemKind ;
4749}
4850
49- /**
50- * PRIVATE
51- * Allows ApiItemContainerMixin to assign the parent.
52- */
51+ // PRIVATE - Allows ApiItemContainerMixin to assign the parent.
52+ //
5353// tslint:disable-next-line:variable-name
54- export const ApiItem_parent : unique symbol = Symbol ( 'ApiItem._parent ' ) ;
54+ export const ApiItem_setParent : unique symbol = Symbol ( 'ApiItem._setParent ' ) ;
5555
5656/**
5757 * The abstract base class for all members of an `ApiModel` object.
@@ -62,7 +62,8 @@ export const ApiItem_parent: unique symbol = Symbol('ApiItem._parent');
6262 * @public
6363 */
6464export class ApiItem {
65- public [ ApiItem_parent ] : ApiItem | undefined ;
65+ private _canonicalReference : DeclarationReference | undefined ;
66+ private _parent : ApiItem | undefined ;
6667
6768 public static deserialize ( jsonObject : IApiItemJson , context : DeserializerContext ) : ApiItem {
6869 // The Deserializer class is coupled with a ton of other classes, so we delay loading it
@@ -94,6 +95,22 @@ export class ApiItem {
9495 throw new Error ( 'ApiItem.kind was not implemented by the child class' ) ;
9596 }
9697
98+ /**
99+ * Warning: This API is used internally by API extractor but is not yet ready for general usage.
100+ *
101+ * @remarks
102+ *
103+ * Returns a `DeclarationReference` object using the experimental new declaration reference notation.
104+ *
105+ * @beta
106+ */
107+ public get canonicalReference ( ) : DeclarationReference {
108+ if ( ! this . _canonicalReference ) {
109+ this . _canonicalReference = this . buildCanonicalReference ( ) ;
110+ }
111+ return this . _canonicalReference ;
112+ }
113+
97114 /**
98115 * Returns a string key that can be used to efficiently retrieve an `ApiItem` from an `ApiItemContainerMixin`.
99116 * The key is unique within the container. Its format is undocumented and may change at any time.
@@ -105,7 +122,7 @@ export class ApiItem {
105122 * @virtual
106123 */
107124 public get containerKey ( ) : string {
108- throw new Error ( 'ApiItem.containerKey was not implemented by the child class' ) ;
125+ throw new InternalError ( 'ApiItem.containerKey was not implemented by the child class' ) ;
109126 }
110127
111128 /**
@@ -135,7 +152,7 @@ export class ApiItem {
135152 * @virtual
136153 */
137154 public get parent ( ) : ApiItem | undefined {
138- return this [ ApiItem_parent ] ;
155+ return this . _parent ;
139156 }
140157
141158 /**
@@ -215,6 +232,27 @@ export class ApiItem {
215232 public getSortKey ( ) : string {
216233 return this . containerKey ;
217234 }
235+
236+ /**
237+ * PRIVATE
238+ *
239+ * @privateRemarks
240+ * Allows ApiItemContainerMixin to assign the parent.
241+ *
242+ * @internal
243+ */
244+ public [ ApiItem_setParent ] ( parent : ApiItem | undefined ) : void {
245+ this . _parent = parent ;
246+ this . _canonicalReference = undefined ;
247+ }
248+
249+ /**
250+ * Builds the cached object used by the `canonicalReference` property.
251+ * @virtual
252+ */
253+ protected buildCanonicalReference ( ) : DeclarationReference {
254+ throw new InternalError ( 'ApiItem.canonicalReference was not implemented by the child class' ) ;
255+ }
218256}
219257
220258/**
0 commit comments