File size: 3,503 Bytes
31248b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { DocNode, DocNodeKind } from './DocNode';
import { DocSection } from './DocSection';
import { StandardModifierTagSet } from '../details/StandardModifierTagSet';
import { StringBuilder } from '../emitters/StringBuilder';
import { TSDocEmitter } from '../emitters/TSDocEmitter';
import { DocParamCollection } from './DocParamCollection';
/**
 * Represents an entire documentation comment conforming to the TSDoc structure.
 * This is the root of the DocNode tree.
 */
export class DocComment extends DocNode {
    /**
     * Don't call this directly.  Instead use {@link TSDocParser}
     * @internal
     */
    constructor(parameters) {
        super(parameters);
        this.summarySection = new DocSection({ configuration: this.configuration });
        this.remarksBlock = undefined;
        this.privateRemarks = undefined;
        this.deprecatedBlock = undefined;
        this.params = new DocParamCollection({ configuration: this.configuration });
        this.typeParams = new DocParamCollection({ configuration: this.configuration });
        this.returnsBlock = undefined;
        this.modifierTagSet = new StandardModifierTagSet();
        this._seeBlocks = [];
        this._customBlocks = [];
    }
    /** @override */
    get kind() {
        return DocNodeKind.Comment;
    }
    /**
     * The collection of all `@see` DockBlockTag nodes belonging to this doc comment.
     */
    get seeBlocks() {
        return this._seeBlocks;
    }
    /**
     * The collection of all DocBlock nodes belonging to this doc comment.
     */
    get customBlocks() {
        return this._customBlocks;
    }
    /**
     * Append an item to the seeBlocks collection.
     * @internal
     */
    _appendSeeBlock(block) {
        this._seeBlocks.push(block);
    }
    /**
     * Append an item to the customBlocks collection.
     */
    appendCustomBlock(block) {
        this._customBlocks.push(block);
    }
    /** @override */
    onGetChildNodes() {
        return [
            this.summarySection,
            this.remarksBlock,
            this.privateRemarks,
            this.deprecatedBlock,
            this.params.count > 0 ? this.params : undefined,
            this.typeParams.count > 0 ? this.typeParams : undefined,
            this.returnsBlock,
            ...this.customBlocks,
            ...this.seeBlocks,
            this.inheritDocTag,
            ...this.modifierTagSet.nodes
        ];
    }
    /**
     * Generates a doc comment corresponding to the `DocComment` tree.  The output is in a normalized form,
     * and may ignore formatting/spacing from the original input.
     *
     * @remarks
     * After parsing a string, and possibly modifying the result, `emitAsTsdoc()` can be used to render the result
     * as a doc comment in a normalized format.  It can also be used to emit a `DocComment` tree that was constructed
     * manually.
     *
     * This method is provided as convenience for simple use cases.  To customize the output, or if you need
     * to render into a `StringBuilder`, use the {@link TSDocEmitter} class instead.
     */
    emitAsTsdoc() {
        const stringBuilder = new StringBuilder();
        const emitter = new TSDocEmitter();
        emitter.renderComment(stringBuilder, this);
        return stringBuilder.toString();
    }
}
//# sourceMappingURL=DocComment.js.map