UNPKG

11 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.TSDocConfiguration = void 0;
4var StandardTags_1 = require("../details/StandardTags");
5var TSDocValidationConfiguration_1 = require("./TSDocValidationConfiguration");
6var DocNodeManager_1 = require("./DocNodeManager");
7var BuiltInDocNodes_1 = require("../nodes/BuiltInDocNodes");
8var TSDocMessageId_1 = require("../parser/TSDocMessageId");
9/**
10 * Configuration for the TSDocParser.
11 */
12var TSDocConfiguration = /** @class */ (function () {
13 function TSDocConfiguration() {
14 this._tagDefinitions = [];
15 this._tagDefinitionsByName = new Map();
16 this._supportedTagDefinitions = new Set();
17 this._validation = new TSDocValidationConfiguration_1.TSDocValidationConfiguration();
18 this._docNodeManager = new DocNodeManager_1.DocNodeManager();
19 this._supportedHtmlElements = new Set();
20 this.clear(false);
21 // Register the built-in node kinds
22 BuiltInDocNodes_1.BuiltInDocNodes.register(this);
23 }
24 /**
25 * Resets the `TSDocConfiguration` object to its initial empty state.
26 * @param noStandardTags - The `TSDocConfiguration` constructor normally adds definitions for the
27 * standard TSDoc tags. Set `noStandardTags` to true for a completely empty `tagDefinitions` collection.
28 */
29 TSDocConfiguration.prototype.clear = function (noStandardTags) {
30 if (noStandardTags === void 0) { noStandardTags = false; }
31 this._tagDefinitions.length = 0;
32 this._tagDefinitionsByName.clear();
33 this._supportedTagDefinitions.clear();
34 this._validation.ignoreUndefinedTags = false;
35 this._validation.reportUnsupportedTags = false;
36 this._validation.reportUnsupportedHtmlElements = false;
37 this._supportedHtmlElements.clear();
38 if (!noStandardTags) {
39 // Define all the standard tags
40 this.addTagDefinitions(StandardTags_1.StandardTags.allDefinitions);
41 }
42 };
43 Object.defineProperty(TSDocConfiguration.prototype, "tagDefinitions", {
44 /**
45 * The TSDoc tags that are defined in this configuration.
46 *
47 * @remarks
48 * The subset of "supported" tags is tracked by {@link TSDocConfiguration.supportedTagDefinitions}.
49 */
50 get: function () {
51 return this._tagDefinitions;
52 },
53 enumerable: false,
54 configurable: true
55 });
56 Object.defineProperty(TSDocConfiguration.prototype, "supportedTagDefinitions", {
57 /**
58 * Returns the subset of {@link TSDocConfiguration.tagDefinitions}
59 * that are supported in this configuration.
60 *
61 * @remarks
62 * This property is only used when
63 * {@link TSDocValidationConfiguration.reportUnsupportedTags} is enabled.
64 */
65 get: function () {
66 var _this = this;
67 return this.tagDefinitions.filter(function (x) { return _this.isTagSupported(x); });
68 },
69 enumerable: false,
70 configurable: true
71 });
72 Object.defineProperty(TSDocConfiguration.prototype, "validation", {
73 /**
74 * Enable/disable validation checks performed by the parser.
75 */
76 get: function () {
77 return this._validation;
78 },
79 enumerable: false,
80 configurable: true
81 });
82 Object.defineProperty(TSDocConfiguration.prototype, "supportedHtmlElements", {
83 /**
84 * The HTML element names that are supported in this configuration. Used in conjunction with the `reportUnsupportedHtmlElements` setting.
85 */
86 get: function () {
87 return Array.from(this._supportedHtmlElements.values());
88 },
89 enumerable: false,
90 configurable: true
91 });
92 Object.defineProperty(TSDocConfiguration.prototype, "docNodeManager", {
93 /**
94 * Register custom DocNode subclasses.
95 */
96 get: function () {
97 return this._docNodeManager;
98 },
99 enumerable: false,
100 configurable: true
101 });
102 /**
103 * Return the tag that was defined with the specified name, or undefined
104 * if not found.
105 */
106 TSDocConfiguration.prototype.tryGetTagDefinition = function (tagName) {
107 return this._tagDefinitionsByName.get(tagName.toUpperCase());
108 };
109 /**
110 * Return the tag that was defined with the specified name, or undefined
111 * if not found.
112 */
113 TSDocConfiguration.prototype.tryGetTagDefinitionWithUpperCase = function (alreadyUpperCaseTagName) {
114 return this._tagDefinitionsByName.get(alreadyUpperCaseTagName);
115 };
116 /**
117 * Define a new TSDoc tag to be recognized by the TSDocParser, and mark it as unsupported.
118 * Use {@link TSDocConfiguration.setSupportForTag} to mark it as supported.
119 *
120 * @remarks
121 * If a tag is "defined" this means that the parser recognizes it and understands its syntax.
122 * Whereas if a tag is "supported", this means it is defined AND the application implements the tag.
123 */
124 TSDocConfiguration.prototype.addTagDefinition = function (tagDefinition) {
125 var existingDefinition = this._tagDefinitionsByName.get(tagDefinition.tagNameWithUpperCase);
126 if (existingDefinition === tagDefinition) {
127 return;
128 }
129 if (existingDefinition) {
130 throw new Error("A tag is already defined using the name " + existingDefinition.tagName);
131 }
132 this._tagDefinitions.push(tagDefinition);
133 this._tagDefinitionsByName.set(tagDefinition.tagNameWithUpperCase, tagDefinition);
134 };
135 /**
136 * Calls {@link TSDocConfiguration.addTagDefinition} for a list of definitions,
137 * and optionally marks them as supported.
138 * @param tagDefinitions - the definitions to be added
139 * @param supported - if specified, calls the {@link TSDocConfiguration.setSupportForTag}
140 * method to mark the definitions as supported or unsupported
141 */
142 TSDocConfiguration.prototype.addTagDefinitions = function (tagDefinitions, supported) {
143 for (var _i = 0, tagDefinitions_1 = tagDefinitions; _i < tagDefinitions_1.length; _i++) {
144 var tagDefinition = tagDefinitions_1[_i];
145 this.addTagDefinition(tagDefinition);
146 if (supported !== undefined) {
147 this.setSupportForTag(tagDefinition, supported);
148 }
149 }
150 };
151 /**
152 * Returns true if the tag is supported in this configuration.
153 */
154 TSDocConfiguration.prototype.isTagSupported = function (tagDefinition) {
155 this._requireTagToBeDefined(tagDefinition);
156 return this._supportedTagDefinitions.has(tagDefinition);
157 };
158 /**
159 * Specifies whether the tag definition is supported in this configuration.
160 * The parser may issue warnings for unsupported tags.
161 *
162 * @remarks
163 * If a tag is "defined" this means that the parser recognizes it and understands its syntax.
164 * Whereas if a tag is "supported", this means it is defined AND the application implements the tag.
165 *
166 * This function automatically sets {@link TSDocValidationConfiguration.reportUnsupportedTags}
167 * to true.
168 */
169 TSDocConfiguration.prototype.setSupportForTag = function (tagDefinition, supported) {
170 this._requireTagToBeDefined(tagDefinition);
171 if (supported) {
172 this._supportedTagDefinitions.add(tagDefinition);
173 }
174 else {
175 this._supportedTagDefinitions.delete(tagDefinition);
176 }
177 this.validation.reportUnsupportedTags = true;
178 };
179 /**
180 * Specifies whether the tag definition is supported in this configuration.
181 * This operation sets {@link TSDocValidationConfiguration.reportUnsupportedTags} to `true`.
182 *
183 * @remarks
184 * The parser may issue warnings for unsupported tags.
185 * If a tag is "defined" this means that the parser recognizes it and understands its syntax.
186 * Whereas if a tag is "supported", this means it is defined AND the application implements the tag.
187 */
188 TSDocConfiguration.prototype.setSupportForTags = function (tagDefinitions, supported) {
189 for (var _i = 0, tagDefinitions_2 = tagDefinitions; _i < tagDefinitions_2.length; _i++) {
190 var tagDefinition = tagDefinitions_2[_i];
191 this.setSupportForTag(tagDefinition, supported);
192 }
193 };
194 /**
195 * Assigns the `supportedHtmlElements` property, replacing any previous elements.
196 * This operation sets {@link TSDocValidationConfiguration.reportUnsupportedHtmlElements} to `true`.
197 */
198 TSDocConfiguration.prototype.setSupportedHtmlElements = function (htmlTags) {
199 this._supportedHtmlElements.clear();
200 this._validation.reportUnsupportedHtmlElements = true;
201 for (var _i = 0, htmlTags_1 = htmlTags; _i < htmlTags_1.length; _i++) {
202 var htmlTag = htmlTags_1[_i];
203 this._supportedHtmlElements.add(htmlTag);
204 }
205 };
206 /**
207 * Returns true if the html element is supported in this configuration.
208 */
209 TSDocConfiguration.prototype.isHtmlElementSupported = function (htmlTag) {
210 return this._supportedHtmlElements.has(htmlTag);
211 };
212 /**
213 * Returns true if the specified {@link TSDocMessageId} string is implemented by this release of the TSDoc parser.
214 * This can be used to detect misspelled identifiers.
215 *
216 * @privateRemarks
217 *
218 * Why this API is associated with TSDocConfiguration: In the future, if we enable support for custom extensions
219 * of the TSDoc parser, we may provide a way to register custom message identifiers.
220 */
221 TSDocConfiguration.prototype.isKnownMessageId = function (messageId) {
222 return TSDocMessageId_1.allTsdocMessageIdsSet.has(messageId);
223 };
224 Object.defineProperty(TSDocConfiguration.prototype, "allTsdocMessageIds", {
225 /**
226 * Returns the list of {@link TSDocMessageId} strings that are implemented by this release of the TSDoc parser.
227 *
228 * @privateRemarks
229 *
230 * Why this API is associated with TSDocConfiguration: In the future, if we enable support for custom extensions
231 * of the TSDoc parser, we may provide a way to register custom message identifiers.
232 */
233 get: function () {
234 return TSDocMessageId_1.allTsdocMessageIds;
235 },
236 enumerable: false,
237 configurable: true
238 });
239 TSDocConfiguration.prototype._requireTagToBeDefined = function (tagDefinition) {
240 var matching = this._tagDefinitionsByName.get(tagDefinition.tagNameWithUpperCase);
241 if (matching) {
242 if (matching === tagDefinition) {
243 return;
244 }
245 }
246 throw new Error('The specified TSDocTagDefinition is not defined for this TSDocConfiguration');
247 };
248 return TSDocConfiguration;
249}());
250exports.TSDocConfiguration = TSDocConfiguration;
251//# sourceMappingURL=TSDocConfiguration.js.map
\No newline at end of file