UNPKG

3.82 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || (function () {
2 var extendStatics = function (d, b) {
3 extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return extendStatics(d, b);
7 };
8 return function (d, b) {
9 extendStatics(d, b);
10 function __() { this.constructor = d; }
11 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12 };
13})();
14import { DocNodeKind, DocNode } from './DocNode';
15/**
16 * Represents a collection of DocParamBlock objects and provides efficient operations for looking up the
17 * documentation for a specified parameter name.
18 */
19var DocParamCollection = /** @class */ (function (_super) {
20 __extends(DocParamCollection, _super);
21 /**
22 * Don't call this directly. Instead use {@link TSDocParser}
23 * @internal
24 */
25 function DocParamCollection(parameters) {
26 var _this = _super.call(this, parameters) || this;
27 _this._blocks = [];
28 return _this;
29 }
30 Object.defineProperty(DocParamCollection.prototype, "kind", {
31 /** @override */
32 get: function () {
33 return DocNodeKind.ParamCollection;
34 },
35 enumerable: false,
36 configurable: true
37 });
38 /**
39 * Provide an iterator for callers that support it.
40 */
41 DocParamCollection.prototype[Symbol.iterator] = function () {
42 return this._blocks[Symbol.iterator]();
43 };
44 Object.defineProperty(DocParamCollection.prototype, "blocks", {
45 /**
46 * Returns the blocks in this collection.
47 */
48 get: function () {
49 return this._blocks;
50 },
51 enumerable: false,
52 configurable: true
53 });
54 Object.defineProperty(DocParamCollection.prototype, "count", {
55 /**
56 * Returns the number of blocks in this collection.
57 */
58 get: function () {
59 return this._blocks.length;
60 },
61 enumerable: false,
62 configurable: true
63 });
64 /**
65 * Adds a new block to the collection.
66 */
67 DocParamCollection.prototype.add = function (docParamBlock) {
68 this._blocks.push(docParamBlock);
69 // Allocate the map on demand, since most DocComment parameter collections will be empty
70 if (this._blocksByName === undefined) {
71 this._blocksByName = new Map();
72 }
73 // The first block to be added takes precedence
74 if (!this._blocksByName.has(docParamBlock.parameterName)) {
75 this._blocksByName.set(docParamBlock.parameterName, docParamBlock);
76 }
77 };
78 /**
79 * Removes all blocks from the collection
80 */
81 DocParamCollection.prototype.clear = function () {
82 this._blocks.length = 0;
83 this._blocksByName = undefined;
84 };
85 /**
86 * Returns the first block whose `parameterName` matches the specified string.
87 *
88 * @remarks
89 * If the collection was parsed from an input containing errors, there could potentially be more than
90 * one DocParamBlock with the same name. In this situation, tryGetBlockByName() will return the first match
91 * that it finds.
92 *
93 * This lookup is optimized using a dictionary.
94 */
95 DocParamCollection.prototype.tryGetBlockByName = function (parameterName) {
96 if (this._blocksByName) {
97 return this._blocksByName.get(parameterName);
98 }
99 return undefined;
100 };
101 /** @override */
102 DocParamCollection.prototype.onGetChildNodes = function () {
103 return this._blocks;
104 };
105 return DocParamCollection;
106}(DocNode));
107export { DocParamCollection };
108//# sourceMappingURL=DocParamCollection.js.map
\No newline at end of file