UNPKG

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