Skip to content

Commit d06c5d4

Browse files
committed
Add ApiItem.parentContainer pointer
1 parent e19d8fa commit d06c5d4

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎libraries/api-extractor/src/definitions/ApiItem.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import DocElementParser from '../DocElementParser';
1010
import ResolvedApiItem from '../ResolvedApiItem';
1111
import 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 { }"

‎libraries/api-extractor/src/definitions/ApiItemContainer.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ abstract class ApiItemContainer extends ApiItem {
4242
} else {
4343
this.innerItems.push(apiItem);
4444
this._memberItems.set(apiItem.name, apiItem);
45+
apiItem.onAddToContainer(this);
4546
}
4647
}
4748

0 commit comments

Comments
 (0)