@cjser/es-joy__jsdoccomment 0.96.0-cjser.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +883 -0
- package/LICENSE-MIT.txt +20 -0
- package/README.md +250 -0
- package/dist/index.d.ts +421 -0
- package/dist-cjser/index.cjs +1224 -0
- package/package.json +144 -0
- package/src/commentHandler.js +48 -0
- package/src/commentParserToESTree.js +525 -0
- package/src/estreeToString.js +234 -0
- package/src/index.js +59 -0
- package/src/inlineTagEscapes.js +73 -0
- package/src/jsdoccomment.js +705 -0
- package/src/parseComment.js +190 -0
- package/src/parseInlineTags.js +114 -0
- package/src/toCamelCase.js +13 -0
|
@@ -0,0 +1,1224 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/index.js
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
commentHandler: () => commentHandler,
|
|
34
|
+
commentParserToESTree: () => commentParserToESTree,
|
|
35
|
+
defaultNoNames: () => defaultNoNames,
|
|
36
|
+
defaultNoTypes: () => defaultNoTypes,
|
|
37
|
+
estreeToString: () => estreeToString,
|
|
38
|
+
findJSDocComment: () => findJSDocComment,
|
|
39
|
+
getDecorator: () => getDecorator,
|
|
40
|
+
getFollowingComment: () => getFollowingComment,
|
|
41
|
+
getJSDocComment: () => getJSDocComment,
|
|
42
|
+
getNonJsdocComment: () => getNonJsdocComment,
|
|
43
|
+
getReducedASTNode: () => getReducedASTNode,
|
|
44
|
+
getTokenizers: () => getTokenizers,
|
|
45
|
+
hasSeeWithLink: () => hasSeeWithLink,
|
|
46
|
+
jsdocTypeVisitorKeys: () => import_jsdoc_type_pratt_parser4.visitorKeys,
|
|
47
|
+
jsdocVisitorKeys: () => jsdocVisitorKeys,
|
|
48
|
+
parseComment: () => parseComment,
|
|
49
|
+
parseInlineTags: () => parseInlineTags
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(index_exports);
|
|
52
|
+
var import_jsdoc_type_pratt_parser4 = require("@cjser/jsdoc-type-pratt-parser");
|
|
53
|
+
__reExport(index_exports, require("@cjser/jsdoc-type-pratt-parser"), module.exports);
|
|
54
|
+
|
|
55
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/commentHandler.js
|
|
56
|
+
var import_esquery = __toESM(require("esquery"), 1);
|
|
57
|
+
var import_jsdoc_type_pratt_parser2 = require("@cjser/jsdoc-type-pratt-parser");
|
|
58
|
+
|
|
59
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/commentParserToESTree.js
|
|
60
|
+
var import_jsdoc_type_pratt_parser = require("@cjser/jsdoc-type-pratt-parser");
|
|
61
|
+
var stripEncapsulatingBrackets = (container, isArr) => {
|
|
62
|
+
if (isArr) {
|
|
63
|
+
const firstItem = (
|
|
64
|
+
/** @type {JsdocTypeLine[]} */
|
|
65
|
+
container[0]
|
|
66
|
+
);
|
|
67
|
+
firstItem.rawType = firstItem.rawType.replace(
|
|
68
|
+
new RegExp("^\\{", "v"),
|
|
69
|
+
""
|
|
70
|
+
);
|
|
71
|
+
const lastItem = (
|
|
72
|
+
/** @type {JsdocTypeLine} */
|
|
73
|
+
/** @type {JsdocTypeLine[]} */
|
|
74
|
+
container.at(-1)
|
|
75
|
+
);
|
|
76
|
+
lastItem.rawType = lastItem.rawType.replace(new RegExp("\\}$", "v"), "");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
container.rawType = /** @type {JsdocTag} */
|
|
80
|
+
container.rawType.replace(
|
|
81
|
+
new RegExp("^\\{", "v"),
|
|
82
|
+
""
|
|
83
|
+
).replace(new RegExp("\\}$", "v"), "");
|
|
84
|
+
};
|
|
85
|
+
var inlineTagToAST = ({ text, tag, format, namepathOrURL }) => ({
|
|
86
|
+
text,
|
|
87
|
+
tag,
|
|
88
|
+
format,
|
|
89
|
+
namepathOrURL,
|
|
90
|
+
type: "JsdocInlineTag"
|
|
91
|
+
});
|
|
92
|
+
var commentParserToESTree = (jsdoc, mode = "typescript", {
|
|
93
|
+
spacing = "compact",
|
|
94
|
+
throwOnTypeParsingErrors = false,
|
|
95
|
+
jsdocTypePrattParserArgs
|
|
96
|
+
} = {}) => {
|
|
97
|
+
const cleanUpLastTag = (lastTag2) => {
|
|
98
|
+
stripEncapsulatingBrackets(lastTag2);
|
|
99
|
+
if (lastTag2.typeLines.length) {
|
|
100
|
+
stripEncapsulatingBrackets(lastTag2.typeLines, true);
|
|
101
|
+
}
|
|
102
|
+
if (lastTag2.descriptionLines.length === 1 && lastTag2.descriptionLines[0].description === "") {
|
|
103
|
+
lastTag2.descriptionLines.length = 0;
|
|
104
|
+
}
|
|
105
|
+
let parsedType = null;
|
|
106
|
+
try {
|
|
107
|
+
parsedType = (0, import_jsdoc_type_pratt_parser.parse)(
|
|
108
|
+
lastTag2.rawType,
|
|
109
|
+
mode,
|
|
110
|
+
jsdocTypePrattParserArgs
|
|
111
|
+
);
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (throwOnTypeParsingErrors && lastTag2.rawType) {
|
|
114
|
+
err.message = `Tag @${lastTag2.tag} with raw type \`${lastTag2.rawType}\` had parsing error: ${/** @type {Error} */
|
|
115
|
+
err.message}`;
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
lastTag2.parsedType = parsedType;
|
|
120
|
+
};
|
|
121
|
+
const { source, inlineTags: blockInlineTags } = jsdoc;
|
|
122
|
+
const { tokens: {
|
|
123
|
+
delimiter: delimiterRoot,
|
|
124
|
+
lineEnd: lineEndRoot,
|
|
125
|
+
postDelimiter: postDelimiterRoot,
|
|
126
|
+
start: startRoot,
|
|
127
|
+
end: endRoot
|
|
128
|
+
} } = source[0];
|
|
129
|
+
const endLine = source.length - 1;
|
|
130
|
+
const ast = {
|
|
131
|
+
delimiter: delimiterRoot,
|
|
132
|
+
delimiterLineBreak: "\n",
|
|
133
|
+
description: "",
|
|
134
|
+
descriptionLines: [],
|
|
135
|
+
inlineTags: blockInlineTags.map((t) => inlineTagToAST(t)),
|
|
136
|
+
initial: startRoot,
|
|
137
|
+
tags: [],
|
|
138
|
+
// `terminal` will be overwritten if there are other entries
|
|
139
|
+
terminal: endRoot,
|
|
140
|
+
preterminalLineBreak: "\n",
|
|
141
|
+
hasPreterminalDescription: 0,
|
|
142
|
+
endLine,
|
|
143
|
+
postDelimiter: postDelimiterRoot,
|
|
144
|
+
lineEnd: lineEndRoot,
|
|
145
|
+
type: "JsdocBlock"
|
|
146
|
+
};
|
|
147
|
+
const tags = [];
|
|
148
|
+
let lastDescriptionLine;
|
|
149
|
+
let lastTag = null;
|
|
150
|
+
let tagDescriptionSeen = false;
|
|
151
|
+
let descLineStateOpen = true;
|
|
152
|
+
source.forEach((info, idx) => {
|
|
153
|
+
const { tokens } = info;
|
|
154
|
+
const {
|
|
155
|
+
delimiter,
|
|
156
|
+
description,
|
|
157
|
+
postDelimiter,
|
|
158
|
+
start: initial,
|
|
159
|
+
tag,
|
|
160
|
+
end,
|
|
161
|
+
type: rawType
|
|
162
|
+
} = tokens;
|
|
163
|
+
if (!tag && description && descLineStateOpen) {
|
|
164
|
+
if (ast.descriptionStartLine === void 0) {
|
|
165
|
+
ast.descriptionStartLine = idx;
|
|
166
|
+
}
|
|
167
|
+
ast.descriptionEndLine = idx;
|
|
168
|
+
}
|
|
169
|
+
if (tag || end) {
|
|
170
|
+
descLineStateOpen = false;
|
|
171
|
+
if (lastDescriptionLine === void 0) {
|
|
172
|
+
lastDescriptionLine = idx;
|
|
173
|
+
}
|
|
174
|
+
if (lastTag) {
|
|
175
|
+
cleanUpLastTag(lastTag);
|
|
176
|
+
}
|
|
177
|
+
if (end && !tag) {
|
|
178
|
+
ast.terminal = end;
|
|
179
|
+
const isDelimiterLine = ast.descriptionLines.length === 0 && delimiter === "/**";
|
|
180
|
+
if (isDelimiterLine) {
|
|
181
|
+
ast.delimiterLineBreak = "";
|
|
182
|
+
}
|
|
183
|
+
if (description) {
|
|
184
|
+
if (ast.terminal === "*/") {
|
|
185
|
+
ast.preterminalLineBreak = "";
|
|
186
|
+
}
|
|
187
|
+
if (lastTag) {
|
|
188
|
+
ast.hasPreterminalTagDescription = 1;
|
|
189
|
+
} else {
|
|
190
|
+
ast.hasPreterminalDescription = 1;
|
|
191
|
+
}
|
|
192
|
+
const holder = lastTag || ast;
|
|
193
|
+
holder.description += (holder.description ? "\n" : "") + description;
|
|
194
|
+
holder.descriptionLines.push({
|
|
195
|
+
delimiter: isDelimiterLine ? "" : delimiter,
|
|
196
|
+
description,
|
|
197
|
+
postDelimiter: isDelimiterLine ? "" : postDelimiter,
|
|
198
|
+
initial,
|
|
199
|
+
type: "JsdocDescriptionLine"
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const {
|
|
205
|
+
// eslint-disable-next-line no-unused-vars -- Discarding
|
|
206
|
+
end: ed,
|
|
207
|
+
delimiter: de,
|
|
208
|
+
postDelimiter: pd,
|
|
209
|
+
start: init,
|
|
210
|
+
...tkns
|
|
211
|
+
} = tokens;
|
|
212
|
+
if (!tokens.name) {
|
|
213
|
+
let i = 1;
|
|
214
|
+
while (Object.hasOwn(source, idx + i)) {
|
|
215
|
+
const { tokens: {
|
|
216
|
+
name,
|
|
217
|
+
postName,
|
|
218
|
+
postType,
|
|
219
|
+
tag: tg
|
|
220
|
+
} } = source[idx + i];
|
|
221
|
+
if (tg) {
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
if (name) {
|
|
225
|
+
tkns.postType = postType;
|
|
226
|
+
tkns.name = name;
|
|
227
|
+
tkns.postName = postName;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
i++;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const tagInlineTags = tag ? (
|
|
234
|
+
/**
|
|
235
|
+
* @type {import('comment-parser').Spec & {
|
|
236
|
+
* inlineTags: JsdocInlineTagNoType[]
|
|
237
|
+
* }}
|
|
238
|
+
*/
|
|
239
|
+
jsdoc.tags[tags.length].inlineTags.map(
|
|
240
|
+
(t) => inlineTagToAST(t)
|
|
241
|
+
)
|
|
242
|
+
) : [];
|
|
243
|
+
const tagObj = {
|
|
244
|
+
...tkns,
|
|
245
|
+
initial: endLine ? init : "",
|
|
246
|
+
postDelimiter: lastDescriptionLine ? pd : "",
|
|
247
|
+
delimiter: lastDescriptionLine ? de : "",
|
|
248
|
+
descriptionLines: [],
|
|
249
|
+
inlineTags: tagInlineTags,
|
|
250
|
+
parsedType: null,
|
|
251
|
+
rawType: "",
|
|
252
|
+
type: "JsdocTag",
|
|
253
|
+
typeLines: []
|
|
254
|
+
};
|
|
255
|
+
tagObj.tag = tagObj.tag.replace(new RegExp("^@", "v"), "");
|
|
256
|
+
lastTag = tagObj;
|
|
257
|
+
tagDescriptionSeen = false;
|
|
258
|
+
tags.push(tagObj);
|
|
259
|
+
}
|
|
260
|
+
if (rawType) {
|
|
261
|
+
lastTag.typeLines.push(
|
|
262
|
+
/** @type {JsdocTag} */
|
|
263
|
+
lastTag.typeLines.length ? {
|
|
264
|
+
delimiter,
|
|
265
|
+
postDelimiter,
|
|
266
|
+
rawType,
|
|
267
|
+
initial,
|
|
268
|
+
type: "JsdocTypeLine"
|
|
269
|
+
} : {
|
|
270
|
+
delimiter: "",
|
|
271
|
+
postDelimiter: "",
|
|
272
|
+
rawType,
|
|
273
|
+
initial: "",
|
|
274
|
+
type: "JsdocTypeLine"
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
lastTag.rawType += /** @type {JsdocTag} */
|
|
278
|
+
lastTag.rawType ? "\n" + rawType : rawType;
|
|
279
|
+
}
|
|
280
|
+
if (lastTag || spacing === "compact" && description || spacing === "preserve" && (description || delimiter !== "/**")) {
|
|
281
|
+
const holder = lastTag || ast;
|
|
282
|
+
const isDelimiterLine = holder.descriptionLines.length === 0 && delimiter === "/**";
|
|
283
|
+
if (isDelimiterLine) {
|
|
284
|
+
ast.delimiterLineBreak = "";
|
|
285
|
+
}
|
|
286
|
+
tagDescriptionSeen ||= Boolean(lastTag && (rawType === "" || (rawType == null ? void 0 : rawType.endsWith("}"))));
|
|
287
|
+
if (lastTag) {
|
|
288
|
+
if (tagDescriptionSeen) {
|
|
289
|
+
const isFirstDescriptionLine = holder.descriptionLines.length === 0;
|
|
290
|
+
if (spacing === "preserve" || spacing === "compact" && (description || isFirstDescriptionLine)) {
|
|
291
|
+
holder.descriptionLines.push({
|
|
292
|
+
delimiter: isFirstDescriptionLine ? "" : delimiter,
|
|
293
|
+
description,
|
|
294
|
+
postDelimiter: isFirstDescriptionLine ? "" : postDelimiter,
|
|
295
|
+
initial: isFirstDescriptionLine ? "" : initial,
|
|
296
|
+
type: "JsdocDescriptionLine"
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
holder.descriptionLines.push({
|
|
302
|
+
delimiter: isDelimiterLine ? "" : delimiter,
|
|
303
|
+
description,
|
|
304
|
+
postDelimiter: isDelimiterLine ? "" : postDelimiter,
|
|
305
|
+
initial: isDelimiterLine ? `` : initial,
|
|
306
|
+
type: "JsdocDescriptionLine"
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (!tag) {
|
|
310
|
+
if (lastTag) {
|
|
311
|
+
if (tagDescriptionSeen && !(spacing === "compact" && description === "" && holder.description)) {
|
|
312
|
+
holder.description += !holder.description ? description : "\n" + description;
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
holder.description += !holder.description ? description : "\n" + description;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (end && tag) {
|
|
320
|
+
ast.terminal = end;
|
|
321
|
+
ast.hasPreterminalTagDescription = 1;
|
|
322
|
+
if (ast.terminal === "*/") {
|
|
323
|
+
ast.preterminalLineBreak = "";
|
|
324
|
+
}
|
|
325
|
+
cleanUpLastTag(
|
|
326
|
+
/** @type {JsdocTag} */
|
|
327
|
+
lastTag
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
ast.lastDescriptionLine = lastDescriptionLine;
|
|
332
|
+
ast.tags = tags;
|
|
333
|
+
return ast;
|
|
334
|
+
};
|
|
335
|
+
var jsdocVisitorKeys = {
|
|
336
|
+
JsdocBlock: ["descriptionLines", "tags", "inlineTags"],
|
|
337
|
+
JsdocDescriptionLine: [],
|
|
338
|
+
JsdocTypeLine: [],
|
|
339
|
+
JsdocTag: ["parsedType", "typeLines", "descriptionLines", "inlineTags"],
|
|
340
|
+
JsdocInlineTag: []
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/commentHandler.js
|
|
344
|
+
var commentHandler = (settings, commentParserToESTreeOptions) => {
|
|
345
|
+
return (commentSelector, jsdoc) => {
|
|
346
|
+
const { mode } = settings;
|
|
347
|
+
const selector = import_esquery.default.parse(commentSelector);
|
|
348
|
+
const ast = commentParserToESTree(
|
|
349
|
+
jsdoc,
|
|
350
|
+
mode,
|
|
351
|
+
commentParserToESTreeOptions
|
|
352
|
+
);
|
|
353
|
+
const castAst = (
|
|
354
|
+
/** @type {unknown} */
|
|
355
|
+
ast
|
|
356
|
+
);
|
|
357
|
+
return import_esquery.default.matches(
|
|
358
|
+
/** @type {import('estree').Node} */
|
|
359
|
+
castAst,
|
|
360
|
+
selector,
|
|
361
|
+
void 0,
|
|
362
|
+
{
|
|
363
|
+
visitorKeys: {
|
|
364
|
+
...import_jsdoc_type_pratt_parser2.visitorKeys,
|
|
365
|
+
...jsdocVisitorKeys
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
);
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/estreeToString.js
|
|
373
|
+
var import_jsdoc_type_pratt_parser3 = require("@cjser/jsdoc-type-pratt-parser");
|
|
374
|
+
|
|
375
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/inlineTagEscapes.js
|
|
376
|
+
function getLabelDelimiter(format) {
|
|
377
|
+
return format === "prefix" ? "]" : "}";
|
|
378
|
+
}
|
|
379
|
+
function decodeInlineTagText(text, format) {
|
|
380
|
+
const delimiter = getLabelDelimiter(format);
|
|
381
|
+
let decoded = "";
|
|
382
|
+
let idx = 0;
|
|
383
|
+
while (idx < text.length) {
|
|
384
|
+
const character = text[idx];
|
|
385
|
+
if (character === "\\") {
|
|
386
|
+
const nextCharacter = text[idx + 1];
|
|
387
|
+
if (nextCharacter === "\\" || nextCharacter === delimiter) {
|
|
388
|
+
decoded += nextCharacter;
|
|
389
|
+
idx += 2;
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
decoded += character;
|
|
394
|
+
idx++;
|
|
395
|
+
}
|
|
396
|
+
return decoded;
|
|
397
|
+
}
|
|
398
|
+
function encodeInlineTagText(text, format) {
|
|
399
|
+
const delimiter = getLabelDelimiter(format);
|
|
400
|
+
let encoded = "";
|
|
401
|
+
for (let idx = 0; idx < text.length; idx++) {
|
|
402
|
+
const character = text[idx];
|
|
403
|
+
if (character === delimiter) {
|
|
404
|
+
encoded += `\\${delimiter}`;
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
if (character === "\\") {
|
|
408
|
+
const nextCharacter = text[idx + 1];
|
|
409
|
+
if ([void 0, "\\", delimiter].includes(nextCharacter)) {
|
|
410
|
+
encoded += "\\\\";
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
encoded += character;
|
|
415
|
+
}
|
|
416
|
+
return encoded;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/estreeToString.js
|
|
420
|
+
var stringifiers = {
|
|
421
|
+
/* eslint-enable jsdoc/reject-function-type -- Different functions */
|
|
422
|
+
JsdocBlock,
|
|
423
|
+
/**
|
|
424
|
+
* @param {import('./commentParserToESTree.js').JsdocDescriptionLine} node
|
|
425
|
+
* @returns {string}
|
|
426
|
+
*/
|
|
427
|
+
JsdocDescriptionLine({
|
|
428
|
+
initial,
|
|
429
|
+
delimiter,
|
|
430
|
+
postDelimiter,
|
|
431
|
+
description
|
|
432
|
+
}) {
|
|
433
|
+
return `${initial}${delimiter}${postDelimiter}${description}`;
|
|
434
|
+
},
|
|
435
|
+
/**
|
|
436
|
+
* @param {import('./commentParserToESTree.js').JsdocTypeLine} node
|
|
437
|
+
* @returns {string}
|
|
438
|
+
*/
|
|
439
|
+
JsdocTypeLine({
|
|
440
|
+
initial,
|
|
441
|
+
delimiter,
|
|
442
|
+
postDelimiter,
|
|
443
|
+
rawType
|
|
444
|
+
}) {
|
|
445
|
+
return `${initial}${delimiter}${postDelimiter}${rawType}`;
|
|
446
|
+
},
|
|
447
|
+
/**
|
|
448
|
+
* @param {import('./commentParserToESTree.js').JsdocInlineTag} node
|
|
449
|
+
*/
|
|
450
|
+
JsdocInlineTag({ format, namepathOrURL, tag, text }) {
|
|
451
|
+
const encodedText = encodeInlineTagText(text, format);
|
|
452
|
+
return format === "pipe" ? `{@${tag} ${namepathOrURL}|${encodedText}}` : format === "plain" ? `{@${tag} ${namepathOrURL}}` : format === "prefix" ? `[${encodedText}]{@${tag} ${namepathOrURL}}` : `{@${tag} ${namepathOrURL} ${encodedText}}`;
|
|
453
|
+
},
|
|
454
|
+
JsdocTag
|
|
455
|
+
};
|
|
456
|
+
function estreeToString(node, opts = {}) {
|
|
457
|
+
if (Object.hasOwn(stringifiers, node.type)) {
|
|
458
|
+
return stringifiers[
|
|
459
|
+
/**
|
|
460
|
+
* @type {import('./commentParserToESTree.js').JsdocBlock|
|
|
461
|
+
* import('./commentParserToESTree.js').JsdocDescriptionLine|
|
|
462
|
+
* import('./commentParserToESTree.js').JsdocTypeLine|
|
|
463
|
+
* import('./commentParserToESTree.js').JsdocTag}
|
|
464
|
+
*/
|
|
465
|
+
node.type
|
|
466
|
+
](
|
|
467
|
+
node,
|
|
468
|
+
opts
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
if (node.type.startsWith("JsdocType")) {
|
|
472
|
+
return opts.preferRawType ? "" : `{${(0, import_jsdoc_type_pratt_parser3.stringify)(
|
|
473
|
+
/** @type {import('@cjser/jsdoc-type-pratt-parser').RootResult} */
|
|
474
|
+
node,
|
|
475
|
+
opts.jtppStringificationRules
|
|
476
|
+
)}}`;
|
|
477
|
+
}
|
|
478
|
+
throw new Error(`Unhandled node type: ${node.type}`);
|
|
479
|
+
}
|
|
480
|
+
function JsdocBlock(node, opts) {
|
|
481
|
+
const {
|
|
482
|
+
delimiter,
|
|
483
|
+
delimiterLineBreak,
|
|
484
|
+
descriptionLines,
|
|
485
|
+
initial,
|
|
486
|
+
postDelimiter,
|
|
487
|
+
preterminalLineBreak,
|
|
488
|
+
tags,
|
|
489
|
+
terminal
|
|
490
|
+
} = node;
|
|
491
|
+
const terminalPrepend = preterminalLineBreak !== "" ? `${preterminalLineBreak}${initial} ` : "";
|
|
492
|
+
let result = `${initial}${delimiter}${postDelimiter}${delimiterLineBreak}`;
|
|
493
|
+
for (let i = 0; i < descriptionLines.length; i++) {
|
|
494
|
+
result += estreeToString(descriptionLines[i]);
|
|
495
|
+
if (i !== descriptionLines.length - 1 || tags.length) {
|
|
496
|
+
result += "\n";
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
for (let i = 0; i < tags.length; i++) {
|
|
500
|
+
result += estreeToString(tags[i], opts);
|
|
501
|
+
if (i !== tags.length - 1) {
|
|
502
|
+
result += "\n";
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
result += `${terminalPrepend}${terminal}`;
|
|
506
|
+
return result;
|
|
507
|
+
}
|
|
508
|
+
function JsdocTag(node, opts) {
|
|
509
|
+
const {
|
|
510
|
+
delimiter,
|
|
511
|
+
descriptionLines,
|
|
512
|
+
initial,
|
|
513
|
+
name,
|
|
514
|
+
parsedType,
|
|
515
|
+
postDelimiter,
|
|
516
|
+
postName,
|
|
517
|
+
postTag,
|
|
518
|
+
postType,
|
|
519
|
+
tag,
|
|
520
|
+
typeLines
|
|
521
|
+
} = node;
|
|
522
|
+
let result = `${initial}${delimiter}${postDelimiter}@${tag}${postTag}`;
|
|
523
|
+
if (!parsedType || opts.preferRawType) {
|
|
524
|
+
if (typeLines.length) {
|
|
525
|
+
result += "{";
|
|
526
|
+
for (let i = 0; i < typeLines.length; i++) {
|
|
527
|
+
result += estreeToString(typeLines[i]);
|
|
528
|
+
if (i !== typeLines.length - 1) {
|
|
529
|
+
result += "\n";
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
result += "}";
|
|
533
|
+
}
|
|
534
|
+
} else if (parsedType == null ? void 0 : parsedType.type.startsWith("JsdocType")) {
|
|
535
|
+
result += `{${(0, import_jsdoc_type_pratt_parser3.stringify)(
|
|
536
|
+
/** @type {import('@cjser/jsdoc-type-pratt-parser').RootResult} */
|
|
537
|
+
parsedType
|
|
538
|
+
)}}`;
|
|
539
|
+
}
|
|
540
|
+
let nameLineOffset = 0;
|
|
541
|
+
if (name && postTag === "" && postType === "") {
|
|
542
|
+
result += "\n";
|
|
543
|
+
if (descriptionLines.length > 0) {
|
|
544
|
+
const firstDescLine = descriptionLines[0];
|
|
545
|
+
if (firstDescLine.description === "" && firstDescLine.delimiter === "" && firstDescLine.postDelimiter === "" && firstDescLine.initial === "") {
|
|
546
|
+
if (descriptionLines.length > 1) {
|
|
547
|
+
const nameLine = descriptionLines[1];
|
|
548
|
+
result += `${nameLine.initial}${nameLine.delimiter}${nameLine.postDelimiter}${name}${postName}${nameLine.description}`;
|
|
549
|
+
nameLineOffset = 2;
|
|
550
|
+
} else {
|
|
551
|
+
result += name + postName;
|
|
552
|
+
nameLineOffset = 1;
|
|
553
|
+
}
|
|
554
|
+
} else {
|
|
555
|
+
const nameLine = descriptionLines[0];
|
|
556
|
+
result += `${nameLine.initial}${nameLine.delimiter}${nameLine.postDelimiter}${name}${postName}${nameLine.description}`;
|
|
557
|
+
nameLineOffset = 1;
|
|
558
|
+
}
|
|
559
|
+
} else {
|
|
560
|
+
result += `${initial}${delimiter}${postDelimiter}${name}${postName}`;
|
|
561
|
+
}
|
|
562
|
+
} else {
|
|
563
|
+
result += name ? `${postType}${name}${postName}` : postType;
|
|
564
|
+
}
|
|
565
|
+
for (let i = nameLineOffset; i < descriptionLines.length; i++) {
|
|
566
|
+
const descriptionLine = descriptionLines[i];
|
|
567
|
+
if (i > 0 || nameLineOffset > 0) {
|
|
568
|
+
result += "\n";
|
|
569
|
+
}
|
|
570
|
+
result += estreeToString(descriptionLine);
|
|
571
|
+
}
|
|
572
|
+
return result;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/jsdoccomment.js
|
|
576
|
+
var isCommentToken = (token) => {
|
|
577
|
+
return ["Line", "Block", "Shebang"].includes(token.type);
|
|
578
|
+
};
|
|
579
|
+
var getDecorator = (node) => {
|
|
580
|
+
var _a, _b, _c, _d, _e;
|
|
581
|
+
return ((_b = (_a = node == null ? void 0 : node.declaration) == null ? void 0 : _a.decorators) == null ? void 0 : _b[0]) || // @ts-expect-error -- Loose checking
|
|
582
|
+
((_c = node == null ? void 0 : node.decorators) == null ? void 0 : _c[0]) || // @ts-expect-error -- Loose checking
|
|
583
|
+
((_e = (_d = node == null ? void 0 : node.parent) == null ? void 0 : _d.decorators) == null ? void 0 : _e[0]);
|
|
584
|
+
};
|
|
585
|
+
var looksLikeExport = function(astNode) {
|
|
586
|
+
return [
|
|
587
|
+
"ExportDefaultDeclaration",
|
|
588
|
+
"ExportNamedDeclaration",
|
|
589
|
+
"ExportAllDeclaration",
|
|
590
|
+
"ExportSpecifier"
|
|
591
|
+
].includes(astNode.type);
|
|
592
|
+
};
|
|
593
|
+
var getTSFunctionComment = function(astNode) {
|
|
594
|
+
const { parent } = astNode;
|
|
595
|
+
if (!parent) {
|
|
596
|
+
return astNode;
|
|
597
|
+
}
|
|
598
|
+
const grandparent = parent.parent;
|
|
599
|
+
if (!grandparent) {
|
|
600
|
+
return astNode;
|
|
601
|
+
}
|
|
602
|
+
if (
|
|
603
|
+
/** @type {ESLintOrTSNode} */
|
|
604
|
+
parent.type !== "TSTypeAnnotation"
|
|
605
|
+
) {
|
|
606
|
+
if (parent.type === "TSTypeAliasDeclaration" && grandparent.type === "ExportNamedDeclaration") {
|
|
607
|
+
return grandparent;
|
|
608
|
+
}
|
|
609
|
+
return astNode;
|
|
610
|
+
}
|
|
611
|
+
const greatGrandparent = grandparent.parent;
|
|
612
|
+
const greatGreatGrandparent = greatGrandparent && greatGrandparent.parent;
|
|
613
|
+
switch (
|
|
614
|
+
/** @type {ESLintOrTSNode} */
|
|
615
|
+
grandparent.type
|
|
616
|
+
) {
|
|
617
|
+
// @ts-expect-error -- For `ClassProperty`.
|
|
618
|
+
case "PropertyDefinition":
|
|
619
|
+
case "ClassProperty":
|
|
620
|
+
case "TSDeclareFunction":
|
|
621
|
+
case "TSMethodSignature":
|
|
622
|
+
case "TSPropertySignature":
|
|
623
|
+
return grandparent;
|
|
624
|
+
case "ArrowFunctionExpression":
|
|
625
|
+
if (!greatGrandparent) {
|
|
626
|
+
return astNode;
|
|
627
|
+
}
|
|
628
|
+
if (greatGrandparent.type === "VariableDeclarator") {
|
|
629
|
+
if (!greatGreatGrandparent || !greatGreatGrandparent.parent) {
|
|
630
|
+
return astNode;
|
|
631
|
+
}
|
|
632
|
+
return greatGreatGrandparent.parent;
|
|
633
|
+
}
|
|
634
|
+
return astNode;
|
|
635
|
+
/* v8 ignore stop */
|
|
636
|
+
case "FunctionExpression":
|
|
637
|
+
if (!greatGreatGrandparent) {
|
|
638
|
+
return astNode;
|
|
639
|
+
}
|
|
640
|
+
if (greatGrandparent.type === "MethodDefinition") {
|
|
641
|
+
return greatGrandparent;
|
|
642
|
+
}
|
|
643
|
+
// Fallthrough
|
|
644
|
+
default:
|
|
645
|
+
if (grandparent.type !== "Identifier") {
|
|
646
|
+
return astNode;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (!greatGreatGrandparent) {
|
|
650
|
+
return astNode;
|
|
651
|
+
}
|
|
652
|
+
switch (greatGrandparent.type) {
|
|
653
|
+
case "ArrowFunctionExpression":
|
|
654
|
+
if (greatGreatGrandparent.type === "VariableDeclarator" && greatGreatGrandparent.parent.type === "VariableDeclaration") {
|
|
655
|
+
return greatGreatGrandparent.parent;
|
|
656
|
+
}
|
|
657
|
+
return astNode;
|
|
658
|
+
case "FunctionDeclaration":
|
|
659
|
+
return greatGrandparent;
|
|
660
|
+
case "VariableDeclarator":
|
|
661
|
+
if (greatGreatGrandparent.type === "VariableDeclaration") {
|
|
662
|
+
return greatGreatGrandparent;
|
|
663
|
+
}
|
|
664
|
+
/* v8 ignore next 2 */
|
|
665
|
+
// Fallthrough
|
|
666
|
+
default:
|
|
667
|
+
return astNode;
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
var invokedExpression = /* @__PURE__ */ new Set(
|
|
671
|
+
["CallExpression", "OptionalCallExpression", "NewExpression"]
|
|
672
|
+
);
|
|
673
|
+
var allowableCommentNode = /* @__PURE__ */ new Set([
|
|
674
|
+
"AssignmentPattern",
|
|
675
|
+
"VariableDeclaration",
|
|
676
|
+
"ExpressionStatement",
|
|
677
|
+
"MethodDefinition",
|
|
678
|
+
"Property",
|
|
679
|
+
"ObjectProperty",
|
|
680
|
+
"ClassProperty",
|
|
681
|
+
"PropertyDefinition",
|
|
682
|
+
"ExportDefaultDeclaration",
|
|
683
|
+
"ReturnStatement"
|
|
684
|
+
]);
|
|
685
|
+
var getReducedASTNode = function(node, sourceCode, settings) {
|
|
686
|
+
let { parent } = node;
|
|
687
|
+
switch (
|
|
688
|
+
/** @type {ESLintOrTSNode} */
|
|
689
|
+
node.type
|
|
690
|
+
) {
|
|
691
|
+
case "TSFunctionType":
|
|
692
|
+
return getTSFunctionComment(node);
|
|
693
|
+
case "TSInterfaceDeclaration":
|
|
694
|
+
case "TSTypeAliasDeclaration":
|
|
695
|
+
case "TSEnumDeclaration":
|
|
696
|
+
case "ClassDeclaration":
|
|
697
|
+
case "FunctionDeclaration":
|
|
698
|
+
if (!parent) {
|
|
699
|
+
return node;
|
|
700
|
+
}
|
|
701
|
+
return looksLikeExport(parent) ? parent : node;
|
|
702
|
+
case "TSDeclareFunction":
|
|
703
|
+
case "ClassExpression":
|
|
704
|
+
case "ObjectExpression":
|
|
705
|
+
case "ArrowFunctionExpression":
|
|
706
|
+
case "TSEmptyBodyFunctionExpression":
|
|
707
|
+
case "FunctionExpression":
|
|
708
|
+
if (!parent) {
|
|
709
|
+
return node;
|
|
710
|
+
}
|
|
711
|
+
if (!invokedExpression.has(parent.type) || (settings == null ? void 0 : settings.skipInvokedExpressionsForCommentFinding)) {
|
|
712
|
+
let token = node;
|
|
713
|
+
do {
|
|
714
|
+
token = sourceCode.getTokenBefore(
|
|
715
|
+
/** @type {import('eslint').Rule.Node|import('eslint').AST.Token} */
|
|
716
|
+
token,
|
|
717
|
+
{ includeComments: true }
|
|
718
|
+
);
|
|
719
|
+
} while (token && token.type === "Punctuator" && token.value === "(");
|
|
720
|
+
if (token && token.type === "Block") {
|
|
721
|
+
return node;
|
|
722
|
+
}
|
|
723
|
+
if (sourceCode.getCommentsBefore(
|
|
724
|
+
/** @type {import('eslint').Rule.Node} */
|
|
725
|
+
node
|
|
726
|
+
).length) {
|
|
727
|
+
return node;
|
|
728
|
+
}
|
|
729
|
+
while (!sourceCode.getCommentsBefore(
|
|
730
|
+
/** @type {import('eslint').Rule.Node} */
|
|
731
|
+
parent
|
|
732
|
+
).length && !new RegExp("Function", "v").test(parent.type) && !allowableCommentNode.has(parent.type)) {
|
|
733
|
+
({ parent } = parent);
|
|
734
|
+
if (!parent) {
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (parent && parent.type !== "FunctionDeclaration" && parent.type !== "Program") {
|
|
739
|
+
if (parent.parent && parent.parent.type === "ExportNamedDeclaration") {
|
|
740
|
+
return parent.parent;
|
|
741
|
+
}
|
|
742
|
+
return parent;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return node;
|
|
746
|
+
default:
|
|
747
|
+
return node;
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
var findJSDocComment = (astNode, sourceCode, settings, opts = {}) => {
|
|
751
|
+
const { nonJSDoc } = opts;
|
|
752
|
+
const { minLines, maxLines } = settings;
|
|
753
|
+
let currentNode = astNode;
|
|
754
|
+
let tokenBefore = null;
|
|
755
|
+
let parenthesisToken = null;
|
|
756
|
+
while (currentNode) {
|
|
757
|
+
const decorator = getDecorator(currentNode);
|
|
758
|
+
if (decorator) {
|
|
759
|
+
const dec = (
|
|
760
|
+
/** @type {unknown} */
|
|
761
|
+
decorator
|
|
762
|
+
);
|
|
763
|
+
currentNode = /** @type {import('eslint').Rule.Node} */
|
|
764
|
+
dec;
|
|
765
|
+
}
|
|
766
|
+
tokenBefore = sourceCode.getTokenBefore(
|
|
767
|
+
/** @type {import('eslint').Rule.Node} */
|
|
768
|
+
currentNode,
|
|
769
|
+
{ includeComments: true }
|
|
770
|
+
);
|
|
771
|
+
if (tokenBefore && tokenBefore.type === "Punctuator" && tokenBefore.value === "(") {
|
|
772
|
+
parenthesisToken = tokenBefore;
|
|
773
|
+
[tokenBefore] = sourceCode.getTokensBefore(
|
|
774
|
+
/** @type {import('eslint').Rule.Node} */
|
|
775
|
+
currentNode,
|
|
776
|
+
{
|
|
777
|
+
count: 2,
|
|
778
|
+
includeComments: true
|
|
779
|
+
}
|
|
780
|
+
);
|
|
781
|
+
}
|
|
782
|
+
if (!tokenBefore || !isCommentToken(tokenBefore)) {
|
|
783
|
+
return null;
|
|
784
|
+
}
|
|
785
|
+
if (!nonJSDoc && tokenBefore.type === "Line") {
|
|
786
|
+
currentNode = tokenBefore;
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
791
|
+
if (!tokenBefore || !currentNode.loc || !tokenBefore.loc) {
|
|
792
|
+
return null;
|
|
793
|
+
}
|
|
794
|
+
if ((nonJSDoc && (tokenBefore.type !== "Block" || !new RegExp("^\\*\\s", "v").test(tokenBefore.value)) || !nonJSDoc && tokenBefore.type === "Block" && new RegExp("^\\*\\s", "v").test(tokenBefore.value)) && currentNode.loc.start.line - /** @type {import('eslint').AST.Token} */
|
|
795
|
+
(parenthesisToken ?? tokenBefore).loc.end.line >= minLines && currentNode.loc.start.line - /** @type {import('eslint').AST.Token} */
|
|
796
|
+
(parenthesisToken ?? tokenBefore).loc.end.line <= maxLines) {
|
|
797
|
+
return tokenBefore;
|
|
798
|
+
}
|
|
799
|
+
return null;
|
|
800
|
+
};
|
|
801
|
+
var overloadMethodNode = /* @__PURE__ */ new Set([
|
|
802
|
+
"MethodDefinition",
|
|
803
|
+
"TSAbstractMethodDefinition"
|
|
804
|
+
]);
|
|
805
|
+
var getOverloadStatementSiblings = (node) => {
|
|
806
|
+
if (node && // eslint-disable-next-line @stylistic/max-len -- Long
|
|
807
|
+
// eslint-disable-next-line unicorn/prefer-includes-over-repeated-comparisons -- TS
|
|
808
|
+
(node.type === "BlockStatement" || node.type === "Program" || node.type === "StaticBlock" || node.type === "TSModuleBlock")) {
|
|
809
|
+
return (
|
|
810
|
+
/** @type {ESLintOrTSNode[]} */
|
|
811
|
+
node.body
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
return void 0;
|
|
815
|
+
};
|
|
816
|
+
var getMethodOverloadInfo = (node) => {
|
|
817
|
+
var _a, _b;
|
|
818
|
+
if (!overloadMethodNode.has(node.type)) {
|
|
819
|
+
return null;
|
|
820
|
+
}
|
|
821
|
+
const method = node;
|
|
822
|
+
if (method.computed || !method.kind || !["method", "constructor"].includes(
|
|
823
|
+
/** @type {string} */
|
|
824
|
+
method.kind
|
|
825
|
+
) || !((_a = method.key) == null ? void 0 : _a.name)) {
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
return {
|
|
829
|
+
bodyless: node.type === "TSAbstractMethodDefinition" || ((_b = method.value) == null ? void 0 : _b.type) === "TSEmptyBodyFunctionExpression",
|
|
830
|
+
kind: method.kind,
|
|
831
|
+
name: method.key.name,
|
|
832
|
+
static: Boolean(method.static)
|
|
833
|
+
};
|
|
834
|
+
};
|
|
835
|
+
var isMatchingMethodOverloadSibling = (node, prevSibling) => {
|
|
836
|
+
const current = getMethodOverloadInfo(node);
|
|
837
|
+
const previous = getMethodOverloadInfo(prevSibling);
|
|
838
|
+
return Boolean(
|
|
839
|
+
current && (previous == null ? void 0 : previous.bodyless) && previous.name === current.name && previous.kind === current.kind && previous.static === current.static
|
|
840
|
+
);
|
|
841
|
+
};
|
|
842
|
+
var getCurrentOverloadName = (node) => {
|
|
843
|
+
var _a, _b, _c;
|
|
844
|
+
if (node.type === "TSDeclareFunction" || node.type === "FunctionDeclaration") {
|
|
845
|
+
return (
|
|
846
|
+
/** @type {{id?: {name?: string}}} */
|
|
847
|
+
(_a = node.id) == null ? void 0 : _a.name
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
851
|
+
const { declaration } = (
|
|
852
|
+
/** @type {{declaration?: {type?: string, id?: {name?: string}}}} */
|
|
853
|
+
node
|
|
854
|
+
);
|
|
855
|
+
if ((declaration == null ? void 0 : declaration.type) === "FunctionDeclaration" || (declaration == null ? void 0 : declaration.type) === "TSDeclareFunction") {
|
|
856
|
+
return (_b = declaration.id) == null ? void 0 : _b.name;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
if (overloadMethodNode.has(node.type)) {
|
|
860
|
+
const method = (
|
|
861
|
+
/** @type {{computed?: boolean, key?: {name?: string}}} */
|
|
862
|
+
node
|
|
863
|
+
);
|
|
864
|
+
if (!method.computed) {
|
|
865
|
+
return (_c = method.key) == null ? void 0 : _c.name;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
return void 0;
|
|
869
|
+
};
|
|
870
|
+
var getPreviousOverloadName = (node) => {
|
|
871
|
+
var _a, _b, _c;
|
|
872
|
+
if (node.type === "TSDeclareFunction") {
|
|
873
|
+
return (
|
|
874
|
+
/** @type {{id?: {name?: string}}} */
|
|
875
|
+
(_a = node.id) == null ? void 0 : _a.name
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
879
|
+
const { declaration } = (
|
|
880
|
+
/** @type {{declaration?: {type?: string, id?: {name?: string}}}} */
|
|
881
|
+
node
|
|
882
|
+
);
|
|
883
|
+
if ((declaration == null ? void 0 : declaration.type) === "TSDeclareFunction") {
|
|
884
|
+
return (_b = declaration.id) == null ? void 0 : _b.name;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
if (overloadMethodNode.has(node.type)) {
|
|
888
|
+
const method = (
|
|
889
|
+
/** @type {{computed?: boolean, key?: {name?: string}}} */
|
|
890
|
+
node
|
|
891
|
+
);
|
|
892
|
+
if (!method.computed) {
|
|
893
|
+
return (_c = method.key) == null ? void 0 : _c.name;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return void 0;
|
|
897
|
+
};
|
|
898
|
+
var getPreviousOverloadSibling = (node) => {
|
|
899
|
+
const { parent } = node;
|
|
900
|
+
let childNode = node;
|
|
901
|
+
let siblings;
|
|
902
|
+
if (overloadMethodNode.has(node.type) && (parent == null ? void 0 : parent.type) === "ClassBody") {
|
|
903
|
+
siblings = /** @type {ESLintOrTSNode[]} */
|
|
904
|
+
parent.body;
|
|
905
|
+
} else if ((parent == null ? void 0 : parent.type) === "ExportNamedDeclaration") {
|
|
906
|
+
childNode = parent;
|
|
907
|
+
siblings = getOverloadStatementSiblings(parent.parent);
|
|
908
|
+
} else {
|
|
909
|
+
siblings = getOverloadStatementSiblings(parent);
|
|
910
|
+
}
|
|
911
|
+
if (!siblings) {
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
const idx = siblings.indexOf(childNode);
|
|
915
|
+
return idx > 0 ? siblings[idx - 1] : null;
|
|
916
|
+
};
|
|
917
|
+
var getJSDocComment = function(sourceCode, node, settings, opts = {}) {
|
|
918
|
+
const reducedNode = getReducedASTNode(node, sourceCode, settings);
|
|
919
|
+
const comment = findJSDocComment(reducedNode, sourceCode, settings);
|
|
920
|
+
if (!comment && opts.checkOverloads) {
|
|
921
|
+
const functionName = getCurrentOverloadName(reducedNode);
|
|
922
|
+
const prevSibling = getPreviousOverloadSibling(reducedNode);
|
|
923
|
+
if (prevSibling && functionName && getPreviousOverloadName(prevSibling) === functionName && (!overloadMethodNode.has(reducedNode.type) || isMatchingMethodOverloadSibling(reducedNode, prevSibling))) {
|
|
924
|
+
return getJSDocComment(sourceCode, prevSibling, settings, opts);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
return comment;
|
|
928
|
+
};
|
|
929
|
+
var getNonJsdocComment = function(sourceCode, node, settings) {
|
|
930
|
+
const reducedNode = getReducedASTNode(node, sourceCode, settings);
|
|
931
|
+
return findJSDocComment(reducedNode, sourceCode, settings, {
|
|
932
|
+
nonJSDoc: true
|
|
933
|
+
});
|
|
934
|
+
};
|
|
935
|
+
var compareLocEndToStart = (nodeA, nodeB) => {
|
|
936
|
+
var _a, _b;
|
|
937
|
+
return (((_a = nodeA.loc) == null ? void 0 : _a.end.line) ?? 0) === (((_b = nodeB.loc) == null ? void 0 : _b.start.line) ?? 0);
|
|
938
|
+
};
|
|
939
|
+
var getFollowingComment = function(sourceCode, astNode) {
|
|
940
|
+
const getTokensAfterIgnoringSemis = (node) => {
|
|
941
|
+
let tokenAfter2 = sourceCode.getTokenAfter(
|
|
942
|
+
/** @type {import('eslint').Rule.Node} */
|
|
943
|
+
node,
|
|
944
|
+
{ includeComments: true }
|
|
945
|
+
);
|
|
946
|
+
while (tokenAfter2 && tokenAfter2.type === "Punctuator" && // tokenAfter.value === ')' // Don't apparently need to ignore
|
|
947
|
+
tokenAfter2.value === ";") {
|
|
948
|
+
[tokenAfter2] = sourceCode.getTokensAfter(tokenAfter2, {
|
|
949
|
+
includeComments: true
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
return tokenAfter2;
|
|
953
|
+
};
|
|
954
|
+
const tokenAfterIgnoringSemis = (node) => {
|
|
955
|
+
const tokenAfter2 = getTokensAfterIgnoringSemis(node);
|
|
956
|
+
return tokenAfter2 && isCommentToken(tokenAfter2) && compareLocEndToStart(node, tokenAfter2) ? tokenAfter2 : null;
|
|
957
|
+
};
|
|
958
|
+
let tokenAfter = tokenAfterIgnoringSemis(astNode);
|
|
959
|
+
if (!tokenAfter) {
|
|
960
|
+
switch (astNode.type) {
|
|
961
|
+
case "FunctionDeclaration":
|
|
962
|
+
tokenAfter = tokenAfterIgnoringSemis(
|
|
963
|
+
/** @type {ESLintOrTSNode} */
|
|
964
|
+
astNode.body
|
|
965
|
+
);
|
|
966
|
+
break;
|
|
967
|
+
case "ExpressionStatement":
|
|
968
|
+
tokenAfter = tokenAfterIgnoringSemis(
|
|
969
|
+
/** @type {ESLintOrTSNode} */
|
|
970
|
+
astNode.expression
|
|
971
|
+
);
|
|
972
|
+
break;
|
|
973
|
+
/* v8 ignore next 3 */
|
|
974
|
+
default:
|
|
975
|
+
break;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return tokenAfter;
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/parseComment.js
|
|
982
|
+
var import_comment_parser = require("comment-parser");
|
|
983
|
+
|
|
984
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/parseInlineTags.js
|
|
985
|
+
function determineFormat(match) {
|
|
986
|
+
const { separator, text } = match.groups;
|
|
987
|
+
const [, textEnd] = match.indices.groups.text;
|
|
988
|
+
const [tagStart] = match.indices.groups.tag;
|
|
989
|
+
if (!text) {
|
|
990
|
+
return "plain";
|
|
991
|
+
}
|
|
992
|
+
if (separator === "|") {
|
|
993
|
+
return "pipe";
|
|
994
|
+
}
|
|
995
|
+
if (textEnd < tagStart) {
|
|
996
|
+
return "prefix";
|
|
997
|
+
}
|
|
998
|
+
return "space";
|
|
999
|
+
}
|
|
1000
|
+
function parseDescription(description) {
|
|
1001
|
+
const result = [];
|
|
1002
|
+
const prefixedTextPattern = new RegExp("(?:\\[(?<text>(?:[^\\\\\\]]|\\\\[\\s\\S])+)\\])\\{@(?<tag>[^\\}\\s]+)\\s?(?<namepathOrURL>[^\\}\\s\\|]*)\\}", "gvd");
|
|
1003
|
+
const suffixedAfterPattern = new RegExp("(?<!\\])\\{@(?<tag>[^\\}\\s]+)\\s?(?<namepathOrURL>[^\\}\\s\\|]*)\\s*(?<separator>[\\s\\|])?\\s*(?<text>(?:[^\\\\\\}]|\\\\[\\s\\S])*)\\}", "gvd");
|
|
1004
|
+
const matches = [
|
|
1005
|
+
...description.matchAll(prefixedTextPattern),
|
|
1006
|
+
...description.matchAll(suffixedAfterPattern)
|
|
1007
|
+
];
|
|
1008
|
+
for (const mtch of matches) {
|
|
1009
|
+
const match = (
|
|
1010
|
+
/**
|
|
1011
|
+
* @type {RegExpMatchArray & {
|
|
1012
|
+
* indices: {
|
|
1013
|
+
* groups: {
|
|
1014
|
+
* [key: string]: [number, number]
|
|
1015
|
+
* }
|
|
1016
|
+
* }
|
|
1017
|
+
* groups: {[key: string]: string}
|
|
1018
|
+
* }}
|
|
1019
|
+
*/
|
|
1020
|
+
mtch
|
|
1021
|
+
);
|
|
1022
|
+
const { tag, namepathOrURL, text } = match.groups;
|
|
1023
|
+
const [start, end] = match.indices[0];
|
|
1024
|
+
const format = determineFormat(match);
|
|
1025
|
+
const decodedText = decodeInlineTagText(text, format);
|
|
1026
|
+
result.push({
|
|
1027
|
+
tag,
|
|
1028
|
+
namepathOrURL,
|
|
1029
|
+
text: decodedText,
|
|
1030
|
+
format,
|
|
1031
|
+
start,
|
|
1032
|
+
end
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
return result;
|
|
1036
|
+
}
|
|
1037
|
+
function parseInlineTags(block) {
|
|
1038
|
+
const inlineTags = (
|
|
1039
|
+
/**
|
|
1040
|
+
* @type {(import('./commentParserToESTree.js').JsdocInlineTagNoType & {
|
|
1041
|
+
* line?: import('./commentParserToESTree.js').Integer
|
|
1042
|
+
* })[]}
|
|
1043
|
+
*/
|
|
1044
|
+
parseDescription(block.description)
|
|
1045
|
+
);
|
|
1046
|
+
block.inlineTags = inlineTags;
|
|
1047
|
+
for (const tag of block.tags) {
|
|
1048
|
+
tag.inlineTags = parseDescription(tag.description);
|
|
1049
|
+
}
|
|
1050
|
+
return (
|
|
1051
|
+
/**
|
|
1052
|
+
* @type {import('./index.js').JsdocBlockWithInline}
|
|
1053
|
+
*/
|
|
1054
|
+
block
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// packages/@cjser/es-joy__jsdoccomment.tmp-26-1788540365480/src/parseComment.js
|
|
1059
|
+
var {
|
|
1060
|
+
name: nameTokenizer,
|
|
1061
|
+
tag: tagTokenizer,
|
|
1062
|
+
type: typeTokenizer,
|
|
1063
|
+
description: descriptionTokenizer
|
|
1064
|
+
} = import_comment_parser.tokenizers;
|
|
1065
|
+
var hasSeeWithLink = (spec) => {
|
|
1066
|
+
return spec.tag === "see" && new RegExp("\\{@link.+?\\}", "v").test(spec.source[0].source);
|
|
1067
|
+
};
|
|
1068
|
+
var defaultNoTypes = [
|
|
1069
|
+
"default",
|
|
1070
|
+
"defaultvalue",
|
|
1071
|
+
"description",
|
|
1072
|
+
"example",
|
|
1073
|
+
"file",
|
|
1074
|
+
"fileoverview",
|
|
1075
|
+
"license",
|
|
1076
|
+
"overview",
|
|
1077
|
+
"see",
|
|
1078
|
+
"summary"
|
|
1079
|
+
];
|
|
1080
|
+
var defaultNoNames = [
|
|
1081
|
+
"access",
|
|
1082
|
+
"author",
|
|
1083
|
+
"default",
|
|
1084
|
+
"defaultvalue",
|
|
1085
|
+
"description",
|
|
1086
|
+
"example",
|
|
1087
|
+
"exception",
|
|
1088
|
+
"file",
|
|
1089
|
+
"fileoverview",
|
|
1090
|
+
"kind",
|
|
1091
|
+
"license",
|
|
1092
|
+
"overview",
|
|
1093
|
+
"return",
|
|
1094
|
+
"returns",
|
|
1095
|
+
"since",
|
|
1096
|
+
"summary",
|
|
1097
|
+
"throws",
|
|
1098
|
+
"version",
|
|
1099
|
+
"variation"
|
|
1100
|
+
];
|
|
1101
|
+
var optionalBrackets = new RegExp("^\\[(?<name>[^=]*)=[^\\]]*\\]", "v");
|
|
1102
|
+
var preserveTypeTokenizer = typeTokenizer("preserve");
|
|
1103
|
+
var preserveDescriptionTokenizer = descriptionTokenizer("preserve");
|
|
1104
|
+
var plainNameTokenizer = nameTokenizer();
|
|
1105
|
+
var getTokenizers = ({
|
|
1106
|
+
noTypes = defaultNoTypes,
|
|
1107
|
+
noNames = defaultNoNames
|
|
1108
|
+
} = {}) => {
|
|
1109
|
+
return [
|
|
1110
|
+
// Tag
|
|
1111
|
+
tagTokenizer(),
|
|
1112
|
+
/**
|
|
1113
|
+
* Type tokenizer.
|
|
1114
|
+
* @param {import('comment-parser').Spec} spec
|
|
1115
|
+
* @returns {import('comment-parser').Spec}
|
|
1116
|
+
*/
|
|
1117
|
+
(spec) => {
|
|
1118
|
+
if (noTypes.includes(spec.tag)) {
|
|
1119
|
+
return spec;
|
|
1120
|
+
}
|
|
1121
|
+
return preserveTypeTokenizer(spec);
|
|
1122
|
+
},
|
|
1123
|
+
/**
|
|
1124
|
+
* Name tokenizer.
|
|
1125
|
+
* @param {import('comment-parser').Spec} spec
|
|
1126
|
+
* @returns {import('comment-parser').Spec}
|
|
1127
|
+
*/
|
|
1128
|
+
(spec) => {
|
|
1129
|
+
if (spec.tag === "template") {
|
|
1130
|
+
const remainder = spec.source[0].tokens.description;
|
|
1131
|
+
let pos;
|
|
1132
|
+
if (remainder.startsWith("[") && remainder.includes("]")) {
|
|
1133
|
+
const endingBracketPos = remainder.lastIndexOf("]");
|
|
1134
|
+
pos = remainder.slice(endingBracketPos).search(new RegExp("(?<![\\s,])\\s", "v"));
|
|
1135
|
+
if (pos > -1) {
|
|
1136
|
+
pos += endingBracketPos;
|
|
1137
|
+
}
|
|
1138
|
+
} else {
|
|
1139
|
+
pos = remainder.search(new RegExp("(?<![\\s,])\\s", "v"));
|
|
1140
|
+
}
|
|
1141
|
+
const name = pos === -1 ? remainder : remainder.slice(0, pos);
|
|
1142
|
+
const extra = remainder.slice(pos);
|
|
1143
|
+
let postName = "", description = "", lineEnd = "";
|
|
1144
|
+
if (pos > -1) {
|
|
1145
|
+
[, postName, description, lineEnd] = /** @type {RegExpMatchArray} */
|
|
1146
|
+
extra.match(new RegExp("(\\s*)([^\\r]*)(\\r)?", "v"));
|
|
1147
|
+
}
|
|
1148
|
+
spec.optional = optionalBrackets.test(name);
|
|
1149
|
+
spec.name = name;
|
|
1150
|
+
const { tokens } = spec.source[0];
|
|
1151
|
+
tokens.name = name;
|
|
1152
|
+
tokens.postName = postName;
|
|
1153
|
+
tokens.description = description;
|
|
1154
|
+
tokens.lineEnd = lineEnd || "";
|
|
1155
|
+
return spec;
|
|
1156
|
+
}
|
|
1157
|
+
if (noNames.includes(spec.tag) || hasSeeWithLink(spec)) {
|
|
1158
|
+
return spec;
|
|
1159
|
+
}
|
|
1160
|
+
return plainNameTokenizer(spec);
|
|
1161
|
+
},
|
|
1162
|
+
/**
|
|
1163
|
+
* Description tokenizer.
|
|
1164
|
+
* @param {import('comment-parser').Spec} spec
|
|
1165
|
+
* @returns {import('comment-parser').Spec}
|
|
1166
|
+
*/
|
|
1167
|
+
(spec) => {
|
|
1168
|
+
return preserveDescriptionTokenizer(spec);
|
|
1169
|
+
}
|
|
1170
|
+
];
|
|
1171
|
+
};
|
|
1172
|
+
var parseComment = (commentOrNode, indent = "") => {
|
|
1173
|
+
let result;
|
|
1174
|
+
switch (typeof commentOrNode) {
|
|
1175
|
+
case "string":
|
|
1176
|
+
result = (0, import_comment_parser.parse)(`${indent}${commentOrNode}`, {
|
|
1177
|
+
// @see https://github.com/yavorskiy/comment-parser/issues/21
|
|
1178
|
+
tokenizers: getTokenizers()
|
|
1179
|
+
});
|
|
1180
|
+
break;
|
|
1181
|
+
case "object":
|
|
1182
|
+
if (commentOrNode === null) {
|
|
1183
|
+
throw new TypeError(`'commentOrNode' is not a string or object.`);
|
|
1184
|
+
}
|
|
1185
|
+
result = (0, import_comment_parser.parse)(`${indent}/*${commentOrNode.value}*/`, {
|
|
1186
|
+
// @see https://github.com/yavorskiy/comment-parser/issues/21
|
|
1187
|
+
tokenizers: getTokenizers()
|
|
1188
|
+
});
|
|
1189
|
+
break;
|
|
1190
|
+
default:
|
|
1191
|
+
throw new TypeError(`'commentOrNode' is not a string or object.`);
|
|
1192
|
+
}
|
|
1193
|
+
if (!result.length) {
|
|
1194
|
+
throw new Error("There were no results for comment parsing");
|
|
1195
|
+
}
|
|
1196
|
+
const [block] = result;
|
|
1197
|
+
return parseInlineTags(block);
|
|
1198
|
+
};
|
|
1199
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1200
|
+
0 && (module.exports = {
|
|
1201
|
+
commentHandler,
|
|
1202
|
+
commentParserToESTree,
|
|
1203
|
+
defaultNoNames,
|
|
1204
|
+
defaultNoTypes,
|
|
1205
|
+
estreeToString,
|
|
1206
|
+
findJSDocComment,
|
|
1207
|
+
getDecorator,
|
|
1208
|
+
getFollowingComment,
|
|
1209
|
+
getJSDocComment,
|
|
1210
|
+
getNonJsdocComment,
|
|
1211
|
+
getReducedASTNode,
|
|
1212
|
+
getTokenizers,
|
|
1213
|
+
hasSeeWithLink,
|
|
1214
|
+
jsdocTypeVisitorKeys,
|
|
1215
|
+
jsdocVisitorKeys,
|
|
1216
|
+
parseComment,
|
|
1217
|
+
parseInlineTags,
|
|
1218
|
+
...require("@cjser/jsdoc-type-pratt-parser")
|
|
1219
|
+
});
|
|
1220
|
+
/**
|
|
1221
|
+
* Obtained originally from {@link https://github.com/eslint/eslint/blob/master/lib/util/source-code.js#L313}.
|
|
1222
|
+
*
|
|
1223
|
+
* @license MIT
|
|
1224
|
+
*/
|