UNPKG

3.21 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 { DocExcerpt, ExcerptKind } from './DocExcerpt';
16/**
17 * Represents a span of comment text that is considered by the parser
18 * to contain no special symbols or meaning.
19 *
20 * @remarks
21 * The text content must not contain newline characters.
22 * Use DocSoftBreak to represent manual line splitting.
23 */
24var DocPlainText = /** @class */ (function (_super) {
25 __extends(DocPlainText, _super);
26 /**
27 * Don't call this directly. Instead use {@link TSDocParser}
28 * @internal
29 */
30 function DocPlainText(parameters) {
31 var _this = _super.call(this, parameters) || this;
32 if (DocNode.isParsedParameters(parameters)) {
33 _this._textExcerpt = new DocExcerpt({
34 configuration: _this.configuration,
35 excerptKind: ExcerptKind.PlainText,
36 content: parameters.textExcerpt
37 });
38 }
39 else {
40 if (DocPlainText._newlineCharacterRegExp.test(parameters.text)) {
41 // Use DocSoftBreak to represent manual line splitting
42 throw new Error('The DocPlainText content must not contain newline characters');
43 }
44 _this._text = parameters.text;
45 }
46 return _this;
47 }
48 Object.defineProperty(DocPlainText.prototype, "kind", {
49 /** @override */
50 get: function () {
51 return DocNodeKind.PlainText;
52 },
53 enumerable: false,
54 configurable: true
55 });
56 Object.defineProperty(DocPlainText.prototype, "text", {
57 /**
58 * The text content.
59 */
60 get: function () {
61 if (this._text === undefined) {
62 this._text = this._textExcerpt.content.toString();
63 }
64 return this._text;
65 },
66 enumerable: false,
67 configurable: true
68 });
69 Object.defineProperty(DocPlainText.prototype, "textExcerpt", {
70 get: function () {
71 if (this._textExcerpt) {
72 return this._textExcerpt.content;
73 }
74 else {
75 return undefined;
76 }
77 },
78 enumerable: false,
79 configurable: true
80 });
81 /** @override */
82 DocPlainText.prototype.onGetChildNodes = function () {
83 return [this._textExcerpt];
84 };
85 // TODO: We should also prohibit "\r", but this requires updating LineExtractor
86 // to interpret a lone "\r" as a newline
87 DocPlainText._newlineCharacterRegExp = /[\n]/;
88 return DocPlainText;
89}(DocNode));
90export { DocPlainText };
91//# sourceMappingURL=DocPlainText.js.map
\No newline at end of file