|
4 | 4 | import * as tsdoc from '@microsoft/tsdoc'; |
5 | 5 | import { ReleaseTag } from '@microsoft/api-extractor-model'; |
6 | 6 | import { VisitorState } from './VisitorState'; |
| 7 | +import { AstDeclaration } from '../analyzer/AstDeclaration'; |
| 8 | +import { InternalError } from '@microsoft/node-core-library'; |
7 | 9 |
|
8 | 10 | export class DeclarationMetadata { |
9 | 11 | /** |
@@ -47,4 +49,41 @@ export class DeclarationMetadata { |
47 | 49 | public releaseTagSameAsParent: boolean = false; |
48 | 50 |
|
49 | 51 | public docCommentEnhancerVisitorState: VisitorState = VisitorState.Unvisited; |
| 52 | + |
| 53 | + /** |
| 54 | + * If true, then this declaration is treated as part of another declaration. |
| 55 | + */ |
| 56 | + public isAncillary: boolean = false; |
| 57 | + |
| 58 | + /** |
| 59 | + * A list of other declarations that are treated as being part of this declaration. For example, a property |
| 60 | + * getter/setter pair will be treated as a single API item, with the setter being treated as ancillary to the getter. |
| 61 | + * |
| 62 | + * If the `ancillaryDeclarations` array is non-empty, then `isAncillary` will be false for this declaration, |
| 63 | + * and `isAncillary` will be true for all the array items. |
| 64 | + */ |
| 65 | + public ancillaryDeclarations: AstDeclaration[] = []; |
| 66 | + |
| 67 | + public addAncillaryDeclaration(otherDeclaration: AstDeclaration): void { |
| 68 | + const otherMetadata: DeclarationMetadata = otherDeclaration.metadata as DeclarationMetadata; |
| 69 | + |
| 70 | + if (!otherMetadata) { |
| 71 | + throw new InternalError('addAncillaryDeclaration() cannot be called before the declaration metadata is solved'); |
| 72 | + } |
| 73 | + |
| 74 | + if (this.ancillaryDeclarations.indexOf(otherDeclaration) >= 0) { |
| 75 | + return; // already added |
| 76 | + } |
| 77 | + |
| 78 | + if (this.isAncillary) { |
| 79 | + throw new InternalError('Invalid call to addAncillaryDeclaration() because the target is ancillary itself'); |
| 80 | + } |
| 81 | + |
| 82 | + if (otherMetadata.isAncillary) { |
| 83 | + throw new InternalError('Invalid call to addAncillaryDeclaration() because source is already ancillary to another declaration'); |
| 84 | + } |
| 85 | + |
| 86 | + otherMetadata.isAncillary = true; |
| 87 | + this.ancillaryDeclarations.push(otherDeclaration); |
| 88 | + } |
50 | 89 | } |
0 commit comments