UNPKG

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