UNPKG

7.36 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 { DocNode, DocNodeKind } from './DocNode';
15import { TokenKind } from '../parser/Token';
16/* eslint-disable @typescript-eslint/naming-convention */
17/**
18 * Indicates the type of {@link DocExcerpt}.
19 */
20export var ExcerptKind;
21(function (ExcerptKind) {
22 ExcerptKind["Spacing"] = "Spacing";
23 ExcerptKind["BlockTag"] = "BlockTag";
24 ExcerptKind["CodeSpan_OpeningDelimiter"] = "CodeSpan_OpeningDelimiter";
25 ExcerptKind["CodeSpan_Code"] = "CodeSpan_Code";
26 ExcerptKind["CodeSpan_ClosingDelimiter"] = "CodeSpan_ClosingDelimiter";
27 ExcerptKind["DeclarationReference_PackageName"] = "DeclarationReference_PackageName";
28 ExcerptKind["DeclarationReference_ImportPath"] = "DeclarationReference_ImportPath";
29 ExcerptKind["DeclarationReference_ImportHash"] = "DeclarationReference_ImportHash";
30 /**
31 * Input characters that were reported as an error and do not appear to be part of a valid expression.
32 * A syntax highlighter might display them with an error color (e.g. red).
33 */
34 ExcerptKind["ErrorText"] = "ErrorText";
35 /**
36 * Input characters that do not conform to the TSDoc specification, but were recognized by the parser, for example
37 * as a known JSDoc pattern. A syntax highlighter should not display them with an error color (e.g. red)
38 * because the error reporting may be suppressed for "lax" parsing of legacy source code.
39 */
40 ExcerptKind["NonstandardText"] = "NonstandardText";
41 ExcerptKind["EscapedText"] = "EscapedText";
42 ExcerptKind["FencedCode_OpeningFence"] = "FencedCode_OpeningFence";
43 ExcerptKind["FencedCode_Language"] = "FencedCode_Language";
44 ExcerptKind["FencedCode_Code"] = "FencedCode_Code";
45 ExcerptKind["FencedCode_ClosingFence"] = "FencedCode_ClosingFence";
46 ExcerptKind["HtmlAttribute_Name"] = "HtmlAttribute_Name";
47 ExcerptKind["HtmlAttribute_Equals"] = "HtmlAttribute_Equals";
48 ExcerptKind["HtmlAttribute_Value"] = "HtmlAttribute_Value";
49 ExcerptKind["HtmlEndTag_OpeningDelimiter"] = "HtmlEndTag_OpeningDelimiter";
50 ExcerptKind["HtmlEndTag_Name"] = "HtmlEndTag_Name";
51 ExcerptKind["HtmlEndTag_ClosingDelimiter"] = "HtmlEndTag_ClosingDelimiter";
52 ExcerptKind["HtmlStartTag_OpeningDelimiter"] = "HtmlStartTag_OpeningDelimiter";
53 ExcerptKind["HtmlStartTag_Name"] = "HtmlStartTag_Name";
54 ExcerptKind["HtmlStartTag_ClosingDelimiter"] = "HtmlStartTag_ClosingDelimiter";
55 ExcerptKind["InlineTag_OpeningDelimiter"] = "InlineTag_OpeningDelimiter";
56 ExcerptKind["InlineTag_TagName"] = "InlineTag_TagName";
57 ExcerptKind["InlineTag_TagContent"] = "InlineTag_TagContent";
58 ExcerptKind["InlineTag_ClosingDelimiter"] = "InlineTag_ClosingDelimiter";
59 ExcerptKind["LinkTag_UrlDestination"] = "LinkTag_UrlDestination";
60 ExcerptKind["LinkTag_Pipe"] = "LinkTag_Pipe";
61 ExcerptKind["LinkTag_LinkText"] = "LinkTag_LinkText";
62 ExcerptKind["MemberIdentifier_LeftQuote"] = "MemberIdentifier_LeftQuote";
63 ExcerptKind["MemberIdentifier_Identifier"] = "MemberIdentifier_Identifier";
64 ExcerptKind["MemberIdentifier_RightQuote"] = "MemberIdentifier_RightQuote";
65 ExcerptKind["MemberReference_Dot"] = "MemberReference_Dot";
66 ExcerptKind["MemberReference_LeftParenthesis"] = "MemberReference_LeftParenthesis";
67 ExcerptKind["MemberReference_Colon"] = "MemberReference_Colon";
68 ExcerptKind["MemberReference_RightParenthesis"] = "MemberReference_RightParenthesis";
69 ExcerptKind["MemberSelector"] = "MemberSelector";
70 ExcerptKind["DocMemberSymbol_LeftBracket"] = "DocMemberSymbol_LeftBracket";
71 ExcerptKind["DocMemberSymbol_RightBracket"] = "DocMemberSymbol_RightBracket";
72 ExcerptKind["ParamBlock_ParameterName"] = "ParamBlock_ParameterName";
73 ExcerptKind["ParamBlock_Hyphen"] = "ParamBlock_Hyphen";
74 ExcerptKind["PlainText"] = "PlainText";
75 ExcerptKind["SoftBreak"] = "SoftBreak";
76})(ExcerptKind || (ExcerptKind = {}));
77/**
78 * Represents a parsed token sequence.
79 *
80 * @remarks
81 * When a `DocNode` is created by parsing a doc comment, it will have `DocExcerpt` child nodes corresponding to
82 * the parsed syntax elements such as names, keywords, punctuation, and spaces. These excerpts indicate the original
83 * coordinates of the syntax element, and thus can be used for syntax highlighting and precise error reporting.
84 * They could also be used to rewrite specific words in a source file (e.g. renaming a parameter) without disturbing
85 * any other characters in the file.
86 *
87 * Every parsed character will correspond to at most one DocExcerpt object. In other words, excerpts never overlap.
88 * A given excerpt can span multiple comment lines, and it may contain gaps, for example to skip the `*` character
89 * that starts a new TSDoc comment line.
90 */
91var DocExcerpt = /** @class */ (function (_super) {
92 __extends(DocExcerpt, _super);
93 /**
94 * Don't call this directly. Instead use {@link TSDocParser}
95 * @internal
96 */
97 function DocExcerpt(parameters) {
98 var _this = _super.call(this, parameters) || this;
99 if (parameters.excerptKind === ExcerptKind.Spacing) {
100 for (var _i = 0, _a = parameters.content.tokens; _i < _a.length; _i++) {
101 var token = _a[_i];
102 switch (token.kind) {
103 case TokenKind.Spacing:
104 case TokenKind.Newline:
105 case TokenKind.EndOfInput:
106 break;
107 default:
108 throw new Error("The excerptKind=Spacing but the range contains a non-whitespace token");
109 }
110 }
111 }
112 _this._excerptKind = parameters.excerptKind;
113 _this._content = parameters.content;
114 return _this;
115 }
116 Object.defineProperty(DocExcerpt.prototype, "kind", {
117 /** @override */
118 get: function () {
119 return DocNodeKind.Excerpt;
120 },
121 enumerable: false,
122 configurable: true
123 });
124 Object.defineProperty(DocExcerpt.prototype, "excerptKind", {
125 /**
126 * Indicates the kind of DocExcerpt.
127 */
128 get: function () {
129 return this._excerptKind;
130 },
131 enumerable: false,
132 configurable: true
133 });
134 Object.defineProperty(DocExcerpt.prototype, "content", {
135 /**
136 * The input token sequence corresponding to this excerpt.
137 * @remarks
138 * Note that a token sequence can span multiple input lines and may contain gaps, for example to skip the `*`
139 * character that starts a new TSDoc comment line.
140 */
141 get: function () {
142 return this._content;
143 },
144 enumerable: false,
145 configurable: true
146 });
147 return DocExcerpt;
148}(DocNode));
149export { DocExcerpt };
150//# sourceMappingURL=DocExcerpt.js.map
\No newline at end of file