UNPKG

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