UNPKG

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