@@ -10,6 +10,7 @@ import DocElementParser from '../DocElementParser';
1010import ResolvedApiItem from '../ResolvedApiItem' ;
1111import ApiDefinitionReference ,
1212 { IScopedPackageName , IApiDefinintionReferenceParts } from '../ApiDefinitionReference' ;
13+ import ApiItemContainer from './ApiItemContainer' ;
1314
1415/**
1516 * Indicates the type of definition represented by a ApiItem object.
@@ -250,6 +251,8 @@ abstract class ApiItem {
250251 */
251252 private _state : InitializationState ;
252253
254+ private _parentContainer : ApiItemContainer | undefined ;
255+
253256 constructor ( options : IApiItemOptions ) {
254257 this . reportError = this . reportError . bind ( this ) ;
255258
@@ -280,6 +283,14 @@ abstract class ApiItem {
280283 ) ;
281284 }
282285
286+ public onAddToContainer ( parentContainer : ApiItemContainer ) : void {
287+ if ( this . _parentContainer ) {
288+ // This would indicate a program bug
289+ throw new Error ( 'The API item has already been added to another container: ' + this . _parentContainer . name ) ;
290+ }
291+ this . _parentContainer = parentContainer ;
292+ }
293+
283294 /**
284295 * Called after the constructor to finish the analysis.
285296 */
@@ -313,6 +324,13 @@ abstract class ApiItem {
313324 return true ;
314325 }
315326
327+ /**
328+ * The ApiItemContainer that this member belongs to, or undefined if there is none.
329+ */
330+ public get parentContainer ( ) : ApiItemContainer | undefined {
331+ return this . _parentContainer ;
332+ }
333+
316334 /**
317335 * This traverses any type aliases to find the original place where an item was defined.
318336 * For example, suppose a class is defined as "export default class MyClass { }"
0 commit comments