UNPKG

7.01 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.DocMemberSelector = exports.SelectorKind = void 0;
17var DocNode_1 = require("./DocNode");
18var StringChecks_1 = require("../parser/StringChecks");
19var DocExcerpt_1 = require("./DocExcerpt");
20/**
21 * Kinds of TSDoc selectors.
22 */
23var SelectorKind;
24(function (SelectorKind) {
25 /**
26 * Used in cases where the parser encounters a string that is incorrect but
27 * valid enough that a DocMemberSelector node was created.
28 */
29 SelectorKind["Error"] = "error";
30 /**
31 * System selectors are always all lower-case and belong to a set of predefined label names.
32 */
33 SelectorKind["System"] = "system";
34 /**
35 * Index selectors are integer numbers. They provide an alternative way of referencing
36 * overloaded functions, based on the order in which the declarations appear in
37 * a source file.
38 *
39 * @remarks
40 * Warning: Index selectors are not recommended; they are intended to provide a temporary
41 * workaround for situations where an external library neglected to declare a `{@label}` tag
42 * and cannot be easily fixed.
43 */
44 SelectorKind["Index"] = "index";
45 /**
46 * Label selectors refer to labels created using the `{@label}` TSDoc tag.
47 * The labels are always comprised of upper-case letters or numbers separated by underscores,
48 * and the first character cannot be a number.
49 */
50 SelectorKind["Label"] = "label";
51})(SelectorKind = exports.SelectorKind || (exports.SelectorKind = {}));
52/**
53 */
54var DocMemberSelector = /** @class */ (function (_super) {
55 __extends(DocMemberSelector, _super);
56 /**
57 * Don't call this directly. Instead use {@link TSDocParser}
58 * @internal
59 */
60 function DocMemberSelector(parameters) {
61 var _this = _super.call(this, parameters) || this;
62 if (DocNode_1.DocNode.isParsedParameters(parameters)) {
63 _this._selectorExcerpt = new DocExcerpt_1.DocExcerpt({
64 configuration: _this.configuration,
65 excerptKind: DocExcerpt_1.ExcerptKind.MemberSelector,
66 content: parameters.selectorExcerpt
67 });
68 _this._selector = parameters.selectorExcerpt.toString();
69 }
70 else {
71 _this._selector = parameters.selector;
72 }
73 _this._selectorKind = SelectorKind.Error;
74 _this._errorMessage = undefined;
75 // The logic below will always either (1) assign selectorKind or (2) else assign an errorMessage
76 if (_this._selector.length === 0) {
77 _this._errorMessage = 'The selector cannot be an empty string';
78 }
79 else if (DocMemberSelector._likeIndexSelectorRegExp.test(_this._selector)) {
80 // It looks like an index selector
81 if (DocMemberSelector._indexSelectorRegExp.test(_this._selector)) {
82 _this._selectorKind = SelectorKind.Index;
83 }
84 else {
85 _this._errorMessage = 'If the selector begins with a number, it must be a positive integer value';
86 }
87 }
88 else if (DocMemberSelector._likeLabelSelectorRegExp.test(_this._selector)) {
89 // It looks like a label selector
90 if (DocMemberSelector._labelSelectorRegExp.test(_this._selector)) {
91 _this._selectorKind = SelectorKind.Label;
92 }
93 else {
94 _this._errorMessage =
95 'A label selector must be comprised of upper case letters, numbers,' +
96 ' and underscores and must not start with a number';
97 }
98 }
99 else {
100 if (StringChecks_1.StringChecks.isSystemSelector(_this._selector)) {
101 _this._selectorKind = SelectorKind.System;
102 }
103 else if (DocMemberSelector._likeSystemSelectorRegExp.test(_this._selector)) {
104 // It looks like a system selector, but is not
105 _this._errorMessage =
106 "The selector " + JSON.stringify(_this._selector) +
107 " is not a recognized TSDoc system selector name";
108 }
109 else {
110 // It doesn't look like anything we recognize
111 _this._errorMessage = 'Invalid syntax for selector';
112 }
113 }
114 return _this;
115 }
116 Object.defineProperty(DocMemberSelector.prototype, "kind", {
117 /** @override */
118 get: function () {
119 return DocNode_1.DocNodeKind.MemberSelector;
120 },
121 enumerable: false,
122 configurable: true
123 });
124 Object.defineProperty(DocMemberSelector.prototype, "selector", {
125 /**
126 * The text representation of the selector.
127 *
128 * @remarks
129 * For system selectors, it will be a predefined lower case name.
130 * For label selectors, it will be an upper case name defined using the `{@label}` tag.
131 * For index selectors, it will be a positive integer.
132 */
133 get: function () {
134 return this._selector;
135 },
136 enumerable: false,
137 configurable: true
138 });
139 Object.defineProperty(DocMemberSelector.prototype, "selectorKind", {
140 /**
141 * Indicates the kind of selector.
142 */
143 get: function () {
144 return this._selectorKind;
145 },
146 enumerable: false,
147 configurable: true
148 });
149 Object.defineProperty(DocMemberSelector.prototype, "errorMessage", {
150 /**
151 * If the `selectorKind` is `SelectorKind.Error`, this string will be defined and provide
152 * more detail about why the string was not valid.
153 */
154 get: function () {
155 return this._errorMessage;
156 },
157 enumerable: false,
158 configurable: true
159 });
160 /** @override */
161 DocMemberSelector.prototype.onGetChildNodes = function () {
162 return [this._selectorExcerpt];
163 };
164 DocMemberSelector._likeIndexSelectorRegExp = /^[0-9]/;
165 DocMemberSelector._indexSelectorRegExp = /^[1-9][0-9]*$/;
166 DocMemberSelector._likeLabelSelectorRegExp = /^[A-Z_]/u;
167 DocMemberSelector._labelSelectorRegExp = /^[A-Z_][A-Z0-9_]+$/;
168 DocMemberSelector._likeSystemSelectorRegExp = /^[a-z]+$/u;
169 return DocMemberSelector;
170}(DocNode_1.DocNode));
171exports.DocMemberSelector = DocMemberSelector;
172//# sourceMappingURL=DocMemberSelector.js.map
\No newline at end of file