UNPKG

7.2 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 { DocInlineTagBase } from './DocInlineTagBase';
16import { DocExcerpt, ExcerptKind } from './DocExcerpt';
17/**
18 * Represents an `{@link}` tag.
19 */
20var DocLinkTag = /** @class */ (function (_super) {
21 __extends(DocLinkTag, _super);
22 /**
23 * Don't call this directly. Instead use {@link TSDocParser}
24 * @internal
25 */
26 function DocLinkTag(parameters) {
27 var _this = _super.call(this, parameters) || this;
28 if (_this.tagNameWithUpperCase !== '@LINK') {
29 throw new Error('DocLinkTag requires the tag name to be "{@link}"');
30 }
31 _this._codeDestination = parameters.codeDestination;
32 if (DocNode.isParsedParameters(parameters)) {
33 if (parameters.codeDestination !== undefined && parameters.urlDestinationExcerpt !== undefined) {
34 throw new Error('Either the codeDestination or the urlDestination may be specified, but not both');
35 }
36 if (parameters.urlDestinationExcerpt) {
37 _this._urlDestinationExcerpt = new DocExcerpt({
38 configuration: _this.configuration,
39 excerptKind: ExcerptKind.LinkTag_UrlDestination,
40 content: parameters.urlDestinationExcerpt
41 });
42 }
43 if (parameters.spacingAfterDestinationExcerpt) {
44 _this._spacingAfterDestinationExcerpt = new DocExcerpt({
45 configuration: _this.configuration,
46 excerptKind: ExcerptKind.Spacing,
47 content: parameters.spacingAfterDestinationExcerpt
48 });
49 }
50 if (parameters.pipeExcerpt) {
51 _this._pipeExcerpt = new DocExcerpt({
52 configuration: _this.configuration,
53 excerptKind: ExcerptKind.LinkTag_Pipe,
54 content: parameters.pipeExcerpt
55 });
56 }
57 if (parameters.spacingAfterPipeExcerpt) {
58 _this._spacingAfterPipeExcerpt = new DocExcerpt({
59 configuration: _this.configuration,
60 excerptKind: ExcerptKind.Spacing,
61 content: parameters.spacingAfterPipeExcerpt
62 });
63 }
64 if (parameters.linkTextExcerpt) {
65 _this._linkTextExcerpt = new DocExcerpt({
66 configuration: _this.configuration,
67 excerptKind: ExcerptKind.LinkTag_LinkText,
68 content: parameters.linkTextExcerpt
69 });
70 }
71 if (parameters.spacingAfterLinkTextExcerpt) {
72 _this._spacingAfterLinkTextExcerpt = new DocExcerpt({
73 configuration: _this.configuration,
74 excerptKind: ExcerptKind.Spacing,
75 content: parameters.spacingAfterLinkTextExcerpt
76 });
77 }
78 }
79 else {
80 if (parameters.codeDestination !== undefined && parameters.urlDestination !== undefined) {
81 throw new Error('Either the codeDestination or the urlDestination may be specified, but not both');
82 }
83 _this._urlDestination = parameters.urlDestination;
84 _this._linkText = parameters.linkText;
85 }
86 return _this;
87 }
88 Object.defineProperty(DocLinkTag.prototype, "kind", {
89 /** @override */
90 get: function () {
91 return DocNodeKind.LinkTag;
92 },
93 enumerable: false,
94 configurable: true
95 });
96 Object.defineProperty(DocLinkTag.prototype, "codeDestination", {
97 /**
98 * If the link tag refers to a declaration, this returns the declaration reference object;
99 * otherwise this property is undefined.
100 * @remarks
101 * Either the `codeDestination` or the `urlDestination` property will be defined, but never both.
102 */
103 get: function () {
104 return this._codeDestination;
105 },
106 enumerable: false,
107 configurable: true
108 });
109 Object.defineProperty(DocLinkTag.prototype, "urlDestination", {
110 /**
111 * If the link tag was an ordinary URI, this returns the URL string;
112 * otherwise this property is undefined.
113 * @remarks
114 * Either the `codeDestination` or the `urlDestination` property will be defined, but never both.
115 */
116 get: function () {
117 if (this._urlDestination === undefined) {
118 if (this._urlDestinationExcerpt !== undefined) {
119 this._urlDestination = this._urlDestinationExcerpt.content.toString();
120 }
121 }
122 return this._urlDestination;
123 },
124 enumerable: false,
125 configurable: true
126 });
127 Object.defineProperty(DocLinkTag.prototype, "linkText", {
128 /**
129 * An optional text string that is the hyperlink text. If omitted, the documentation
130 * renderer will use a default string based on the link itself (e.g. the URL text
131 * or the declaration identifier).
132 *
133 * @remarks
134 *
135 * In HTML, the hyperlink can include leading/trailing space characters around the link text.
136 * For example, this HTML will cause a web browser to `y` and also the space character before
137 * and after it:
138 *
139 * ```html
140 * x<a href="#Button"> y </a> z
141 * ```
142 *
143 * Unlike HTML, TSDoc trims leading/trailing spaces. For example, this TSDoc will be
144 * displayed `xy z` and underline only the `y` character:
145 *
146 * ```
147 * x{@link Button | y } z
148 * ```
149 */
150 get: function () {
151 if (this._linkText === undefined) {
152 if (this._linkTextExcerpt !== undefined) {
153 this._linkText = this._linkTextExcerpt.content.toString();
154 }
155 }
156 return this._linkText;
157 },
158 enumerable: false,
159 configurable: true
160 });
161 /** @override */
162 DocLinkTag.prototype.getChildNodesForContent = function () {
163 // abstract
164 return [
165 this._codeDestination,
166 this._urlDestinationExcerpt,
167 this._spacingAfterDestinationExcerpt,
168 this._pipeExcerpt,
169 this._spacingAfterPipeExcerpt,
170 this._linkTextExcerpt,
171 this._spacingAfterLinkTextExcerpt
172 ];
173 };
174 return DocLinkTag;
175}(DocInlineTagBase));
176export { DocLinkTag };
177//# sourceMappingURL=DocLinkTag.js.map
\No newline at end of file