UNPKG

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