UNPKG

5.95 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})();
14var __spreadArrays = (this && this.__spreadArrays) || function () {
15 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
16 for (var r = Array(s), k = 0, i = 0; i < il; i++)
17 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
18 r[k] = a[j];
19 return r;
20};
21import { DocNode, DocNodeKind } from './DocNode';
22import { DocExcerpt, ExcerptKind } from './DocExcerpt';
23import { StringBuilder } from '../emitters/StringBuilder';
24/**
25 * Represents an HTML start tag, which may or may not be self-closing.
26 *
27 * Example: `<a href="#" />`
28 */
29var DocHtmlStartTag = /** @class */ (function (_super) {
30 __extends(DocHtmlStartTag, _super);
31 /**
32 * Don't call this directly. Instead use {@link TSDocParser}
33 * @internal
34 */
35 function DocHtmlStartTag(parameters) {
36 var _a;
37 var _this = _super.call(this, parameters) || this;
38 if (DocNode.isParsedParameters(parameters)) {
39 _this._openingDelimiterExcerpt = new DocExcerpt({
40 configuration: _this.configuration,
41 excerptKind: ExcerptKind.HtmlStartTag_OpeningDelimiter,
42 content: parameters.openingDelimiterExcerpt
43 });
44 _this._nameExcerpt = new DocExcerpt({
45 configuration: _this.configuration,
46 excerptKind: ExcerptKind.HtmlStartTag_Name,
47 content: parameters.nameExcerpt
48 });
49 if (parameters.spacingAfterNameExcerpt) {
50 _this._spacingAfterNameExcerpt = new DocExcerpt({
51 configuration: _this.configuration,
52 excerptKind: ExcerptKind.Spacing,
53 content: parameters.spacingAfterNameExcerpt
54 });
55 }
56 _this._closingDelimiterExcerpt = new DocExcerpt({
57 configuration: _this.configuration,
58 excerptKind: ExcerptKind.HtmlStartTag_ClosingDelimiter,
59 content: parameters.closingDelimiterExcerpt
60 });
61 }
62 else {
63 _this._name = parameters.name;
64 _this._spacingAfterName = parameters.spacingAfterName;
65 }
66 _this._htmlAttributes = [];
67 if (parameters.htmlAttributes) {
68 (_a = _this._htmlAttributes).push.apply(_a, parameters.htmlAttributes);
69 }
70 _this._selfClosingTag = !!parameters.selfClosingTag;
71 return _this;
72 }
73 Object.defineProperty(DocHtmlStartTag.prototype, "kind", {
74 /** @override */
75 get: function () {
76 return DocNodeKind.HtmlStartTag;
77 },
78 enumerable: false,
79 configurable: true
80 });
81 Object.defineProperty(DocHtmlStartTag.prototype, "name", {
82 /**
83 * The HTML element name.
84 */
85 get: function () {
86 if (this._name === undefined) {
87 this._name = this._nameExcerpt.content.toString();
88 }
89 return this._name;
90 },
91 enumerable: false,
92 configurable: true
93 });
94 Object.defineProperty(DocHtmlStartTag.prototype, "htmlAttributes", {
95 /**
96 * The HTML attributes belonging to this HTML element.
97 */
98 get: function () {
99 return this._htmlAttributes;
100 },
101 enumerable: false,
102 configurable: true
103 });
104 Object.defineProperty(DocHtmlStartTag.prototype, "selfClosingTag", {
105 /**
106 * If true, then the HTML tag ends with `/>` instead of `>`.
107 */
108 get: function () {
109 return this._selfClosingTag;
110 },
111 enumerable: false,
112 configurable: true
113 });
114 Object.defineProperty(DocHtmlStartTag.prototype, "spacingAfterName", {
115 /**
116 * Explicit whitespace that a renderer should insert after the HTML element name.
117 * If undefined, then the renderer can use a formatting rule to generate appropriate spacing.
118 */
119 get: function () {
120 if (this._spacingAfterName === undefined) {
121 if (this._spacingAfterNameExcerpt !== undefined) {
122 this._spacingAfterName = this._spacingAfterNameExcerpt.content.toString();
123 }
124 }
125 return this._spacingAfterName;
126 },
127 enumerable: false,
128 configurable: true
129 });
130 /**
131 * Generates the HTML for this tag.
132 */
133 DocHtmlStartTag.prototype.emitAsHtml = function () {
134 // NOTE: Here we're assuming that the TSDoc representation for a tag is also a valid HTML expression.
135 var stringBuilder = new StringBuilder();
136 // eslint-disable-next-line @typescript-eslint/no-use-before-define
137 var emitter = new TSDocEmitter();
138 emitter.renderHtmlTag(stringBuilder, this);
139 return stringBuilder.toString();
140 };
141 /** @override */
142 DocHtmlStartTag.prototype.onGetChildNodes = function () {
143 return __spreadArrays([
144 this._openingDelimiterExcerpt,
145 this._nameExcerpt,
146 this._spacingAfterNameExcerpt
147 ], this._htmlAttributes, [
148 this._closingDelimiterExcerpt
149 ]);
150 };
151 return DocHtmlStartTag;
152}(DocNode));
153export { DocHtmlStartTag };
154// Circular reference
155import { TSDocEmitter } from '../emitters/TSDocEmitter';
156//# sourceMappingURL=DocHtmlStartTag.js.map
\No newline at end of file