|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. |
| 2 | +// See LICENSE in the project root for license information. |
| 3 | + |
| 4 | +import * as tsdoc from '@microsoft/tsdoc'; |
| 5 | +import { ReleaseTag } from '@microsoft/api-extractor-model'; |
| 6 | +import { VisitorState } from './VisitorState'; |
| 7 | + |
| 8 | +/** |
| 9 | + * Constructor parameters for `ApiItemMetadata`. |
| 10 | + */ |
| 11 | +export interface IApiItemMetadataOptions { |
| 12 | + declaredReleaseTag: ReleaseTag; |
| 13 | + effectiveReleaseTag: ReleaseTag; |
| 14 | + releaseTagSameAsParent: boolean; |
| 15 | + isEventProperty: boolean; |
| 16 | + isOverride: boolean; |
| 17 | + isSealed: boolean; |
| 18 | + isVirtual: boolean; |
| 19 | + isPreapproved: boolean; |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * Stores the Collector's additional analysis for an `AstDeclaration`. This object is assigned to |
| 24 | + * `AstDeclaration.apiItemMetadata` but consumers must always obtain it by calling `Collector.fetchApiItemMetadata()`. |
| 25 | + * |
| 26 | + * @remarks |
| 27 | + * Note that ancillary declarations share their `ApiItemMetadata` with the main declaration, |
| 28 | + * whereas a separate `DeclarationMetadata` object is created for each declaration. |
| 29 | + * |
| 30 | + * Consider this example: |
| 31 | + * ```ts |
| 32 | + * export declare class A { |
| 33 | + * get b(): string; |
| 34 | + * set b(value: string); |
| 35 | + * } |
| 36 | + * export declare namespace A { } |
| 37 | + * ``` |
| 38 | + * |
| 39 | + * In this example, there are two "symbols": `A` and `b` |
| 40 | + * |
| 41 | + * There are four "declarations": `A` class, `A` namespace, `b` getter, `b` setter |
| 42 | + * |
| 43 | + * There are three "API items": `A` class, `A` namespace, `b` property. The property getter is the main declaration |
| 44 | + * for `b`, and the setter is the "ancillary" declaration. |
| 45 | + */ |
| 46 | +export class ApiItemMetadata { |
| 47 | + /** |
| 48 | + * This is the release tag that was explicitly specified in the original doc comment, if any. |
| 49 | + */ |
| 50 | + public readonly declaredReleaseTag: ReleaseTag; |
| 51 | + |
| 52 | + /** |
| 53 | + * The "effective" release tag is a normalized value that is based on `declaredReleaseTag`, |
| 54 | + * but may be inherited from a parent, or corrected if the declared value was somehow invalid. |
| 55 | + * When actually trimming .d.ts files or generating docs, API Extractor uses the "effective" value |
| 56 | + * instead of the "declared" value. |
| 57 | + */ |
| 58 | + public readonly effectiveReleaseTag: ReleaseTag; |
| 59 | + |
| 60 | + // If true, then it would be redundant to show this release tag |
| 61 | + public readonly releaseTagSameAsParent: boolean; |
| 62 | + |
| 63 | + // NOTE: In the future, the Collector may infer or error-correct some of these states. |
| 64 | + // Generators should rely on these instead of tsdocComment.modifierTagSet. |
| 65 | + public readonly isEventProperty: boolean; |
| 66 | + public readonly isOverride: boolean; |
| 67 | + public readonly isSealed: boolean; |
| 68 | + public readonly isVirtual: boolean; |
| 69 | + |
| 70 | + public readonly isPreapproved: boolean; |
| 71 | + |
| 72 | + /** |
| 73 | + * This is the TSDoc comment for the declaration. It may be modified (or constructed artificially) by |
| 74 | + * the DocCommentEnhancer. |
| 75 | + */ |
| 76 | + public tsdocComment: tsdoc.DocComment | undefined; |
| 77 | + |
| 78 | + // Assigned by DocCommentEnhancer |
| 79 | + public needsDocumentation: boolean = true; |
| 80 | + |
| 81 | + public docCommentEnhancerVisitorState: VisitorState = VisitorState.Unvisited; |
| 82 | + |
| 83 | + public constructor(options: IApiItemMetadataOptions) { |
| 84 | + this.declaredReleaseTag = options.declaredReleaseTag; |
| 85 | + this.effectiveReleaseTag = options.effectiveReleaseTag; |
| 86 | + this.releaseTagSameAsParent = options.releaseTagSameAsParent; |
| 87 | + this.isEventProperty = options.isEventProperty; |
| 88 | + this.isOverride = options.isOverride; |
| 89 | + this.isSealed = options.isSealed; |
| 90 | + this.isVirtual = options.isVirtual; |
| 91 | + this.isPreapproved = options.isPreapproved; |
| 92 | + } |
| 93 | +} |
0 commit comments