UNPKG

3.41 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ModifierTagSet = void 0;
4var TSDocTagDefinition_1 = require("../configuration/TSDocTagDefinition");
5/**
6 * Represents a set of modifier tags that were extracted from a doc comment.
7 *
8 * @remarks
9 * TSDoc modifier tags are block tags that do not have any associated rich text content.
10 * Instead, their presence or absence acts as an on/off switch, indicating some aspect
11 * of the underlying API item. For example, the `@internal` modifier indicates that a
12 * signature is internal (i.e. not part of the public API contract).
13 */
14var ModifierTagSet = /** @class */ (function () {
15 function ModifierTagSet() {
16 this._nodes = [];
17 // NOTE: To implement case insensitivity, the keys in this set are always upper-case.
18 // This convention makes the normalization more obvious (and as a general practice handles
19 // the Turkish "i" character correctly).
20 this._nodesByName = new Map();
21 }
22 Object.defineProperty(ModifierTagSet.prototype, "nodes", {
23 /**
24 * The original block tag nodes that defined the modifiers in this set, excluding duplicates.
25 */
26 get: function () {
27 return this._nodes;
28 },
29 enumerable: false,
30 configurable: true
31 });
32 /**
33 * Returns true if the set contains a DocBlockTag with the specified tag name.
34 * Note that synonyms are not considered. The comparison is case-insensitive.
35 * @param modifierTagName - The name of the tag, including the `@` prefix For example, `@internal`
36 */
37 ModifierTagSet.prototype.hasTagName = function (modifierTagName) {
38 return this._nodesByName.has(modifierTagName.toUpperCase());
39 };
40 /**
41 * Returns true if the set contains a DocBlockTag matching the specified tag definition.
42 * Note that synonyms are not considered. The comparison is case-insensitive.
43 * The TSDocTagDefinition must be a modifier tag.
44 * @param tagName - The name of the tag, including the `@` prefix For example, `@internal`
45 */
46 ModifierTagSet.prototype.hasTag = function (modifierTagDefinition) {
47 return !!this.tryGetTag(modifierTagDefinition);
48 };
49 /**
50 * Returns a DocBlockTag matching the specified tag definition, or undefined if no such
51 * tag was added to the set. If there were multiple instances, returned object will be
52 * the first one to be added.
53 */
54 ModifierTagSet.prototype.tryGetTag = function (modifierTagDefinition) {
55 if (modifierTagDefinition.syntaxKind !== TSDocTagDefinition_1.TSDocTagSyntaxKind.ModifierTag) {
56 throw new Error('The tag definition is not a modifier tag');
57 }
58 return this._nodesByName.get(modifierTagDefinition.tagNameWithUpperCase);
59 };
60 /**
61 * Adds a new modifier tag to the set. If a tag already exists with the same name,
62 * then no change is made, and the return value is false.
63 */
64 ModifierTagSet.prototype.addTag = function (blockTag) {
65 if (this._nodesByName.has(blockTag.tagNameWithUpperCase)) {
66 return false;
67 }
68 this._nodesByName.set(blockTag.tagNameWithUpperCase, blockTag);
69 this._nodes.push(blockTag);
70 return true;
71 };
72 return ModifierTagSet;
73}());
74exports.ModifierTagSet = ModifierTagSet;
75//# sourceMappingURL=ModifierTagSet.js.map
\No newline at end of file