UNPKG

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