@cjser/jsdoc-type-pratt-parser 9.1.1-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.
@@ -0,0 +1,3027 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // packages/@cjser/jsdoc-type-pratt-parser.tmp-26-1786640272890/dist/index.mjs
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ catharsisTransform: () => catharsisTransform,
23
+ identityTransformRules: () => identityTransformRules,
24
+ jtpTransform: () => jtpTransform,
25
+ parse: () => parse,
26
+ parseName: () => parseName,
27
+ parseNamePath: () => parseNamePath,
28
+ stringify: () => stringify,
29
+ stringifyRules: () => stringifyRules,
30
+ transform: () => transform,
31
+ traverse: () => traverse,
32
+ tryParse: () => tryParse,
33
+ visitorKeys: () => visitorKeys
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ function tokenToString(token) {
37
+ if (token.text !== void 0 && token.text !== "") return `'${token.type}' with value '${token.text}'`;
38
+ else return `'${token.type}'`;
39
+ }
40
+ var NoParsletFoundError = class NoParsletFoundError2 extends Error {
41
+ token;
42
+ constructor(token) {
43
+ super(`No parslet found for token: ${tokenToString(token)}`);
44
+ this.token = token;
45
+ Object.setPrototypeOf(this, NoParsletFoundError2.prototype);
46
+ }
47
+ getToken() {
48
+ return this.token;
49
+ }
50
+ };
51
+ var EarlyEndOfParseError = class EarlyEndOfParseError2 extends Error {
52
+ token;
53
+ constructor(token) {
54
+ super(`The parsing ended early. The next token was: ${tokenToString(token)}`);
55
+ this.token = token;
56
+ Object.setPrototypeOf(this, EarlyEndOfParseError2.prototype);
57
+ }
58
+ getToken() {
59
+ return this.token;
60
+ }
61
+ };
62
+ var UnexpectedTypeError = class UnexpectedTypeError2 extends Error {
63
+ constructor(result, message) {
64
+ let error = `Unexpected type: '${result.type}'.`;
65
+ if (message !== void 0) error += ` Message: ${message}`;
66
+ super(error);
67
+ Object.setPrototypeOf(this, UnexpectedTypeError2.prototype);
68
+ }
69
+ };
70
+ var baseNameTokens = [
71
+ "module",
72
+ "keyof",
73
+ "event",
74
+ "external",
75
+ "readonly",
76
+ "is",
77
+ "typeof",
78
+ "in",
79
+ "null",
80
+ "undefined",
81
+ "function",
82
+ "asserts",
83
+ "infer",
84
+ "extends",
85
+ "import"
86
+ ];
87
+ var reservedWordsAsRootTSTypes = [
88
+ "false",
89
+ "null",
90
+ "true",
91
+ "void"
92
+ ];
93
+ [...reservedWordsAsRootTSTypes];
94
+ var reservedWords$1 = {
95
+ always: [
96
+ "break",
97
+ "case",
98
+ "catch",
99
+ "class",
100
+ "const",
101
+ "continue",
102
+ "debugger",
103
+ "default",
104
+ "delete",
105
+ "do",
106
+ "else",
107
+ "export",
108
+ "extends",
109
+ "false",
110
+ "finally",
111
+ "for",
112
+ "function",
113
+ "if",
114
+ "import",
115
+ "in",
116
+ "instanceof",
117
+ "new",
118
+ "null",
119
+ "return",
120
+ "super",
121
+ "switch",
122
+ "this",
123
+ "throw",
124
+ "true",
125
+ "try",
126
+ "typeof",
127
+ "var",
128
+ "void",
129
+ "while",
130
+ "with"
131
+ ],
132
+ strictMode: [
133
+ "let",
134
+ "static",
135
+ "yield"
136
+ ],
137
+ moduleOrAsyncFunctionBodies: ["await"]
138
+ };
139
+ var futureReservedWords = {
140
+ always: ["enum"],
141
+ strictMode: [
142
+ "implements",
143
+ "interface",
144
+ "package",
145
+ "private",
146
+ "protected",
147
+ "public"
148
+ ]
149
+ };
150
+ var strictModeNonIdentifiers = ["arguments", "eval"];
151
+ function assertResultIsNotReservedWord(parser, result) {
152
+ let text;
153
+ if (result.type === "JsdocTypeName") text = result.value;
154
+ else if (result.type === "JsdocTypeParenthesis") {
155
+ let res = result;
156
+ while (res.type === "JsdocTypeParenthesis") res = res.element;
157
+ if (res.type === "JsdocTypeName") text = res.value;
158
+ else return result;
159
+ } else return result;
160
+ if (reservedWords$1.always.includes(text) && !reservedWordsAsRootTSTypes.includes(text) && (text !== "this" || parser.classContext !== true)) throw new Error(`Unexpected reserved keyword "${text}"`);
161
+ if (futureReservedWords.always.includes(text)) throw new Error(`Unexpected future reserved keyword "${text}"`);
162
+ if (parser.module !== void 0 && parser.module || parser.strictMode !== void 0 && parser.strictMode) {
163
+ if (reservedWords$1.strictMode.includes(text)) throw new Error(`Unexpected reserved keyword "${text}" for strict mode`);
164
+ if (futureReservedWords.strictMode.includes(text)) throw new Error(`Unexpected future reserved keyword "${text}" for strict mode`);
165
+ if (strictModeNonIdentifiers.includes(text)) throw new Error(`The item "${text}" is not an identifier in strict mode`);
166
+ }
167
+ if (parser.module !== void 0 && parser.module || parser.asyncFunctionBody !== void 0 && parser.asyncFunctionBody) {
168
+ if (reservedWords$1.moduleOrAsyncFunctionBodies.includes(text)) throw new Error(`Unexpected reserved keyword "${text}" for modules or async function bodies`);
169
+ }
170
+ return result;
171
+ }
172
+ function assertRootResult(result) {
173
+ if (result === void 0) throw new Error("Unexpected undefined");
174
+ if (result.type === "JsdocTypeKeyValue" || result.type === "JsdocTypeParameterList" || result.type === "JsdocTypeProperty" || result.type === "JsdocTypeReadonlyProperty" || result.type === "JsdocTypeObjectField" || result.type === "JsdocTypeJsdocObjectField" || result.type === "JsdocTypeIndexSignature" || result.type === "JsdocTypeMappedType" || result.type === "JsdocTypeTypeParameter" || result.type === "JsdocTypeCallSignature" || result.type === "JsdocTypeConstructorSignature" || result.type === "JsdocTypeMethodSignature" || result.type === "JsdocTypeIndexedAccessIndex" || result.type === "JsdocTypeComputedProperty" || result.type === "JsdocTypeComputedMethod") throw new UnexpectedTypeError(result);
175
+ return result;
176
+ }
177
+ function assertPlainKeyValueOrRootResult(result) {
178
+ if (result.type === "JsdocTypeKeyValue") return assertPlainKeyValueResult(result);
179
+ return assertRootResult(result);
180
+ }
181
+ function assertPlainKeyValueOrNameResult(result) {
182
+ if (result.type === "JsdocTypeName") return result;
183
+ return assertPlainKeyValueResult(result);
184
+ }
185
+ function assertPlainKeyValueResult(result) {
186
+ if (result.type !== "JsdocTypeKeyValue") throw new UnexpectedTypeError(result);
187
+ return result;
188
+ }
189
+ function assertNumberOrVariadicNameResult(result) {
190
+ var _a;
191
+ if (result.type === "JsdocTypeVariadic") {
192
+ if (((_a = result.element) == null ? void 0 : _a.type) === "JsdocTypeName") return result;
193
+ throw new UnexpectedTypeError(result);
194
+ }
195
+ if (result.type !== "JsdocTypeNumber" && result.type !== "JsdocTypeName") throw new UnexpectedTypeError(result);
196
+ return result;
197
+ }
198
+ function assertArrayOrTupleResult(result) {
199
+ if (result.type === "JsdocTypeTuple") return result;
200
+ if (result.type === "JsdocTypeGeneric" && result.meta.brackets === "square") return result;
201
+ throw new UnexpectedTypeError(result);
202
+ }
203
+ function isSquaredProperty(result) {
204
+ return result.type === "JsdocTypeIndexSignature" || result.type === "JsdocTypeMappedType";
205
+ }
206
+ var Parser = class {
207
+ grammar;
208
+ _lexer;
209
+ baseParser;
210
+ externalParsers;
211
+ module;
212
+ strictMode;
213
+ asyncFunctionBody;
214
+ classContext;
215
+ rangeStart;
216
+ range;
217
+ locStart;
218
+ loc;
219
+ constructor(grammar, lexer, baseParser, { module: module2, strictMode, asyncFunctionBody, classContext, range = false, rangeStart = 0, loc = false, locStart = {
220
+ line: 1,
221
+ column: 0
222
+ }, externalParsers } = {}) {
223
+ this.grammar = grammar;
224
+ this._lexer = lexer;
225
+ this.baseParser = baseParser;
226
+ this.externalParsers = externalParsers;
227
+ this.module = module2;
228
+ this.strictMode = strictMode;
229
+ this.asyncFunctionBody = asyncFunctionBody;
230
+ this.classContext = classContext;
231
+ this.rangeStart = rangeStart;
232
+ this.range = range;
233
+ this.locStart = locStart;
234
+ this.loc = loc;
235
+ }
236
+ get lexer() {
237
+ return this._lexer;
238
+ }
239
+ /**
240
+ * Parses a given string and throws an error if the parse ended before the end of the string.
241
+ */
242
+ parse() {
243
+ const result = this.parseType(0);
244
+ if (this.lexer.current.type !== "EOF") throw new EarlyEndOfParseError(this.lexer.current);
245
+ return result;
246
+ }
247
+ /**
248
+ * Parses with the current lexer and asserts that the result is a {@link RootResult}.
249
+ */
250
+ parseType(precedence) {
251
+ return assertRootResult(this.parseIntermediateType(precedence));
252
+ }
253
+ /**
254
+ * The main parsing function. First it tries to parse the current state in the prefix step, and then it continues
255
+ * to parse the state in the infix step.
256
+ */
257
+ parseIntermediateType(precedence) {
258
+ const result = this.tryParslets(null, precedence);
259
+ if (result === null) throw new NoParsletFoundError(this.lexer.current);
260
+ return this.parseInfixIntermediateType(result, precedence);
261
+ }
262
+ /**
263
+ * In the infix parsing step the parser continues to parse the current state with all parslets until none returns
264
+ * a result.
265
+ */
266
+ parseInfixIntermediateType(left, precedence) {
267
+ let result = this.tryParslets(left, precedence);
268
+ while (result !== null) {
269
+ left = result;
270
+ result = this.tryParslets(left, precedence);
271
+ }
272
+ return left;
273
+ }
274
+ /**
275
+ * Tries to parse the current state with all parslets in the grammar and returns the first non null result.
276
+ */
277
+ tryParslets(left, precedence) {
278
+ for (const parslet of this.grammar) {
279
+ const rangeStart = this.rangeStart;
280
+ const locStartLine = this.locStart.line;
281
+ const locStartColumn = this.locStart.column;
282
+ const result = parslet(this, precedence, left);
283
+ if (result !== null) {
284
+ if (this.range) result.range = [rangeStart, this.rangeStart];
285
+ if (this.loc) result.loc = {
286
+ end: {
287
+ line: this.locStart.line,
288
+ column: this.locStart.column
289
+ },
290
+ start: {
291
+ line: locStartLine,
292
+ column: locStartColumn
293
+ }
294
+ };
295
+ return result;
296
+ }
297
+ }
298
+ return null;
299
+ }
300
+ /**
301
+ * If the given type equals the current type of the {@link Lexer} advance the lexer. Return true if the lexer was
302
+ * advanced.
303
+ */
304
+ consume(types) {
305
+ var _a, _b, _c, _d, _e;
306
+ if (!Array.isArray(types)) types = [types];
307
+ if (types.includes(this.lexer.current.type)) {
308
+ if (this.range)
309
+ this.rangeStart += ((_a = this.lexer.current) == null ? void 0 : _a.reduced) ?? 0;
310
+ if (this.loc) {
311
+ this.locStart.line += ((_b = this.lexer.current) == null ? void 0 : _b.line) ?? 0;
312
+ this.locStart.column = (((_c = this.lexer.current) == null ? void 0 : _c.line) ?? 0) > 0 ? ((_d = this.lexer.current) == null ? void 0 : _d.column) ?? 0 : this.locStart.column + (((_e = this.lexer.current) == null ? void 0 : _e.column) ?? 0);
313
+ }
314
+ this._lexer = this.lexer.advance();
315
+ return true;
316
+ } else return false;
317
+ }
318
+ acceptLexerState(parser) {
319
+ this._lexer = parser.lexer;
320
+ }
321
+ };
322
+ function isQuestionMarkUnknownType(next) {
323
+ return next === "}" || next === "EOF" || next === "|" || next === "," || next === ")" || next === ">";
324
+ }
325
+ var nullableParslet = (parser, precedence, left) => {
326
+ const type = parser.lexer.current.type;
327
+ const next = parser.lexer.next.type;
328
+ const inferSuffix = (left == null ? void 0 : left.type) === "JsdocTypeInfer";
329
+ if (!(left === null && type === "?" && !isQuestionMarkUnknownType(next) || left !== null && !inferSuffix && type === "?" && 12 > precedence)) return null;
330
+ parser.consume("?");
331
+ if (left === null) return {
332
+ type: "JsdocTypeNullable",
333
+ element: parser.parseType(12),
334
+ meta: { position: "prefix" }
335
+ };
336
+ else return {
337
+ type: "JsdocTypeNullable",
338
+ element: assertRootResult(left),
339
+ meta: { position: "suffix" }
340
+ };
341
+ };
342
+ function composeParslet(options) {
343
+ const parslet = (parser, curPrecedence, left) => {
344
+ const type = parser.lexer.current.type;
345
+ const next = parser.lexer.next.type;
346
+ if (left === null) {
347
+ if ("parsePrefix" in options) {
348
+ if (options.accept(type, next)) return options.parsePrefix(parser);
349
+ }
350
+ } else if ("parseInfix" in options) {
351
+ if (options.precedence > curPrecedence && options.accept(type, next)) return options.parseInfix(parser, left);
352
+ }
353
+ return null;
354
+ };
355
+ Object.defineProperty(parslet, "name", { value: options.name });
356
+ return parslet;
357
+ }
358
+ var optionalParslet = composeParslet({
359
+ name: "optionalParslet",
360
+ accept: (type) => type === "=",
361
+ precedence: 11,
362
+ parsePrefix: (parser) => {
363
+ parser.consume("=");
364
+ return {
365
+ type: "JsdocTypeOptional",
366
+ element: parser.parseType(11),
367
+ meta: { position: "prefix" }
368
+ };
369
+ },
370
+ parseInfix: (parser, left) => {
371
+ parser.consume("=");
372
+ return {
373
+ type: "JsdocTypeOptional",
374
+ element: assertRootResult(left),
375
+ meta: { position: "suffix" }
376
+ };
377
+ }
378
+ });
379
+ var numberParslet = composeParslet({
380
+ name: "numberParslet",
381
+ accept: (type) => type === "Number",
382
+ parsePrefix: (parser) => {
383
+ const text = parser.lexer.current.text;
384
+ parser.consume("Number");
385
+ if (text.endsWith("n")) {
386
+ const bigintText = text.slice(0, -1);
387
+ return {
388
+ type: "JsdocTypeBigInt",
389
+ value: BigInt(bigintText).toString()
390
+ };
391
+ }
392
+ return {
393
+ type: "JsdocTypeNumber",
394
+ value: parseFloat(text)
395
+ };
396
+ }
397
+ });
398
+ var parenthesisParslet = composeParslet({
399
+ name: "parenthesisParslet",
400
+ accept: (type) => type === "(",
401
+ parsePrefix: (parser) => {
402
+ parser.consume("(");
403
+ if (parser.consume(")")) return {
404
+ type: "JsdocTypeParameterList",
405
+ elements: []
406
+ };
407
+ const result = parser.parseIntermediateType(0);
408
+ if (!parser.consume(")")) throw new Error("Unterminated parenthesis");
409
+ if (result.type === "JsdocTypeParameterList") return result;
410
+ else if (result.type === "JsdocTypeKeyValue") return {
411
+ type: "JsdocTypeParameterList",
412
+ elements: [result]
413
+ };
414
+ return {
415
+ type: "JsdocTypeParenthesis",
416
+ element: assertRootResult(result)
417
+ };
418
+ }
419
+ });
420
+ var specialTypesParslet = composeParslet({
421
+ name: "specialTypesParslet",
422
+ accept: (type, next) => type === "?" && isQuestionMarkUnknownType(next) || type === "null" || type === "undefined" || type === "*",
423
+ parsePrefix: (parser) => {
424
+ if (parser.consume("null")) return { type: "JsdocTypeNull" };
425
+ if (parser.consume("undefined")) return { type: "JsdocTypeUndefined" };
426
+ if (parser.consume("*")) return { type: "JsdocTypeAny" };
427
+ if (parser.consume("?")) return { type: "JsdocTypeUnknown" };
428
+ throw new Error(`Unacceptable token: ${parser.lexer.current.text}`);
429
+ }
430
+ });
431
+ var notNullableParslet = composeParslet({
432
+ name: "notNullableParslet",
433
+ accept: (type) => type === "!",
434
+ precedence: 12,
435
+ parsePrefix: (parser) => {
436
+ parser.consume("!");
437
+ return {
438
+ type: "JsdocTypeNotNullable",
439
+ element: parser.parseType(12),
440
+ meta: { position: "prefix" }
441
+ };
442
+ },
443
+ parseInfix: (parser, left) => {
444
+ parser.consume("!");
445
+ return {
446
+ type: "JsdocTypeNotNullable",
447
+ element: assertRootResult(left),
448
+ meta: { position: "suffix" }
449
+ };
450
+ }
451
+ });
452
+ function createParameterListParslet({ allowTrailingComma }) {
453
+ return composeParslet({
454
+ name: "parameterListParslet",
455
+ accept: (type) => type === ",",
456
+ precedence: 1,
457
+ parseInfix: (parser, left) => {
458
+ const elements = [assertPlainKeyValueOrRootResult(left)];
459
+ parser.consume(",");
460
+ do
461
+ try {
462
+ const next = parser.parseIntermediateType(1);
463
+ elements.push(assertPlainKeyValueOrRootResult(next));
464
+ } catch (e) {
465
+ if (allowTrailingComma && e instanceof NoParsletFoundError) break;
466
+ else throw e;
467
+ }
468
+ while (parser.consume(","));
469
+ if (elements.length > 0 && elements.slice(0, -1).some((e) => e.type === "JsdocTypeVariadic")) throw new Error("Only the last parameter may be a rest parameter");
470
+ return {
471
+ type: "JsdocTypeParameterList",
472
+ elements
473
+ };
474
+ }
475
+ });
476
+ }
477
+ var genericParslet = composeParslet({
478
+ name: "genericParslet",
479
+ accept: (type, next) => type === "<" || type === "." && next === "<",
480
+ precedence: 17,
481
+ parseInfix: (parser, left) => {
482
+ const dot = parser.consume(".");
483
+ parser.consume("<");
484
+ const elements = [];
485
+ do
486
+ if (parser.consume("infer")) {
487
+ const name = parser.parseIntermediateType(12);
488
+ if (name.type !== "JsdocTypeName") throw new UnexpectedTypeError(name, "A typescript infer always has to have a name.");
489
+ elements.push({
490
+ type: "JsdocTypeInfer",
491
+ element: name
492
+ });
493
+ } else elements.push(parser.parseType(1));
494
+ while (parser.consume(","));
495
+ if (!parser.consume(">")) throw new Error("Unterminated generic parameter list");
496
+ return {
497
+ type: "JsdocTypeGeneric",
498
+ left: assertRootResult(left),
499
+ elements,
500
+ meta: {
501
+ brackets: "angle",
502
+ dot
503
+ }
504
+ };
505
+ }
506
+ });
507
+ var unionParslet = composeParslet({
508
+ name: "unionParslet",
509
+ accept: (type) => type === "|",
510
+ precedence: 5,
511
+ parseInfix: (parser, left) => {
512
+ parser.consume("|");
513
+ const elements = [];
514
+ do
515
+ elements.push(parser.parseType(5));
516
+ while (parser.consume("|"));
517
+ return {
518
+ type: "JsdocTypeUnion",
519
+ elements: [assertResultIsNotReservedWord(parser, assertRootResult(left)), ...elements.map((element) => assertResultIsNotReservedWord(parser, element))]
520
+ };
521
+ }
522
+ });
523
+ var baseGrammar = [
524
+ nullableParslet,
525
+ optionalParslet,
526
+ numberParslet,
527
+ parenthesisParslet,
528
+ specialTypesParslet,
529
+ notNullableParslet,
530
+ createParameterListParslet({ allowTrailingComma: true }),
531
+ genericParslet,
532
+ unionParslet,
533
+ optionalParslet
534
+ ];
535
+ function createNamePathParslet({ allowSquareBracketsOnAnyType, allowJsdocNamePaths, pathGrammar: pathGrammar2 }) {
536
+ return function namePathParslet(parser, precedence, left) {
537
+ if (left === null || precedence >= 18) return null;
538
+ const type = parser.lexer.current.type;
539
+ const next = parser.lexer.next.type;
540
+ if (!(type === "." && next !== "<" || type === "[" && (allowSquareBracketsOnAnyType || left.type === "JsdocTypeName") || allowJsdocNamePaths && (type === "~" || type === "#"))) return null;
541
+ let pathType;
542
+ let brackets = false;
543
+ if (parser.consume(".")) pathType = "property";
544
+ else if (parser.consume("[")) {
545
+ pathType = "property-brackets";
546
+ brackets = true;
547
+ } else if (parser.consume("~")) pathType = "inner";
548
+ else {
549
+ parser.consume("#");
550
+ pathType = "instance";
551
+ }
552
+ const pathParser = brackets && allowSquareBracketsOnAnyType ? parser : pathGrammar2 !== null ? new Parser(pathGrammar2, parser.lexer, parser) : parser;
553
+ const parsed = pathParser.parseType(brackets && allowSquareBracketsOnAnyType ? 0 : 18);
554
+ parser.acceptLexerState(pathParser);
555
+ let right;
556
+ switch (parsed.type) {
557
+ case "JsdocTypeName":
558
+ right = {
559
+ type: "JsdocTypeProperty",
560
+ value: parsed.value,
561
+ meta: { quote: void 0 }
562
+ };
563
+ break;
564
+ case "JsdocTypeNumber":
565
+ right = {
566
+ type: "JsdocTypeProperty",
567
+ value: parsed.value.toString(10),
568
+ meta: { quote: void 0 }
569
+ };
570
+ break;
571
+ case "JsdocTypeBigInt":
572
+ throw new UnexpectedTypeError(parsed, "Expecting 'JsdocTypeName', 'JsdocTypeNumber', 'JsdocStringValue' or 'JsdocTypeSpecialNamePath'");
573
+ case "JsdocTypeStringValue":
574
+ right = {
575
+ type: "JsdocTypeProperty",
576
+ value: parsed.value,
577
+ meta: { quote: parsed.meta.quote }
578
+ };
579
+ break;
580
+ case "JsdocTypeSpecialNamePath":
581
+ if (parsed.specialType === "event") right = parsed;
582
+ else throw new UnexpectedTypeError(parsed, "Type 'JsdocTypeSpecialNamePath' is only allowed with specialType 'event'");
583
+ break;
584
+ default:
585
+ if (!brackets || !allowSquareBracketsOnAnyType) throw new UnexpectedTypeError(parsed, "Expecting 'JsdocTypeName', 'JsdocTypeNumber', 'JsdocStringValue' or 'JsdocTypeSpecialNamePath'");
586
+ right = {
587
+ type: "JsdocTypeIndexedAccessIndex",
588
+ right: parsed
589
+ };
590
+ }
591
+ if (brackets && !parser.consume("]")) {
592
+ const token = parser.lexer.current;
593
+ throw new Error(`Unterminated square brackets. Next token is '${token.type}' with text '${token.text}'`);
594
+ }
595
+ return {
596
+ type: "JsdocTypeNamePath",
597
+ left: assertRootResult(left),
598
+ right,
599
+ pathType
600
+ };
601
+ };
602
+ }
603
+ function createNameParslet({ allowedAdditionalTokens }) {
604
+ return composeParslet({
605
+ name: "nameParslet",
606
+ accept: (type) => type === "Identifier" || type === "this" || type === "new" || allowedAdditionalTokens.includes(type),
607
+ parsePrefix: (parser) => {
608
+ const { type, text } = parser.lexer.current;
609
+ parser.consume(type);
610
+ return {
611
+ type: "JsdocTypeName",
612
+ value: text
613
+ };
614
+ }
615
+ });
616
+ }
617
+ var stringValueParslet = composeParslet({
618
+ name: "stringValueParslet",
619
+ accept: (type) => type === "StringValue",
620
+ parsePrefix: (parser) => {
621
+ const text = parser.lexer.current.text;
622
+ parser.consume("StringValue");
623
+ return {
624
+ type: "JsdocTypeStringValue",
625
+ value: text.slice(1, -1),
626
+ meta: { quote: text.startsWith("'") ? "single" : "double" }
627
+ };
628
+ }
629
+ });
630
+ function createSpecialNamePathParslet({ pathGrammar: pathGrammar2, allowedTypes }) {
631
+ return composeParslet({
632
+ name: "specialNamePathParslet",
633
+ accept: (type) => allowedTypes.includes(type),
634
+ parsePrefix: (parser) => {
635
+ const type = parser.lexer.current.type;
636
+ parser.consume(type);
637
+ if (!parser.consume(":")) return {
638
+ type: "JsdocTypeName",
639
+ value: type
640
+ };
641
+ let result;
642
+ let token = parser.lexer.current;
643
+ if (parser.consume("StringValue")) result = {
644
+ type: "JsdocTypeSpecialNamePath",
645
+ value: token.text.slice(1, -1),
646
+ specialType: type,
647
+ meta: { quote: token.text.startsWith("'") ? "single" : "double" }
648
+ };
649
+ else {
650
+ let value = "";
651
+ const allowed = [
652
+ "Identifier",
653
+ "@",
654
+ "/"
655
+ ];
656
+ while (allowed.some((type2) => parser.consume(type2))) {
657
+ value += token.text;
658
+ token = parser.lexer.current;
659
+ }
660
+ result = {
661
+ type: "JsdocTypeSpecialNamePath",
662
+ value,
663
+ specialType: type,
664
+ meta: { quote: void 0 }
665
+ };
666
+ }
667
+ const moduleParser = new Parser(pathGrammar2, parser.lexer, parser);
668
+ const moduleResult = moduleParser.parseInfixIntermediateType(result, 0);
669
+ parser.acceptLexerState(moduleParser);
670
+ return assertRootResult(moduleResult);
671
+ }
672
+ });
673
+ }
674
+ var basePathGrammar = [
675
+ createNameParslet({ allowedAdditionalTokens: ["external", "module"] }),
676
+ stringValueParslet,
677
+ numberParslet,
678
+ createNamePathParslet({
679
+ allowSquareBracketsOnAnyType: false,
680
+ allowJsdocNamePaths: true,
681
+ pathGrammar: null
682
+ })
683
+ ];
684
+ var pathGrammar = [
685
+ ...basePathGrammar,
686
+ createSpecialNamePathParslet({
687
+ allowedTypes: ["event"],
688
+ pathGrammar: basePathGrammar
689
+ }),
690
+ createNameParslet({ allowedAdditionalTokens: baseNameTokens })
691
+ ];
692
+ function getParameters(value) {
693
+ let parameters;
694
+ if (value.type === "JsdocTypeParameterList") parameters = value.elements;
695
+ else if (value.type === "JsdocTypeParenthesis") parameters = [value.element];
696
+ else throw new UnexpectedTypeError(value);
697
+ return parameters.map((p) => assertPlainKeyValueOrRootResult(p));
698
+ }
699
+ function getUnnamedParameters(value) {
700
+ const parameters = getParameters(value);
701
+ if (parameters.some((p) => p.type === "JsdocTypeKeyValue")) throw new Error("No parameter should be named");
702
+ return parameters;
703
+ }
704
+ function createFunctionParslet({ allowNamedParameters, allowNoReturnType, allowWithoutParenthesis, allowNewAsFunctionKeyword }) {
705
+ return composeParslet({
706
+ name: "functionParslet",
707
+ accept: (type, next) => type === "function" || allowNewAsFunctionKeyword && type === "new" && next === "(",
708
+ parsePrefix: (parser) => {
709
+ const newKeyword = parser.consume("new");
710
+ parser.consume("function");
711
+ const hasParenthesis = parser.lexer.current.type === "(";
712
+ if (!hasParenthesis) {
713
+ if (!allowWithoutParenthesis) throw new Error("function is missing parameter list");
714
+ return {
715
+ type: "JsdocTypeName",
716
+ value: "function"
717
+ };
718
+ }
719
+ let result = {
720
+ type: "JsdocTypeFunction",
721
+ parameters: [],
722
+ arrow: false,
723
+ constructor: newKeyword,
724
+ parenthesis: hasParenthesis
725
+ };
726
+ const value = parser.parseIntermediateType(14);
727
+ if (allowNamedParameters === void 0) result.parameters = getUnnamedParameters(value);
728
+ else if (newKeyword && value.type === "JsdocTypeFunction" && value.arrow) {
729
+ result = value;
730
+ result.constructor = true;
731
+ return result;
732
+ } else {
733
+ result.parameters = getParameters(value);
734
+ for (const p of result.parameters) if (p.type === "JsdocTypeKeyValue" && !allowNamedParameters.includes(p.key)) throw new Error(`only allowed named parameters are ${allowNamedParameters.join(", ")} but got ${p.type}`);
735
+ }
736
+ if (parser.consume(":")) result.returnType = parser.parseType(7);
737
+ else if (!allowNoReturnType) throw new Error("function is missing return type");
738
+ return result;
739
+ }
740
+ });
741
+ }
742
+ function createVariadicParslet({ allowPostfix, allowEnclosingBrackets }) {
743
+ return composeParslet({
744
+ name: "variadicParslet",
745
+ accept: (type) => type === "...",
746
+ precedence: 7,
747
+ parsePrefix: (parser) => {
748
+ parser.consume("...");
749
+ const brackets = allowEnclosingBrackets && parser.consume("[");
750
+ try {
751
+ const element = parser.parseType(7);
752
+ if (brackets && !parser.consume("]")) throw new Error("Unterminated variadic type. Missing ']'");
753
+ return {
754
+ type: "JsdocTypeVariadic",
755
+ element: assertRootResult(element),
756
+ meta: {
757
+ position: "prefix",
758
+ squareBrackets: brackets
759
+ }
760
+ };
761
+ } catch (e) {
762
+ if (e instanceof NoParsletFoundError) {
763
+ if (brackets) throw new Error("Empty square brackets for variadic are not allowed.", { cause: e });
764
+ return {
765
+ type: "JsdocTypeVariadic",
766
+ meta: {
767
+ position: void 0,
768
+ squareBrackets: false
769
+ }
770
+ };
771
+ } else throw e;
772
+ }
773
+ },
774
+ parseInfix: allowPostfix ? (parser, left) => {
775
+ parser.consume("...");
776
+ return {
777
+ type: "JsdocTypeVariadic",
778
+ element: assertRootResult(left),
779
+ meta: {
780
+ position: "suffix",
781
+ squareBrackets: false
782
+ }
783
+ };
784
+ } : void 0
785
+ });
786
+ }
787
+ var symbolParslet = composeParslet({
788
+ name: "symbolParslet",
789
+ accept: (type) => type === "(",
790
+ precedence: 10,
791
+ parseInfix: (parser, left) => {
792
+ if (left.type !== "JsdocTypeName") throw new Error("Symbol expects a name on the left side. (Reacting on '(')");
793
+ parser.consume("(");
794
+ const result = {
795
+ type: "JsdocTypeSymbol",
796
+ value: left.value
797
+ };
798
+ if (!parser.consume(")")) {
799
+ result.element = assertNumberOrVariadicNameResult(parser.parseIntermediateType(10));
800
+ if (!parser.consume(")")) throw new Error("Symbol does not end after value");
801
+ }
802
+ return result;
803
+ }
804
+ });
805
+ var arrayBracketsParslet = composeParslet({
806
+ name: "arrayBracketsParslet",
807
+ precedence: 16,
808
+ accept: (type, next) => type === "[" && next === "]",
809
+ parseInfix: (parser, left) => {
810
+ parser.consume("[");
811
+ parser.consume("]");
812
+ return {
813
+ type: "JsdocTypeGeneric",
814
+ left: {
815
+ type: "JsdocTypeName",
816
+ value: "Array"
817
+ },
818
+ elements: [assertRootResult(left)],
819
+ meta: {
820
+ brackets: "square",
821
+ dot: false
822
+ }
823
+ };
824
+ }
825
+ });
826
+ function createObjectParslet({ signatureGrammar, objectFieldGrammar: objectFieldGrammar2, allowKeyTypes }) {
827
+ return composeParslet({
828
+ name: "objectParslet",
829
+ accept: (type) => type === "{",
830
+ parsePrefix: (parser) => {
831
+ var _a;
832
+ parser.consume("{");
833
+ const result = {
834
+ type: "JsdocTypeObject",
835
+ meta: { separator: "comma" },
836
+ elements: []
837
+ };
838
+ if (!parser.consume("}")) {
839
+ let separator;
840
+ const fieldParser = new Parser(objectFieldGrammar2, parser.lexer, parser, ((_a = parser.externalParsers) == null ? void 0 : _a.computedPropertyParser) !== void 0 ? { externalParsers: { computedPropertyParser: parser.externalParsers.computedPropertyParser } } : void 0);
841
+ while (true) {
842
+ fieldParser.acceptLexerState(parser);
843
+ let field = fieldParser.parseIntermediateType(2);
844
+ parser.acceptLexerState(fieldParser);
845
+ if (field === void 0 && allowKeyTypes) field = parser.parseIntermediateType(2);
846
+ let optional = false;
847
+ if (field.type === "JsdocTypeNullable") {
848
+ optional = true;
849
+ field = field.element;
850
+ }
851
+ if (field.type === "JsdocTypeNumber" || field.type === "JsdocTypeName" || field.type === "JsdocTypeStringValue") {
852
+ let quote2;
853
+ if (field.type === "JsdocTypeStringValue") quote2 = field.meta.quote;
854
+ result.elements.push({
855
+ type: "JsdocTypeObjectField",
856
+ key: field.value.toString(),
857
+ right: void 0,
858
+ optional,
859
+ readonly: false,
860
+ meta: { quote: quote2 }
861
+ });
862
+ } else if (signatureGrammar !== void 0 && (field.type === "JsdocTypeCallSignature" || field.type === "JsdocTypeConstructorSignature" || field.type === "JsdocTypeMethodSignature")) {
863
+ const signatureParser = new Parser([...signatureGrammar, ...parser.grammar.flatMap((grammar) => {
864
+ if (grammar.name === "keyValueParslet") return [];
865
+ return [grammar];
866
+ })], parser.lexer, parser);
867
+ signatureParser.acceptLexerState(parser);
868
+ const params = signatureParser.parseIntermediateType(2);
869
+ parser.acceptLexerState(signatureParser);
870
+ field.parameters = getParameters(params);
871
+ const returnType = parser.parseType(2);
872
+ field.returnType = returnType;
873
+ result.elements.push(field);
874
+ } else if (field.type === "JsdocTypeObjectField" || field.type === "JsdocTypeJsdocObjectField") result.elements.push(field);
875
+ else if (field.type === "JsdocTypeReadonlyProperty" && field.element.type === "JsdocTypeObjectField") {
876
+ if (typeof field.element.key === "object" && field.element.key.type === "JsdocTypeComputedMethod") throw new Error("Computed method may not be readonly");
877
+ field.element.readonly = true;
878
+ result.elements.push(field.element);
879
+ } else throw new UnexpectedTypeError(field);
880
+ if (parser.lexer.current.startOfLine) {
881
+ separator ??= "linebreak";
882
+ parser.consume(",") || parser.consume(";");
883
+ } else if (parser.consume(",")) if (parser.lexer.current.startOfLine) separator = "comma-and-linebreak";
884
+ else separator = "comma";
885
+ else if (parser.consume(";")) if (parser.lexer.current.startOfLine) separator = "semicolon-and-linebreak";
886
+ else separator = "semicolon";
887
+ else break;
888
+ if (parser.lexer.current.type === "}") break;
889
+ }
890
+ result.meta.separator = separator ?? "comma";
891
+ if ((separator ?? "").endsWith("linebreak")) result.meta.propertyIndent = " ";
892
+ if (!parser.consume("}")) throw new Error("Unterminated record type. Missing '}'");
893
+ }
894
+ return result;
895
+ }
896
+ });
897
+ }
898
+ function createObjectFieldParslet({ allowSquaredProperties, allowKeyTypes, allowReadonly, allowOptional }) {
899
+ return composeParslet({
900
+ name: "objectFieldParslet",
901
+ precedence: 3,
902
+ accept: (type) => type === ":",
903
+ parseInfix: (parser, left) => {
904
+ let optional = false;
905
+ let readonlyProperty = false;
906
+ if (allowOptional && left.type === "JsdocTypeNullable") {
907
+ optional = true;
908
+ left = left.element;
909
+ }
910
+ if (allowReadonly && left.type === "JsdocTypeReadonlyProperty") {
911
+ readonlyProperty = true;
912
+ left = left.element;
913
+ }
914
+ if (left.type === "JsdocTypeBigInt") throw new UnexpectedTypeError(left);
915
+ const parentParser = parser.baseParser ?? parser;
916
+ parentParser.acceptLexerState(parser);
917
+ if (left.type === "JsdocTypeNumber" || left.type === "JsdocTypeName" || left.type === "JsdocTypeStringValue" || isSquaredProperty(left)) {
918
+ if (isSquaredProperty(left) && !allowSquaredProperties) throw new UnexpectedTypeError(left);
919
+ parentParser.consume(":");
920
+ let quote2;
921
+ if (left.type === "JsdocTypeStringValue") quote2 = left.meta.quote;
922
+ const right = parentParser.parseType(3);
923
+ parser.acceptLexerState(parentParser);
924
+ return {
925
+ type: "JsdocTypeObjectField",
926
+ /* c8 ignore next -- Guard; not needed anymore? */
927
+ key: isSquaredProperty(left) ? left : left.value.toString(),
928
+ right,
929
+ optional,
930
+ readonly: readonlyProperty,
931
+ meta: { quote: quote2 }
932
+ };
933
+ } else {
934
+ if (!allowKeyTypes) throw new UnexpectedTypeError(left);
935
+ parentParser.consume(":");
936
+ const right = parentParser.parseType(3);
937
+ parser.acceptLexerState(parentParser);
938
+ return {
939
+ type: "JsdocTypeJsdocObjectField",
940
+ left: assertRootResult(left),
941
+ right
942
+ };
943
+ }
944
+ }
945
+ });
946
+ }
947
+ function createKeyValueParslet({ allowOptional, allowVariadic, acceptParameterList }) {
948
+ return composeParslet({
949
+ name: "keyValueParslet",
950
+ precedence: 3,
951
+ accept: (type) => type === ":",
952
+ parseInfix: (parser, left) => {
953
+ let optional = false;
954
+ let variadic = false;
955
+ if (allowOptional && left.type === "JsdocTypeNullable") {
956
+ optional = true;
957
+ left = left.element;
958
+ }
959
+ if (allowVariadic && left.type === "JsdocTypeVariadic" && left.element !== void 0) {
960
+ variadic = true;
961
+ left = left.element;
962
+ }
963
+ if (left.type !== "JsdocTypeName") {
964
+ if (acceptParameterList !== void 0 && left.type === "JsdocTypeParameterList") {
965
+ parser.consume(":");
966
+ return left;
967
+ }
968
+ throw new UnexpectedTypeError(left);
969
+ }
970
+ parser.consume(":");
971
+ const right = parser.parseType(3);
972
+ return {
973
+ type: "JsdocTypeKeyValue",
974
+ key: left.value,
975
+ right,
976
+ optional,
977
+ variadic
978
+ };
979
+ }
980
+ });
981
+ }
982
+ var jsdocBaseGrammar = [
983
+ ...baseGrammar,
984
+ createFunctionParslet({
985
+ allowWithoutParenthesis: true,
986
+ allowNamedParameters: ["this", "new"],
987
+ allowNoReturnType: true,
988
+ allowNewAsFunctionKeyword: false
989
+ }),
990
+ stringValueParslet,
991
+ createSpecialNamePathParslet({
992
+ allowedTypes: [
993
+ "module",
994
+ "external",
995
+ "event"
996
+ ],
997
+ pathGrammar
998
+ }),
999
+ createVariadicParslet({
1000
+ allowEnclosingBrackets: true,
1001
+ allowPostfix: true
1002
+ }),
1003
+ createNameParslet({ allowedAdditionalTokens: ["keyof"] }),
1004
+ symbolParslet,
1005
+ arrayBracketsParslet,
1006
+ createNamePathParslet({
1007
+ allowSquareBracketsOnAnyType: false,
1008
+ allowJsdocNamePaths: true,
1009
+ pathGrammar
1010
+ })
1011
+ ];
1012
+ var jsdocGrammar = [
1013
+ ...jsdocBaseGrammar,
1014
+ createObjectParslet({
1015
+ objectFieldGrammar: [
1016
+ createNameParslet({ allowedAdditionalTokens: [
1017
+ "typeof",
1018
+ "module",
1019
+ "in"
1020
+ ] }),
1021
+ createObjectFieldParslet({
1022
+ allowSquaredProperties: false,
1023
+ allowKeyTypes: true,
1024
+ allowOptional: false,
1025
+ allowReadonly: false
1026
+ }),
1027
+ ...jsdocBaseGrammar
1028
+ ],
1029
+ allowKeyTypes: true
1030
+ }),
1031
+ createKeyValueParslet({
1032
+ allowOptional: true,
1033
+ allowVariadic: true
1034
+ })
1035
+ ];
1036
+ var jsdocNameGrammar = [
1037
+ genericParslet,
1038
+ arrayBracketsParslet,
1039
+ createNameParslet({ allowedAdditionalTokens: baseNameTokens })
1040
+ ];
1041
+ var jsdocNamePathGrammar = [
1042
+ genericParslet,
1043
+ arrayBracketsParslet,
1044
+ createNameParslet({ allowedAdditionalTokens: baseNameTokens }),
1045
+ createNamePathParslet({
1046
+ allowSquareBracketsOnAnyType: false,
1047
+ allowJsdocNamePaths: true,
1048
+ pathGrammar
1049
+ })
1050
+ ];
1051
+ var jsdocNamePathSpecialGrammar = [createSpecialNamePathParslet({
1052
+ allowedTypes: [
1053
+ "module",
1054
+ "external",
1055
+ "event"
1056
+ ],
1057
+ pathGrammar
1058
+ }), ...jsdocNamePathGrammar];
1059
+ var typeOfParslet = composeParslet({
1060
+ name: "typeOfParslet",
1061
+ accept: (type) => type === "typeof",
1062
+ parsePrefix: (parser) => {
1063
+ parser.consume("typeof");
1064
+ return {
1065
+ type: "JsdocTypeTypeof",
1066
+ element: parser.parseType(13)
1067
+ };
1068
+ }
1069
+ });
1070
+ var objectFieldGrammar$1 = [
1071
+ createNameParslet({ allowedAdditionalTokens: [
1072
+ "typeof",
1073
+ "module",
1074
+ "keyof",
1075
+ "event",
1076
+ "external",
1077
+ "in"
1078
+ ] }),
1079
+ nullableParslet,
1080
+ optionalParslet,
1081
+ stringValueParslet,
1082
+ numberParslet,
1083
+ createObjectFieldParslet({
1084
+ allowSquaredProperties: false,
1085
+ allowKeyTypes: false,
1086
+ allowOptional: false,
1087
+ allowReadonly: false
1088
+ })
1089
+ ];
1090
+ var closureGrammar = [
1091
+ ...baseGrammar,
1092
+ createObjectParslet({
1093
+ allowKeyTypes: false,
1094
+ objectFieldGrammar: objectFieldGrammar$1
1095
+ }),
1096
+ createNameParslet({ allowedAdditionalTokens: [
1097
+ "event",
1098
+ "external",
1099
+ "in"
1100
+ ] }),
1101
+ typeOfParslet,
1102
+ createFunctionParslet({
1103
+ allowWithoutParenthesis: false,
1104
+ allowNamedParameters: ["this", "new"],
1105
+ allowNoReturnType: true,
1106
+ allowNewAsFunctionKeyword: false
1107
+ }),
1108
+ createVariadicParslet({
1109
+ allowEnclosingBrackets: false,
1110
+ allowPostfix: false
1111
+ }),
1112
+ createNameParslet({ allowedAdditionalTokens: ["keyof"] }),
1113
+ createSpecialNamePathParslet({
1114
+ allowedTypes: ["module"],
1115
+ pathGrammar
1116
+ }),
1117
+ createNamePathParslet({
1118
+ allowSquareBracketsOnAnyType: false,
1119
+ allowJsdocNamePaths: true,
1120
+ pathGrammar
1121
+ }),
1122
+ createKeyValueParslet({
1123
+ allowOptional: false,
1124
+ allowVariadic: false
1125
+ }),
1126
+ symbolParslet
1127
+ ];
1128
+ var closureNameGrammar = [
1129
+ genericParslet,
1130
+ arrayBracketsParslet,
1131
+ createNameParslet({ allowedAdditionalTokens: baseNameTokens })
1132
+ ];
1133
+ var closureNamePathGrammar = [
1134
+ genericParslet,
1135
+ arrayBracketsParslet,
1136
+ createNameParslet({ allowedAdditionalTokens: baseNameTokens }),
1137
+ createNamePathParslet({
1138
+ allowSquareBracketsOnAnyType: false,
1139
+ allowJsdocNamePaths: true,
1140
+ pathGrammar
1141
+ })
1142
+ ];
1143
+ var closureNamePathSpecialGrammar = [createSpecialNamePathParslet({
1144
+ allowedTypes: ["module"],
1145
+ pathGrammar
1146
+ }), ...closureNamePathGrammar];
1147
+ var assertsParslet = composeParslet({
1148
+ name: "assertsParslet",
1149
+ accept: (type) => type === "asserts",
1150
+ parsePrefix: (parser) => {
1151
+ parser.consume("asserts");
1152
+ const left = parser.parseIntermediateType(10);
1153
+ if (left.type !== "JsdocTypeName") throw new UnexpectedTypeError(left, "A typescript asserts always has to have a name.");
1154
+ if (!parser.consume("is")) return {
1155
+ type: "JsdocTypeAssertsPlain",
1156
+ element: left
1157
+ };
1158
+ return {
1159
+ type: "JsdocTypeAsserts",
1160
+ left,
1161
+ right: assertRootResult(parser.parseIntermediateType(8))
1162
+ };
1163
+ }
1164
+ });
1165
+ var functionPropertyParslet = composeParslet({
1166
+ name: "functionPropertyParslet",
1167
+ accept: (type, next) => type === "new" && (next === "(" || next === "<") || type === "Identifier" && (next === "(" || next === "<") || type === "StringValue" && (next === "(" || next === "<") || type === "(" || type === "<",
1168
+ parsePrefix: (parser) => {
1169
+ let result;
1170
+ const returnType = {
1171
+ type: "JsdocTypeName",
1172
+ value: "void"
1173
+ };
1174
+ if (parser.consume("new")) result = {
1175
+ type: "JsdocTypeConstructorSignature",
1176
+ parameters: [],
1177
+ returnType
1178
+ };
1179
+ else {
1180
+ const text = parser.lexer.current.text;
1181
+ if (parser.consume("Identifier")) result = {
1182
+ type: "JsdocTypeMethodSignature",
1183
+ name: text,
1184
+ meta: { quote: void 0 },
1185
+ parameters: [],
1186
+ returnType
1187
+ };
1188
+ else {
1189
+ const text2 = parser.lexer.current.text;
1190
+ if (parser.consume("StringValue")) result = {
1191
+ type: "JsdocTypeMethodSignature",
1192
+ name: text2.slice(1, -1),
1193
+ meta: { quote: text2.startsWith('"') ? "double" : "single" },
1194
+ parameters: [],
1195
+ returnType
1196
+ };
1197
+ else result = {
1198
+ type: "JsdocTypeCallSignature",
1199
+ parameters: [],
1200
+ returnType
1201
+ };
1202
+ }
1203
+ }
1204
+ const typeParameters = [];
1205
+ if (parser.consume("<")) {
1206
+ do {
1207
+ let defaultValue = void 0;
1208
+ let name = parser.parseIntermediateType(10);
1209
+ if (name.type === "JsdocTypeOptional") {
1210
+ name = name.element;
1211
+ defaultValue = parser.parseType(10);
1212
+ }
1213
+ if (name.type !== "JsdocTypeName") throw new UnexpectedTypeError(name);
1214
+ let constraint = void 0;
1215
+ if (parser.consume("extends")) {
1216
+ constraint = parser.parseType(10);
1217
+ if (constraint.type === "JsdocTypeOptional") {
1218
+ constraint = constraint.element;
1219
+ defaultValue = parser.parseType(10);
1220
+ }
1221
+ }
1222
+ const typeParameter = {
1223
+ type: "JsdocTypeTypeParameter",
1224
+ name
1225
+ };
1226
+ if (constraint !== void 0) typeParameter.constraint = constraint;
1227
+ if (defaultValue !== void 0) typeParameter.defaultValue = defaultValue;
1228
+ typeParameters.push(typeParameter);
1229
+ if (parser.consume(">")) break;
1230
+ } while (parser.consume(","));
1231
+ result.typeParameters = typeParameters;
1232
+ }
1233
+ if (!(parser.lexer.current.type === "(")) throw new Error("function property is missing parameter list");
1234
+ return result;
1235
+ }
1236
+ });
1237
+ function createTupleParslet({ allowQuestionMark }) {
1238
+ return composeParslet({
1239
+ name: "tupleParslet",
1240
+ accept: (type) => type === "[",
1241
+ parsePrefix: (parser) => {
1242
+ parser.consume("[");
1243
+ const result = {
1244
+ type: "JsdocTypeTuple",
1245
+ elements: []
1246
+ };
1247
+ if (parser.consume("]")) return result;
1248
+ const typeList = parser.parseIntermediateType(0);
1249
+ if (typeList.type === "JsdocTypeParameterList") if (typeList.elements[0].type === "JsdocTypeKeyValue") result.elements = typeList.elements.map(assertPlainKeyValueResult);
1250
+ else result.elements = typeList.elements.map(assertRootResult);
1251
+ else if (typeList.type === "JsdocTypeKeyValue") result.elements = [assertPlainKeyValueResult(typeList)];
1252
+ else result.elements = [assertRootResult(typeList)];
1253
+ if (!parser.consume("]")) throw new Error("Unterminated '['");
1254
+ if (!allowQuestionMark && result.elements.some((e) => e.type === "JsdocTypeUnknown")) throw new Error("Question mark in tuple not allowed");
1255
+ return result;
1256
+ }
1257
+ });
1258
+ }
1259
+ var keyOfParslet = composeParslet({
1260
+ name: "keyOfParslet",
1261
+ accept: (type) => type === "keyof",
1262
+ parsePrefix: (parser) => {
1263
+ parser.consume("keyof");
1264
+ return {
1265
+ type: "JsdocTypeKeyof",
1266
+ element: assertRootResult(parser.parseType(13))
1267
+ };
1268
+ }
1269
+ });
1270
+ var inferParslet = composeParslet({
1271
+ name: "inferParslet",
1272
+ accept: (type) => type === "infer",
1273
+ parsePrefix: (parser) => {
1274
+ parser.consume("infer");
1275
+ const element = parser.parseIntermediateType(12);
1276
+ if (element.type !== "JsdocTypeName") throw new UnexpectedTypeError(element, "A typescript infer always has to have a name.");
1277
+ return {
1278
+ type: "JsdocTypeInfer",
1279
+ element
1280
+ };
1281
+ }
1282
+ });
1283
+ var importParslet = composeParslet({
1284
+ name: "importParslet",
1285
+ accept: (type) => type === "import",
1286
+ parsePrefix: (parser) => {
1287
+ parser.consume("import");
1288
+ if (!parser.consume("(")) throw new Error("Missing parenthesis after import keyword");
1289
+ const path = parser.parseType(7);
1290
+ if (path.type !== "JsdocTypeStringValue") throw new Error("Only string values are allowed as paths for imports");
1291
+ if (!parser.consume(")")) throw new Error("Missing closing parenthesis after import keyword");
1292
+ return {
1293
+ type: "JsdocTypeImport",
1294
+ element: path
1295
+ };
1296
+ }
1297
+ });
1298
+ var readonlyPropertyParslet = composeParslet({
1299
+ name: "readonlyPropertyParslet",
1300
+ accept: (type, next) => type === "readonly" && next !== ":" && next !== "?",
1301
+ parsePrefix: (parser) => {
1302
+ parser.consume("readonly");
1303
+ return {
1304
+ type: "JsdocTypeReadonlyProperty",
1305
+ element: parser.parseIntermediateType(3)
1306
+ };
1307
+ }
1308
+ });
1309
+ var arrowFunctionParslet = composeParslet({
1310
+ name: "arrowFunctionParslet",
1311
+ precedence: 15,
1312
+ accept: (type) => type === "=>",
1313
+ parseInfix: (parser, left) => {
1314
+ parser.consume("=>");
1315
+ return {
1316
+ type: "JsdocTypeFunction",
1317
+ parameters: getParameters(left).map(assertPlainKeyValueOrNameResult),
1318
+ arrow: true,
1319
+ constructor: false,
1320
+ parenthesis: true,
1321
+ returnType: parser.parseType(2)
1322
+ };
1323
+ }
1324
+ });
1325
+ var genericArrowFunctionParslet = composeParslet({
1326
+ name: "genericArrowFunctionParslet",
1327
+ accept: (type) => type === "<",
1328
+ parsePrefix: (parser) => {
1329
+ const typeParameters = [];
1330
+ parser.consume("<");
1331
+ do {
1332
+ let defaultValue = void 0;
1333
+ let name = parser.parseIntermediateType(10);
1334
+ if (name.type === "JsdocTypeOptional") {
1335
+ name = name.element;
1336
+ defaultValue = parser.parseType(10);
1337
+ }
1338
+ if (name.type !== "JsdocTypeName") throw new UnexpectedTypeError(name);
1339
+ let constraint = void 0;
1340
+ if (parser.consume("extends")) {
1341
+ constraint = parser.parseType(10);
1342
+ if (constraint.type === "JsdocTypeOptional") {
1343
+ constraint = constraint.element;
1344
+ defaultValue = parser.parseType(10);
1345
+ }
1346
+ }
1347
+ const typeParameter = {
1348
+ type: "JsdocTypeTypeParameter",
1349
+ name
1350
+ };
1351
+ if (constraint !== void 0) typeParameter.constraint = constraint;
1352
+ if (defaultValue !== void 0) typeParameter.defaultValue = defaultValue;
1353
+ typeParameters.push(typeParameter);
1354
+ if (parser.consume(">")) break;
1355
+ } while (parser.consume(","));
1356
+ const functionBase = parser.parseIntermediateType(10);
1357
+ functionBase.typeParameters = typeParameters;
1358
+ return functionBase;
1359
+ }
1360
+ });
1361
+ var intersectionParslet = composeParslet({
1362
+ name: "intersectionParslet",
1363
+ accept: (type) => type === "&",
1364
+ precedence: 6,
1365
+ parseInfix: (parser, left) => {
1366
+ parser.consume("&");
1367
+ const elements = [];
1368
+ do
1369
+ elements.push(parser.parseType(6));
1370
+ while (parser.consume("&"));
1371
+ return {
1372
+ type: "JsdocTypeIntersection",
1373
+ elements: [assertResultIsNotReservedWord(parser, assertRootResult(left)), ...elements.map((element) => assertResultIsNotReservedWord(parser, element))]
1374
+ };
1375
+ }
1376
+ });
1377
+ var predicateParslet = composeParslet({
1378
+ name: "predicateParslet",
1379
+ precedence: 8,
1380
+ accept: (type) => type === "is",
1381
+ parseInfix: (parser, left) => {
1382
+ if (left.type !== "JsdocTypeName") throw new UnexpectedTypeError(left, "A typescript predicate always has to have a name on the left side.");
1383
+ parser.consume("is");
1384
+ return {
1385
+ type: "JsdocTypePredicate",
1386
+ left,
1387
+ right: assertRootResult(parser.parseIntermediateType(8))
1388
+ };
1389
+ }
1390
+ });
1391
+ var breakingWhitespaceRegex = new RegExp("^\\s*\\n\\s*", "v");
1392
+ var Lexer = class Lexer2 {
1393
+ text = "";
1394
+ lexerRules;
1395
+ current;
1396
+ next;
1397
+ previous;
1398
+ static create(lexerRules, text) {
1399
+ const current = this.read(lexerRules, text);
1400
+ text = current.text;
1401
+ const next = this.read(lexerRules, text);
1402
+ text = next.text;
1403
+ return new Lexer2(lexerRules, text, void 0, current.token, next.token);
1404
+ }
1405
+ constructor(lexerRules, text, previous, current, next) {
1406
+ this.lexerRules = lexerRules;
1407
+ this.text = text;
1408
+ this.previous = previous;
1409
+ this.current = current;
1410
+ this.next = next;
1411
+ }
1412
+ static read(lexerRules, text, startOfLine = false) {
1413
+ var _a, _b, _c, _d;
1414
+ startOfLine ||= breakingWhitespaceRegex.test(text);
1415
+ const start = text.length;
1416
+ const initialWhitespace = ((_a = new RegExp("^\\s+", "v").exec(text)) == null ? void 0 : _a[0]) ?? "";
1417
+ text = text.trimStart();
1418
+ const trimmed = start - text.length;
1419
+ for (const rule of lexerRules) {
1420
+ const partial = rule(text);
1421
+ if (partial !== null) {
1422
+ const initialLines = initialWhitespace.split("\n");
1423
+ const currentLines = partial.text.split("\n");
1424
+ const token = {
1425
+ ...partial,
1426
+ startOfLine,
1427
+ reduced: trimmed + partial.text.length,
1428
+ line: initialLines.length + currentLines.length - 2,
1429
+ column: currentLines.length === 1 ? (((_b = initialLines.at(-1)) == null ? void 0 : _b.length) ?? 0) + (((_c = currentLines.at(-1)) == null ? void 0 : _c.length) ?? 0) : ((_d = currentLines.at(-1)) == null ? void 0 : _d.length) ?? 0
1430
+ };
1431
+ text = text.slice(token.text.length);
1432
+ return {
1433
+ text,
1434
+ token
1435
+ };
1436
+ }
1437
+ }
1438
+ throw new Error(`Unexpected Token ${text}`);
1439
+ }
1440
+ remaining() {
1441
+ return this.next.text + this.text;
1442
+ }
1443
+ advance() {
1444
+ const next = Lexer2.read(this.lexerRules, this.text);
1445
+ return new Lexer2(this.lexerRules, next.text, this.current, this.next, next.token);
1446
+ }
1447
+ };
1448
+ var objectSquaredPropertyParslet = composeParslet({
1449
+ name: "objectSquarePropertyParslet",
1450
+ accept: (type) => type === "[",
1451
+ parsePrefix: (parser) => {
1452
+ var _a, _b;
1453
+ if (parser.baseParser === void 0) throw new Error("Only allowed inside object grammar");
1454
+ parser.consume("[");
1455
+ let innerBracketType;
1456
+ if (((_a = parser.externalParsers) == null ? void 0 : _a.computedPropertyParser) === void 0) try {
1457
+ innerBracketType = parser.parseIntermediateType(2);
1458
+ } catch (err) {
1459
+ throw new Error("Error parsing value inside square bracketed property.", { cause: err });
1460
+ }
1461
+ let result;
1462
+ if ((innerBracketType == null ? void 0 : innerBracketType.type) === "JsdocTypeObjectField" && typeof innerBracketType.key === "string" && !innerBracketType.optional && !innerBracketType.readonly && innerBracketType.right !== void 0) {
1463
+ const key = innerBracketType.key;
1464
+ if (!parser.consume("]")) throw new Error("Unterminated square brackets");
1465
+ if (!parser.consume(":")) throw new Error("Incomplete index signature");
1466
+ const parentParser = parser.baseParser;
1467
+ parentParser.acceptLexerState(parser);
1468
+ innerBracketType.key = {
1469
+ type: "JsdocTypeIndexSignature",
1470
+ key,
1471
+ right: innerBracketType.right
1472
+ };
1473
+ innerBracketType.optional = false;
1474
+ innerBracketType.meta.quote = void 0;
1475
+ result = innerBracketType;
1476
+ const right = parentParser.parseType(4);
1477
+ result.right = right;
1478
+ parser.acceptLexerState(parentParser);
1479
+ } else if ((innerBracketType == null ? void 0 : innerBracketType.type) === "JsdocTypeName" && parser.consume("in")) {
1480
+ const parentParser = parser.baseParser;
1481
+ parentParser.acceptLexerState(parser);
1482
+ const mappedTypeRight = parentParser.parseType(4);
1483
+ if (!parentParser.consume("]")) throw new Error("Unterminated square brackets");
1484
+ const optional = parentParser.consume("?");
1485
+ if (!parentParser.consume(":")) throw new Error("Incomplete mapped type clause: missing colon");
1486
+ const right = parentParser.parseType(4);
1487
+ result = {
1488
+ type: "JsdocTypeObjectField",
1489
+ optional,
1490
+ readonly: false,
1491
+ meta: { quote: void 0 },
1492
+ key: {
1493
+ type: "JsdocTypeMappedType",
1494
+ key: innerBracketType.value,
1495
+ right: mappedTypeRight
1496
+ },
1497
+ right
1498
+ };
1499
+ parser.acceptLexerState(parentParser);
1500
+ } else {
1501
+ if (((_b = parser.externalParsers) == null ? void 0 : _b.computedPropertyParser) !== void 0) {
1502
+ let remaining = parser.lexer.current.text + parser.lexer.remaining();
1503
+ let checkingText = remaining;
1504
+ while (checkingText !== "") {
1505
+ try {
1506
+ innerBracketType = parser.externalParsers.computedPropertyParser(checkingText);
1507
+ break;
1508
+ } catch (err) {
1509
+ }
1510
+ checkingText = checkingText.slice(0, -1);
1511
+ }
1512
+ remaining = remaining.slice(checkingText.length);
1513
+ const remainingTextParser = new Parser(parser.grammar, Lexer.create(parser.lexer.lexerRules, remaining), parser.baseParser, { externalParsers: { computedPropertyParser: parser.externalParsers.computedPropertyParser } });
1514
+ parser.acceptLexerState(remainingTextParser);
1515
+ }
1516
+ if (!parser.consume("]")) throw new Error("Unterminated square brackets");
1517
+ let optional = parser.consume("?");
1518
+ const typeParameters = [];
1519
+ if (parser.consume("<")) do {
1520
+ let defaultValue = void 0;
1521
+ let name = parser.parseIntermediateType(10);
1522
+ if (name.type === "JsdocTypeOptional") {
1523
+ name = name.element;
1524
+ defaultValue = parser.parseType(10);
1525
+ }
1526
+ if (name.type !== "JsdocTypeName") throw new UnexpectedTypeError(name);
1527
+ let constraint = void 0;
1528
+ if (parser.consume("extends")) {
1529
+ constraint = parser.parseType(10);
1530
+ if (constraint.type === "JsdocTypeOptional") {
1531
+ constraint = constraint.element;
1532
+ defaultValue = parser.parseType(10);
1533
+ }
1534
+ }
1535
+ const typeParameter = {
1536
+ type: "JsdocTypeTypeParameter",
1537
+ name
1538
+ };
1539
+ if (constraint !== void 0) typeParameter.constraint = constraint;
1540
+ if (defaultValue !== void 0) typeParameter.defaultValue = defaultValue;
1541
+ typeParameters.push(typeParameter);
1542
+ if (parser.consume(">")) break;
1543
+ } while (parser.consume(","));
1544
+ let type;
1545
+ let key;
1546
+ const checkMiddle = () => {
1547
+ if (!optional) optional = parser.consume("?");
1548
+ };
1549
+ let right;
1550
+ if (parser.lexer.current.type === "(") {
1551
+ const signatureParser = new Parser([createKeyValueParslet({
1552
+ allowVariadic: true,
1553
+ allowOptional: true,
1554
+ acceptParameterList: true
1555
+ }), ...parser.baseParser.grammar.flatMap((grammar) => {
1556
+ if (grammar.name === "keyValueParslet") return [];
1557
+ return [grammar];
1558
+ })], parser.lexer, parser);
1559
+ signatureParser.acceptLexerState(parser);
1560
+ const params = signatureParser.parseIntermediateType(2);
1561
+ parser.acceptLexerState(signatureParser);
1562
+ const parameters = getParameters(params);
1563
+ type = "JsdocTypeComputedMethod";
1564
+ checkMiddle();
1565
+ parser.consume(":");
1566
+ const nextValue = parser.parseType(4);
1567
+ key = {
1568
+ type,
1569
+ optional,
1570
+ value: innerBracketType,
1571
+ parameters,
1572
+ returnType: nextValue
1573
+ };
1574
+ if (typeParameters.length > 0) key.typeParameters = typeParameters;
1575
+ } else {
1576
+ type = "JsdocTypeComputedProperty";
1577
+ checkMiddle();
1578
+ if (!parser.consume(":")) throw new Error("Incomplete computed property: missing colon");
1579
+ right = parser.parseType(4);
1580
+ key = {
1581
+ type,
1582
+ value: innerBracketType
1583
+ };
1584
+ }
1585
+ result = {
1586
+ type: "JsdocTypeObjectField",
1587
+ optional: type === "JsdocTypeComputedMethod" ? false : optional,
1588
+ readonly: false,
1589
+ meta: { quote: void 0 },
1590
+ key,
1591
+ right
1592
+ };
1593
+ }
1594
+ return result;
1595
+ }
1596
+ });
1597
+ var readonlyArrayParslet = composeParslet({
1598
+ name: "readonlyArrayParslet",
1599
+ accept: (type) => type === "readonly",
1600
+ parsePrefix: (parser) => {
1601
+ parser.consume("readonly");
1602
+ return {
1603
+ type: "JsdocTypeReadonlyArray",
1604
+ element: assertArrayOrTupleResult(parser.parseIntermediateType(0))
1605
+ };
1606
+ }
1607
+ });
1608
+ var conditionalParslet = composeParslet({
1609
+ name: "conditionalParslet",
1610
+ precedence: 8,
1611
+ accept: (type) => type === "extends",
1612
+ parseInfix: (parser, left) => {
1613
+ parser.consume("extends");
1614
+ const extendsType = assertRootResult(parser.parseType(13));
1615
+ parser.consume("?");
1616
+ const trueType = parser.parseType(8);
1617
+ parser.consume(":");
1618
+ return {
1619
+ type: "JsdocTypeConditional",
1620
+ checksType: assertRootResult(left),
1621
+ extendsType,
1622
+ trueType,
1623
+ falseType: parser.parseType(8)
1624
+ };
1625
+ }
1626
+ });
1627
+ function makePunctuationRule(type) {
1628
+ return (text) => {
1629
+ if (text.startsWith(type)) return {
1630
+ type,
1631
+ text: type
1632
+ };
1633
+ else return null;
1634
+ };
1635
+ }
1636
+ function getQuoted(text) {
1637
+ let position = 0;
1638
+ let char = void 0;
1639
+ const mark = text[0];
1640
+ let escaped = false;
1641
+ if (mark !== "'" && mark !== '"') return null;
1642
+ while (position < text.length) {
1643
+ position++;
1644
+ char = text[position];
1645
+ if (!escaped && char === mark) {
1646
+ position++;
1647
+ break;
1648
+ }
1649
+ escaped = !escaped && char === "\\";
1650
+ }
1651
+ if (char !== mark) throw new Error("Unterminated String");
1652
+ return text.slice(0, position);
1653
+ }
1654
+ function getTemplateLiteral(text) {
1655
+ let position = 0;
1656
+ let char = void 0;
1657
+ const mark = text[0];
1658
+ let escaped = false;
1659
+ if (mark !== "`") return null;
1660
+ while (position < text.length) {
1661
+ position++;
1662
+ char = text[position];
1663
+ if (!escaped && char === mark) {
1664
+ position++;
1665
+ break;
1666
+ }
1667
+ escaped = !escaped && char === "\\";
1668
+ }
1669
+ if (char !== mark) throw new Error("Unterminated template literal");
1670
+ return text.slice(0, position);
1671
+ }
1672
+ function getTemplateLiteralLiteral(text) {
1673
+ let position = 0;
1674
+ const start = text[0];
1675
+ let escaped = false;
1676
+ if (start === "`" || start === "$" && text[1] === "{") return null;
1677
+ while (position < text.length) {
1678
+ position++;
1679
+ const char = text[position];
1680
+ if (!escaped && (char === "`" || char === "$" && text[position + 1] === "{")) break;
1681
+ escaped = !escaped && char === "\\";
1682
+ }
1683
+ return text.slice(0, position);
1684
+ }
1685
+ var identifierStartRegex = new RegExp("[$_\\p{ID_Start}]|\\\\u\\p{Hex_Digit}{4}|\\\\u\\{0*(?:\\p{Hex_Digit}{1,5}|10\\p{Hex_Digit}{4})\\}", "v");
1686
+ var identifierContinueRegex = new RegExp("[$\\p{ID_Continue}\\u200C\\u200D]|\\\\u\\p{Hex_Digit}{4}|\\\\u\\{0*(?:\\p{Hex_Digit}{1,5}|10\\p{Hex_Digit}{4})\\}", "v");
1687
+ var identifierContinueRegexLoose = new RegExp("[$\\-\\p{ID_Continue}\\u200C\\u200D]|\\\\u\\p{Hex_Digit}{4}|\\\\u\\{0*(?:\\p{Hex_Digit}{1,5}|10\\p{Hex_Digit}{4})\\}", "v");
1688
+ function makeGetIdentifier(identifierContinueRegex2) {
1689
+ return function(text) {
1690
+ let char = text[0];
1691
+ if (!identifierStartRegex.test(char)) return null;
1692
+ let position = 1;
1693
+ do {
1694
+ char = text[position];
1695
+ if (!identifierContinueRegex2.test(char)) break;
1696
+ position++;
1697
+ } while (position < text.length);
1698
+ return text.slice(0, position);
1699
+ };
1700
+ }
1701
+ var bigintRegex = new RegExp("^(?:-?\\d+n)", "v");
1702
+ var numberRegex = new RegExp("^(?:-?(?:(?:\\d*\\.\\d+|\\d+)(?:[Ee][+\\-]?\\d+)?))", "v");
1703
+ var looseNumberRegex = new RegExp("^(?:NaN|-?(?:(?:\\d*\\.\\d+|\\d+)(?:[Ee][+\\-]?\\d+)?|Infinity))", "v");
1704
+ function getGetNumber(numberRegex2) {
1705
+ return function getNumber(text) {
1706
+ var _a;
1707
+ return ((_a = numberRegex2.exec(text)) == null ? void 0 : _a[0]) ?? null;
1708
+ };
1709
+ }
1710
+ var looseIdentifierRule = (text) => {
1711
+ const value = makeGetIdentifier(identifierContinueRegexLoose)(text);
1712
+ if (value === null) return null;
1713
+ return {
1714
+ type: "Identifier",
1715
+ text: value
1716
+ };
1717
+ };
1718
+ var identifierRule = (text) => {
1719
+ const value = makeGetIdentifier(identifierContinueRegex)(text);
1720
+ if (value === null) return null;
1721
+ return {
1722
+ type: "Identifier",
1723
+ text: value
1724
+ };
1725
+ };
1726
+ function makeKeyWordRule(type) {
1727
+ return (text) => {
1728
+ if (!text.startsWith(type)) return null;
1729
+ const prepends = text[type.length];
1730
+ if (prepends !== void 0 && identifierContinueRegex.test(prepends)) return null;
1731
+ return {
1732
+ type,
1733
+ text: type
1734
+ };
1735
+ };
1736
+ }
1737
+ var stringValueRule = (text) => {
1738
+ const value = getQuoted(text);
1739
+ if (value === null) return null;
1740
+ return {
1741
+ type: "StringValue",
1742
+ text: value
1743
+ };
1744
+ };
1745
+ var templateLiteralRule = (text) => {
1746
+ const value = getTemplateLiteral(text);
1747
+ if (value === null) return null;
1748
+ return {
1749
+ type: "TemplateLiteral",
1750
+ text: value
1751
+ };
1752
+ };
1753
+ var eofRule = (text) => {
1754
+ if (text.length > 0) return null;
1755
+ return {
1756
+ type: "EOF",
1757
+ text: ""
1758
+ };
1759
+ };
1760
+ var numberRule = (text) => {
1761
+ var _a;
1762
+ const bigintValue = (_a = bigintRegex.exec(text)) == null ? void 0 : _a[0];
1763
+ if (bigintValue !== void 0) return {
1764
+ type: "Number",
1765
+ text: bigintValue
1766
+ };
1767
+ const value = getGetNumber(numberRegex)(text);
1768
+ if (value === null) return null;
1769
+ return {
1770
+ type: "Number",
1771
+ text: value
1772
+ };
1773
+ };
1774
+ var looseNumberRule = (text) => {
1775
+ var _a;
1776
+ const bigintValue = (_a = bigintRegex.exec(text)) == null ? void 0 : _a[0];
1777
+ if (bigintValue !== void 0) return {
1778
+ type: "Number",
1779
+ text: bigintValue
1780
+ };
1781
+ const value = getGetNumber(looseNumberRegex)(text);
1782
+ if (value === null) return null;
1783
+ return {
1784
+ type: "Number",
1785
+ text: value
1786
+ };
1787
+ };
1788
+ var rules = [
1789
+ eofRule,
1790
+ makePunctuationRule("=>"),
1791
+ makePunctuationRule("("),
1792
+ makePunctuationRule(")"),
1793
+ makePunctuationRule("{"),
1794
+ makePunctuationRule("}"),
1795
+ makePunctuationRule("["),
1796
+ makePunctuationRule("]"),
1797
+ makePunctuationRule("|"),
1798
+ makePunctuationRule("&"),
1799
+ makePunctuationRule("<"),
1800
+ makePunctuationRule(">"),
1801
+ makePunctuationRule(","),
1802
+ makePunctuationRule(";"),
1803
+ makePunctuationRule("*"),
1804
+ makePunctuationRule("?"),
1805
+ makePunctuationRule("!"),
1806
+ makePunctuationRule("="),
1807
+ makePunctuationRule(":"),
1808
+ makePunctuationRule("..."),
1809
+ makePunctuationRule("."),
1810
+ makePunctuationRule("#"),
1811
+ makePunctuationRule("~"),
1812
+ makePunctuationRule("/"),
1813
+ makePunctuationRule("@"),
1814
+ makeKeyWordRule("undefined"),
1815
+ makeKeyWordRule("null"),
1816
+ makeKeyWordRule("function"),
1817
+ makeKeyWordRule("this"),
1818
+ makeKeyWordRule("new"),
1819
+ makeKeyWordRule("module"),
1820
+ makeKeyWordRule("event"),
1821
+ makeKeyWordRule("extends"),
1822
+ makeKeyWordRule("external"),
1823
+ makeKeyWordRule("infer"),
1824
+ makeKeyWordRule("typeof"),
1825
+ makeKeyWordRule("keyof"),
1826
+ makeKeyWordRule("readonly"),
1827
+ makeKeyWordRule("import"),
1828
+ makeKeyWordRule("is"),
1829
+ makeKeyWordRule("in"),
1830
+ makeKeyWordRule("asserts"),
1831
+ numberRule,
1832
+ identifierRule,
1833
+ stringValueRule,
1834
+ templateLiteralRule
1835
+ ];
1836
+ var looseRules = rules.toSpliced(-4, 2, looseNumberRule, looseIdentifierRule);
1837
+ var templateLiteralParslet = composeParslet({
1838
+ name: "templateLiteralParslet",
1839
+ accept: (type) => type === "TemplateLiteral",
1840
+ parsePrefix: (parser) => {
1841
+ const text = parser.lexer.current.text;
1842
+ parser.consume("TemplateLiteral");
1843
+ const literals = [];
1844
+ const interpolations = [];
1845
+ let currentText = text.slice(1, -1);
1846
+ const advanceLiteral = () => {
1847
+ const literal = getTemplateLiteralLiteral(currentText) ?? "";
1848
+ literals.push(literal.replace(new RegExp("\\\\`", "gv"), "`"));
1849
+ currentText = currentText.slice(literal.length);
1850
+ };
1851
+ advanceLiteral();
1852
+ while (true) {
1853
+ if (currentText.startsWith("${")) {
1854
+ currentText = currentText.slice(2);
1855
+ let templateParser;
1856
+ let interpolationType;
1857
+ let snipped = currentText;
1858
+ let remnant = "";
1859
+ while (true) try {
1860
+ templateParser = new Parser(parser.grammar, Lexer.create(parser.lexer.lexerRules, snipped));
1861
+ interpolationType = templateParser.parseType(0);
1862
+ break;
1863
+ } catch (err) {
1864
+ remnant = snipped.slice(-1) + remnant;
1865
+ snipped = snipped.slice(0, -1);
1866
+ }
1867
+ interpolations.push(interpolationType);
1868
+ if (templateParser.lexer.current.text !== "}") throw new Error("unterminated interpolation");
1869
+ currentText = templateParser.lexer.remaining() + remnant;
1870
+ } else break;
1871
+ advanceLiteral();
1872
+ }
1873
+ return {
1874
+ type: "JsdocTypeTemplateLiteral",
1875
+ literals,
1876
+ interpolations
1877
+ };
1878
+ }
1879
+ });
1880
+ var uniqueSymbolParslet = (parser, _precedence, left) => {
1881
+ if (left !== null) return null;
1882
+ if (parser.lexer.current.type !== "Identifier" || parser.lexer.current.text !== "unique" || parser.lexer.next.type !== "Identifier" || parser.lexer.next.text !== "symbol") return null;
1883
+ parser.consume("Identifier");
1884
+ parser.consume("Identifier");
1885
+ return { type: "JsdocTypeUniqueSymbol" };
1886
+ };
1887
+ var objectFieldGrammar = [
1888
+ functionPropertyParslet,
1889
+ readonlyPropertyParslet,
1890
+ createNameParslet({ allowedAdditionalTokens: baseNameTokens }),
1891
+ nullableParslet,
1892
+ optionalParslet,
1893
+ stringValueParslet,
1894
+ numberParslet,
1895
+ createObjectFieldParslet({
1896
+ allowSquaredProperties: true,
1897
+ allowKeyTypes: false,
1898
+ allowOptional: true,
1899
+ allowReadonly: true
1900
+ }),
1901
+ objectSquaredPropertyParslet
1902
+ ];
1903
+ var typescriptGrammar = [
1904
+ ...baseGrammar,
1905
+ createObjectParslet({
1906
+ allowKeyTypes: false,
1907
+ objectFieldGrammar,
1908
+ signatureGrammar: [createKeyValueParslet({
1909
+ allowVariadic: true,
1910
+ allowOptional: true,
1911
+ acceptParameterList: true
1912
+ })]
1913
+ }),
1914
+ readonlyArrayParslet,
1915
+ typeOfParslet,
1916
+ keyOfParslet,
1917
+ inferParslet,
1918
+ importParslet,
1919
+ stringValueParslet,
1920
+ createFunctionParslet({
1921
+ allowWithoutParenthesis: true,
1922
+ allowNoReturnType: true,
1923
+ allowNamedParameters: [
1924
+ "this",
1925
+ "new",
1926
+ "args"
1927
+ ],
1928
+ allowNewAsFunctionKeyword: true
1929
+ }),
1930
+ createTupleParslet({ allowQuestionMark: false }),
1931
+ createVariadicParslet({
1932
+ allowEnclosingBrackets: false,
1933
+ allowPostfix: false
1934
+ }),
1935
+ assertsParslet,
1936
+ conditionalParslet,
1937
+ uniqueSymbolParslet,
1938
+ createNameParslet({ allowedAdditionalTokens: [
1939
+ "event",
1940
+ "external",
1941
+ "in"
1942
+ ] }),
1943
+ createSpecialNamePathParslet({
1944
+ allowedTypes: ["module"],
1945
+ pathGrammar
1946
+ }),
1947
+ arrayBracketsParslet,
1948
+ arrowFunctionParslet,
1949
+ genericArrowFunctionParslet,
1950
+ createNamePathParslet({
1951
+ allowSquareBracketsOnAnyType: true,
1952
+ allowJsdocNamePaths: false,
1953
+ pathGrammar
1954
+ }),
1955
+ intersectionParslet,
1956
+ predicateParslet,
1957
+ templateLiteralParslet,
1958
+ createKeyValueParslet({
1959
+ allowVariadic: true,
1960
+ allowOptional: true
1961
+ })
1962
+ ];
1963
+ var typescriptNameGrammar = [
1964
+ genericParslet,
1965
+ arrayBracketsParslet,
1966
+ createNameParslet({ allowedAdditionalTokens: baseNameTokens })
1967
+ ];
1968
+ var typescriptNamePathGrammar = [
1969
+ genericParslet,
1970
+ arrayBracketsParslet,
1971
+ createNameParslet({ allowedAdditionalTokens: baseNameTokens }),
1972
+ createNamePathParslet({
1973
+ allowSquareBracketsOnAnyType: true,
1974
+ allowJsdocNamePaths: true,
1975
+ pathGrammar
1976
+ })
1977
+ ];
1978
+ var typescriptNamePathSpecialGrammar = [createSpecialNamePathParslet({
1979
+ allowedTypes: ["module"],
1980
+ pathGrammar
1981
+ }), ...typescriptNamePathGrammar];
1982
+ function parse(expression, mode, { range = false, rangeStart, loc = false, locStart = {
1983
+ column: 0,
1984
+ line: 1
1985
+ }, module: module2 = true, strictMode = true, asyncFunctionBody = true, classContext = false, computedPropertyParser } = {}) {
1986
+ let parser;
1987
+ switch (mode) {
1988
+ case "closure":
1989
+ parser = new Parser(closureGrammar, Lexer.create(looseRules, expression), void 0, {
1990
+ module: module2,
1991
+ strictMode,
1992
+ asyncFunctionBody,
1993
+ classContext,
1994
+ range,
1995
+ rangeStart,
1996
+ loc,
1997
+ locStart
1998
+ });
1999
+ break;
2000
+ case "jsdoc":
2001
+ parser = new Parser(jsdocGrammar, Lexer.create(looseRules, expression), void 0, {
2002
+ module: module2,
2003
+ strictMode,
2004
+ asyncFunctionBody,
2005
+ classContext,
2006
+ range,
2007
+ rangeStart,
2008
+ loc,
2009
+ locStart
2010
+ });
2011
+ break;
2012
+ case "typescript":
2013
+ parser = new Parser(typescriptGrammar, Lexer.create(rules, expression), void 0, {
2014
+ module: module2,
2015
+ strictMode,
2016
+ asyncFunctionBody,
2017
+ classContext,
2018
+ range,
2019
+ rangeStart,
2020
+ loc,
2021
+ locStart,
2022
+ externalParsers: { computedPropertyParser }
2023
+ });
2024
+ break;
2025
+ }
2026
+ const result = parser.parse();
2027
+ return assertResultIsNotReservedWord(parser, result);
2028
+ }
2029
+ function tryParse(expression, modes = [
2030
+ "typescript",
2031
+ "closure",
2032
+ "jsdoc"
2033
+ ], { module: module2 = true, strictMode = true, asyncFunctionBody = true, classContext = false, range, rangeStart, loc = false, locStart = {
2034
+ column: 0,
2035
+ line: 1
2036
+ } } = {}) {
2037
+ let error;
2038
+ for (const mode of modes) try {
2039
+ return parse(expression, mode, {
2040
+ module: module2,
2041
+ strictMode,
2042
+ asyncFunctionBody,
2043
+ classContext,
2044
+ range,
2045
+ rangeStart,
2046
+ loc,
2047
+ locStart
2048
+ });
2049
+ } catch (e) {
2050
+ error = e;
2051
+ }
2052
+ throw error;
2053
+ }
2054
+ function parseNamePath(expression, mode, { includeSpecial = false } = {}) {
2055
+ switch (mode) {
2056
+ case "closure":
2057
+ return new Parser(includeSpecial ? closureNamePathSpecialGrammar : closureNamePathGrammar, Lexer.create(looseRules, expression)).parse();
2058
+ case "jsdoc":
2059
+ return new Parser(includeSpecial ? jsdocNamePathSpecialGrammar : jsdocNamePathGrammar, Lexer.create(looseRules, expression)).parse();
2060
+ case "typescript":
2061
+ return new Parser(includeSpecial ? typescriptNamePathSpecialGrammar : typescriptNamePathGrammar, Lexer.create(rules, expression)).parse();
2062
+ }
2063
+ }
2064
+ function parseName(expression, mode) {
2065
+ switch (mode) {
2066
+ case "closure":
2067
+ return new Parser(closureNameGrammar, Lexer.create(looseRules, expression)).parse();
2068
+ case "jsdoc":
2069
+ return new Parser(jsdocNameGrammar, Lexer.create(looseRules, expression)).parse();
2070
+ case "typescript":
2071
+ return new Parser(typescriptNameGrammar, Lexer.create(rules, expression)).parse();
2072
+ }
2073
+ }
2074
+ function transform(rules2, parseResult) {
2075
+ const rule = rules2[parseResult.type];
2076
+ if (rule === void 0) throw new Error(`In this set of transform rules exists no rule for type ${parseResult.type}.`);
2077
+ return rule(parseResult, (aParseResult) => transform(rules2, aParseResult));
2078
+ }
2079
+ function notAvailableTransform(parseResult) {
2080
+ throw new Error("This transform is not available. Are you trying the correct parsing mode?");
2081
+ }
2082
+ function extractSpecialParams(source) {
2083
+ const result = { params: [] };
2084
+ for (const param of source.parameters) if (param.type === "JsdocTypeKeyValue") if (param.key === "this") result.this = param.right;
2085
+ else if (param.key === "new") result.new = param.right;
2086
+ else result.params.push(param);
2087
+ else result.params.push(param);
2088
+ return result;
2089
+ }
2090
+ function applyPosition(position, target, value) {
2091
+ return position === "prefix" ? value + target : target + value;
2092
+ }
2093
+ function quote(value, quote2) {
2094
+ switch (quote2) {
2095
+ case "double":
2096
+ return `"${value}"`;
2097
+ case "single":
2098
+ return `'${value}'`;
2099
+ case void 0:
2100
+ return value;
2101
+ }
2102
+ }
2103
+ function stringifyRules({ computedPropertyStringifier } = {}) {
2104
+ return {
2105
+ JsdocTypeParenthesis: (result, transform2) => `(${result.element !== void 0 ? transform2(result.element) : ""})`,
2106
+ JsdocTypeKeyof: (result, transform2) => `keyof ${transform2(result.element)}`,
2107
+ JsdocTypeFunction: (result, transform2) => {
2108
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2109
+ if (!result.arrow) {
2110
+ let stringified = result.constructor ? "new" : "function";
2111
+ if (!result.parenthesis) return stringified;
2112
+ stringified += `(${result.parameters.map(transform2).join(`,${((_a = result.meta) == null ? void 0 : _a.parameterSpacing) ?? " "}`)})`;
2113
+ if (result.returnType !== void 0) stringified += `${((_b = result.meta) == null ? void 0 : _b.preReturnMarkerSpacing) ?? ""}:${((_c = result.meta) == null ? void 0 : _c.postReturnMarkerSpacing) ?? " "}${transform2(result.returnType)}`;
2114
+ return stringified;
2115
+ } else {
2116
+ if (result.returnType === void 0) throw new Error("Arrow function needs a return type.");
2117
+ let stringified = `${result.typeParameters !== void 0 ? `<${result.typeParameters.map(transform2).join(`,${((_d = result.meta) == null ? void 0 : _d.typeParameterSpacing) ?? " "}`)}>${((_e = result.meta) == null ? void 0 : _e.postGenericSpacing) ?? ""}` : ""}(${result.parameters.map(transform2).join(`,${((_f = result.meta) == null ? void 0 : _f.parameterSpacing) ?? " "}`)})${((_g = result.meta) == null ? void 0 : _g.preReturnMarkerSpacing) ?? " "}=>${((_h = result.meta) == null ? void 0 : _h.postReturnMarkerSpacing) ?? " "}${transform2(result.returnType)}`;
2118
+ if (result.constructor) stringified = `new ${stringified}`;
2119
+ return stringified;
2120
+ }
2121
+ },
2122
+ JsdocTypeName: (result) => result.value,
2123
+ JsdocTypeInfer: (result, transform2) => `infer ${transform2(result.element)}`,
2124
+ JsdocTypeUniqueSymbol: () => "unique symbol",
2125
+ JsdocTypeTuple: (result, transform2) => {
2126
+ var _a;
2127
+ return `[${result.elements.map(transform2).join(`,${((_a = result.meta) == null ? void 0 : _a.elementSpacing) ?? " "}`)}]`;
2128
+ },
2129
+ JsdocTypeVariadic: (result, transform2) => result.meta.position === void 0 ? "..." : applyPosition(result.meta.position, transform2(result.element), "..."),
2130
+ JsdocTypeNamePath: (result, transform2) => {
2131
+ const left = transform2(result.left);
2132
+ const right = transform2(result.right);
2133
+ switch (result.pathType) {
2134
+ case "inner":
2135
+ return `${left}~${right}`;
2136
+ case "instance":
2137
+ return `${left}#${right}`;
2138
+ case "property":
2139
+ return `${left}.${right}`;
2140
+ case "property-brackets":
2141
+ return `${left}[${right}]`;
2142
+ }
2143
+ },
2144
+ JsdocTypeStringValue: (result) => quote(result.value, result.meta.quote),
2145
+ JsdocTypeAny: () => "*",
2146
+ JsdocTypeGeneric: (result, transform2) => {
2147
+ if (result.meta.brackets === "square") {
2148
+ const element = result.elements[0];
2149
+ const transformed = transform2(element);
2150
+ if (element.type === "JsdocTypeUnion" || element.type === "JsdocTypeIntersection") return `(${transformed})[]`;
2151
+ else return `${transformed}[]`;
2152
+ } else return `${transform2(result.left)}${result.meta.dot ? "." : ""}<${result.elements.map(transform2).join(`,${result.meta.elementSpacing ?? " "}`)}>`;
2153
+ },
2154
+ JsdocTypeImport: (result, transform2) => `import(${transform2(result.element)})`,
2155
+ JsdocTypeObjectField: (result, transform2) => {
2156
+ let text = "";
2157
+ if (result.readonly) text += "readonly ";
2158
+ let optionalBeforeParentheses = false;
2159
+ if (typeof result.key === "string") text += quote(result.key, result.meta.quote);
2160
+ else {
2161
+ if (result.key.type === "JsdocTypeComputedMethod") optionalBeforeParentheses = true;
2162
+ text += transform2(result.key);
2163
+ }
2164
+ text += result.meta.postKeySpacing ?? "";
2165
+ if (!optionalBeforeParentheses && result.optional) {
2166
+ text += "?";
2167
+ text += result.meta.postOptionalSpacing ?? "";
2168
+ }
2169
+ if (result.right === void 0) return text;
2170
+ else return `${text}:${result.meta.postColonSpacing ?? " "}${transform2(result.right)}`;
2171
+ },
2172
+ JsdocTypeJsdocObjectField: (result, transform2) => `${transform2(result.left)}: ${transform2(result.right)}`,
2173
+ JsdocTypeKeyValue: (result, transform2) => {
2174
+ var _a, _b, _c, _d, _e;
2175
+ let text = result.key;
2176
+ if (result.optional) text += `${((_a = result.meta) == null ? void 0 : _a.postKeySpacing) ?? ""}?${((_b = result.meta) == null ? void 0 : _b.postOptionalSpacing) ?? ""}`;
2177
+ else if (result.variadic) text = `...${((_c = result.meta) == null ? void 0 : _c.postVariadicSpacing) ?? ""}${text}`;
2178
+ else if (result.right !== void 0) text += ((_d = result.meta) == null ? void 0 : _d.postKeySpacing) ?? "";
2179
+ if (result.right === void 0) return text;
2180
+ else return `${text}:${((_e = result.meta) == null ? void 0 : _e.postColonSpacing) ?? " "}${transform2(result.right)}`;
2181
+ },
2182
+ JsdocTypeSpecialNamePath: (result) => `${result.specialType}:${quote(result.value, result.meta.quote)}`,
2183
+ JsdocTypeNotNullable: (result, transform2) => applyPosition(result.meta.position, transform2(result.element), "!"),
2184
+ JsdocTypeNull: () => "null",
2185
+ JsdocTypeNullable: (result, transform2) => applyPosition(result.meta.position, transform2(result.element), "?"),
2186
+ JsdocTypeNumber: (result) => result.value.toString(),
2187
+ JsdocTypeBigInt: (result) => `${result.value}n`,
2188
+ JsdocTypeObject: (result, transform2) => {
2189
+ const lbType = (result.meta.separator ?? "").endsWith("linebreak");
2190
+ const lbEnding = result.meta.separator === "comma-and-linebreak" ? ",\n" : result.meta.separator === "semicolon-and-linebreak" ? ";\n" : result.meta.separator === "linebreak" ? "\n" : "";
2191
+ const separatorForSingleObjectField = result.meta.separatorForSingleObjectField ?? false;
2192
+ const trailingPunctuation = result.meta.trailingPunctuation ?? false;
2193
+ const bracketSpacing = result.meta.bracketSpacing ?? "";
2194
+ return `{${(lbType && (separatorForSingleObjectField || result.elements.length > 1) ? `
2195
+ ${result.meta.propertyIndent ?? ""}` : bracketSpacing) + result.elements.map(transform2).join(result.meta.separator === "comma" ? ", " : lbType ? lbEnding + (result.meta.propertyIndent ?? "") : "; ") + (separatorForSingleObjectField && result.elements.length === 1 ? result.meta.separator === "comma" ? "," : lbType ? lbEnding : ";" : trailingPunctuation && result.meta.separator !== void 0 ? result.meta.separator.startsWith("comma") ? "," : result.meta.separator.startsWith("semicolon") ? ";" : "" : "") + (lbType && result.elements.length > 1 ? "\n" : bracketSpacing)}}`;
2196
+ },
2197
+ JsdocTypeOptional: (result, transform2) => applyPosition(result.meta.position, transform2(result.element), "="),
2198
+ JsdocTypeSymbol: (result, transform2) => `${result.value}(${result.element !== void 0 ? transform2(result.element) : ""})`,
2199
+ JsdocTypeTypeof: (result, transform2) => `typeof ${transform2(result.element)}`,
2200
+ JsdocTypeUndefined: () => "undefined",
2201
+ JsdocTypeUnion: (result, transform2) => {
2202
+ var _a;
2203
+ return result.elements.map(transform2).join(((_a = result.meta) == null ? void 0 : _a.spacing) === void 0 ? " | " : `${result.meta.spacing}|${result.meta.spacing}`);
2204
+ },
2205
+ JsdocTypeUnknown: () => "?",
2206
+ JsdocTypeIntersection: (result, transform2) => result.elements.map(transform2).join(" & "),
2207
+ JsdocTypeProperty: (result) => quote(result.value, result.meta.quote),
2208
+ JsdocTypePredicate: (result, transform2) => `${transform2(result.left)} is ${transform2(result.right)}`,
2209
+ JsdocTypeIndexSignature: (result, transform2) => `[${result.key}: ${transform2(result.right)}]`,
2210
+ JsdocTypeMappedType: (result, transform2) => `[${result.key} in ${transform2(result.right)}]`,
2211
+ JsdocTypeAsserts: (result, transform2) => `asserts ${transform2(result.left)} is ${transform2(result.right)}`,
2212
+ JsdocTypeReadonlyArray: (result, transform2) => `readonly ${transform2(result.element)}`,
2213
+ JsdocTypeAssertsPlain: (result, transform2) => `asserts ${transform2(result.element)}`,
2214
+ JsdocTypeConditional: (result, transform2) => `${transform2(result.checksType)} extends ${transform2(result.extendsType)} ? ${transform2(result.trueType)} : ${transform2(result.falseType)}`,
2215
+ JsdocTypeTypeParameter: (result, transform2) => {
2216
+ var _a, _b;
2217
+ return `${transform2(result.name)}${result.constraint !== void 0 ? ` extends ${transform2(result.constraint)}` : ""}${result.defaultValue !== void 0 ? `${((_a = result.meta) == null ? void 0 : _a.defaultValueSpacing) ?? " "}=${((_b = result.meta) == null ? void 0 : _b.defaultValueSpacing) ?? " "}${transform2(result.defaultValue)}` : ""}`;
2218
+ },
2219
+ JsdocTypeCallSignature: (result, transform2) => {
2220
+ var _a, _b, _c, _d, _e;
2221
+ return `${result.typeParameters !== void 0 ? `<${result.typeParameters.map(transform2).join(`,${((_a = result.meta) == null ? void 0 : _a.typeParameterSpacing) ?? " "}`)}>${((_b = result.meta) == null ? void 0 : _b.postGenericSpacing) ?? ""}` : ""}(${result.parameters.map(transform2).join(`,${((_c = result.meta) == null ? void 0 : _c.parameterSpacing) ?? " "}`)})${((_d = result.meta) == null ? void 0 : _d.preReturnMarkerSpacing) ?? ""}:${((_e = result.meta) == null ? void 0 : _e.postReturnMarkerSpacing) ?? " "}${transform2(result.returnType)}`;
2222
+ },
2223
+ JsdocTypeConstructorSignature: (result, transform2) => {
2224
+ var _a, _b, _c, _d, _e, _f;
2225
+ return `new${((_a = result.meta) == null ? void 0 : _a.postNewSpacing) ?? " "}${result.typeParameters !== void 0 ? `<${result.typeParameters.map(transform2).join(`,${((_b = result.meta) == null ? void 0 : _b.typeParameterSpacing) ?? " "}`)}>${((_c = result.meta) == null ? void 0 : _c.postGenericSpacing) ?? ""}` : ""}(${result.parameters.map(transform2).join(`,${((_d = result.meta) == null ? void 0 : _d.parameterSpacing) ?? " "}`)})${((_e = result.meta) == null ? void 0 : _e.preReturnMarkerSpacing) ?? ""}:${((_f = result.meta) == null ? void 0 : _f.postReturnMarkerSpacing) ?? " "}${transform2(result.returnType)}`;
2226
+ },
2227
+ JsdocTypeMethodSignature: (result, transform2) => {
2228
+ const quote2 = result.meta.quote === "double" ? '"' : result.meta.quote === "single" ? "'" : "";
2229
+ return `${quote2}${result.name}${quote2}${result.meta.postMethodNameSpacing ?? ""}${result.typeParameters !== void 0 ? `<${result.typeParameters.map(transform2).join(`,${result.meta.typeParameterSpacing ?? " "}`)}>${result.meta.postGenericSpacing ?? ""}` : ""}(${result.parameters.map(transform2).join(`,${result.meta.parameterSpacing ?? " "}`)})${result.meta.preReturnMarkerSpacing ?? ""}:${result.meta.postReturnMarkerSpacing ?? " "}${transform2(result.returnType)}`;
2230
+ },
2231
+ JsdocTypeIndexedAccessIndex: (result, transform2) => transform2(result.right),
2232
+ JsdocTypeTemplateLiteral: (result, transform2) => `\`${result.literals.slice(0, -1).map((literal, idx) => `${literal.replace(new RegExp("`", "gv"), "\\`")}\${${transform2(result.interpolations[idx])}}`).join("") + result.literals.slice(-1)[0].replace(new RegExp("`", "gv"), "\\`")}\``,
2233
+ JsdocTypeComputedProperty: (result, transform2) => {
2234
+ if (result.value.type.startsWith("JsdocType")) return `[${transform2(result.value)}]`;
2235
+ else {
2236
+ if (computedPropertyStringifier === void 0) throw new Error("Must have a computed property stringifier");
2237
+ return `[${computedPropertyStringifier(result.value).replace(new RegExp(";$", "v"), "")}]`;
2238
+ }
2239
+ },
2240
+ JsdocTypeComputedMethod: (result, transform2) => {
2241
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2242
+ if (result.value.type.startsWith("JsdocType")) return `[${transform2(result.value)}]${result.optional ? "?" : ""}${result.typeParameters !== void 0 ? `<${result.typeParameters.map(transform2).join(`,${((_a = result.meta) == null ? void 0 : _a.typeParameterSpacing) ?? " "}`)}>${((_b = result.meta) == null ? void 0 : _b.postGenericSpacing) ?? ""}` : ""}(${result.parameters.map(transform2).join(`,${((_c = result.meta) == null ? void 0 : _c.parameterSpacing) ?? " "}`)})${((_d = result.meta) == null ? void 0 : _d.preReturnMarkerSpacing) ?? ""}:${((_e = result.meta) == null ? void 0 : _e.postReturnMarkerSpacing) ?? " "}${transform2(result.returnType)}`;
2243
+ else {
2244
+ if (computedPropertyStringifier === void 0) throw new Error("Must have a computed property stringifier");
2245
+ return `[${computedPropertyStringifier(result.value).replace(new RegExp(";$", "v"), "")}](${result.parameters.map(transform2).join(`,${((_f = result.meta) == null ? void 0 : _f.parameterSpacing) ?? " "}`)})${((_g = result.meta) == null ? void 0 : _g.preReturnMarkerSpacing) ?? ""}:${((_h = result.meta) == null ? void 0 : _h.postReturnMarkerSpacing) ?? " "}${transform2(result.returnType)}`;
2246
+ }
2247
+ }
2248
+ };
2249
+ }
2250
+ var storedStringifyRules = stringifyRules();
2251
+ function stringify(result, stringificationRules = storedStringifyRules) {
2252
+ if (typeof stringificationRules === "function") stringificationRules = stringifyRules({ computedPropertyStringifier: stringificationRules });
2253
+ return transform(stringificationRules, result);
2254
+ }
2255
+ var reservedWords = [
2256
+ "null",
2257
+ "true",
2258
+ "false",
2259
+ "break",
2260
+ "case",
2261
+ "catch",
2262
+ "class",
2263
+ "const",
2264
+ "continue",
2265
+ "debugger",
2266
+ "default",
2267
+ "delete",
2268
+ "do",
2269
+ "else",
2270
+ "export",
2271
+ "extends",
2272
+ "finally",
2273
+ "for",
2274
+ "function",
2275
+ "if",
2276
+ "import",
2277
+ "in",
2278
+ "instanceof",
2279
+ "new",
2280
+ "return",
2281
+ "super",
2282
+ "switch",
2283
+ "this",
2284
+ "throw",
2285
+ "try",
2286
+ "typeof",
2287
+ "var",
2288
+ "void",
2289
+ "while",
2290
+ "with",
2291
+ "yield"
2292
+ ];
2293
+ function makeName(value) {
2294
+ const result = {
2295
+ type: "NameExpression",
2296
+ name: value
2297
+ };
2298
+ if (reservedWords.includes(value)) result.reservedWord = true;
2299
+ return result;
2300
+ }
2301
+ var catharsisTransformRules = {
2302
+ JsdocTypeOptional: (result, transform2) => {
2303
+ const transformed = transform2(result.element);
2304
+ transformed.optional = true;
2305
+ return transformed;
2306
+ },
2307
+ JsdocTypeNullable: (result, transform2) => {
2308
+ const transformed = transform2(result.element);
2309
+ transformed.nullable = true;
2310
+ return transformed;
2311
+ },
2312
+ JsdocTypeNotNullable: (result, transform2) => {
2313
+ const transformed = transform2(result.element);
2314
+ transformed.nullable = false;
2315
+ return transformed;
2316
+ },
2317
+ JsdocTypeVariadic: (result, transform2) => {
2318
+ if (result.element === void 0) throw new Error("dots without value are not allowed in catharsis mode");
2319
+ const transformed = transform2(result.element);
2320
+ transformed.repeatable = true;
2321
+ return transformed;
2322
+ },
2323
+ JsdocTypeAny: () => ({ type: "AllLiteral" }),
2324
+ JsdocTypeNull: () => ({ type: "NullLiteral" }),
2325
+ JsdocTypeStringValue: (result) => makeName(quote(result.value, result.meta.quote)),
2326
+ JsdocTypeUndefined: () => ({ type: "UndefinedLiteral" }),
2327
+ JsdocTypeUnknown: () => ({ type: "UnknownLiteral" }),
2328
+ JsdocTypeFunction: (result, transform2) => {
2329
+ const params = extractSpecialParams(result);
2330
+ const transformed = {
2331
+ type: "FunctionType",
2332
+ params: params.params.map(transform2)
2333
+ };
2334
+ if (params.this !== void 0) transformed.this = transform2(params.this);
2335
+ if (params.new !== void 0) transformed.new = transform2(params.new);
2336
+ if (result.returnType !== void 0) transformed.result = transform2(result.returnType);
2337
+ return transformed;
2338
+ },
2339
+ JsdocTypeGeneric: (result, transform2) => ({
2340
+ type: "TypeApplication",
2341
+ applications: result.elements.map((o) => transform2(o)),
2342
+ expression: transform2(result.left)
2343
+ }),
2344
+ JsdocTypeSpecialNamePath: (result) => makeName(`${result.specialType}:${quote(result.value, result.meta.quote)}`),
2345
+ JsdocTypeName: (result) => {
2346
+ if (result.value !== "function") return makeName(result.value);
2347
+ else return {
2348
+ type: "FunctionType",
2349
+ params: []
2350
+ };
2351
+ },
2352
+ JsdocTypeNumber: (result) => makeName(result.value.toString()),
2353
+ JsdocTypeBigInt: (result) => makeName(`${result.value}n`),
2354
+ JsdocTypeObject: (result, transform2) => {
2355
+ const transformed = {
2356
+ type: "RecordType",
2357
+ fields: []
2358
+ };
2359
+ for (const field of result.elements) if (field.type !== "JsdocTypeObjectField" && field.type !== "JsdocTypeJsdocObjectField") transformed.fields.push({
2360
+ type: "FieldType",
2361
+ key: transform2(field),
2362
+ value: void 0
2363
+ });
2364
+ else transformed.fields.push(transform2(field));
2365
+ return transformed;
2366
+ },
2367
+ JsdocTypeObjectField: (result, transform2) => {
2368
+ if (typeof result.key !== "string") throw new Error("Index signatures and mapped types are not supported");
2369
+ return {
2370
+ type: "FieldType",
2371
+ key: makeName(quote(result.key, result.meta.quote)),
2372
+ value: result.right === void 0 ? void 0 : transform2(result.right)
2373
+ };
2374
+ },
2375
+ JsdocTypeJsdocObjectField: (result, transform2) => ({
2376
+ type: "FieldType",
2377
+ key: transform2(result.left),
2378
+ value: transform2(result.right)
2379
+ }),
2380
+ JsdocTypeUnion: (result, transform2) => ({
2381
+ type: "TypeUnion",
2382
+ elements: result.elements.map((e) => transform2(e))
2383
+ }),
2384
+ JsdocTypeKeyValue: (result, transform2) => ({
2385
+ type: "FieldType",
2386
+ key: makeName(result.key),
2387
+ value: result.right === void 0 ? void 0 : transform2(result.right)
2388
+ }),
2389
+ JsdocTypeNamePath: (result, transform2) => {
2390
+ const leftResult = transform2(result.left);
2391
+ let rightValue;
2392
+ if (result.right.type === "JsdocTypeIndexedAccessIndex") throw new TypeError("JsdocTypeIndexedAccessIndex is not supported in catharsis");
2393
+ if (result.right.type === "JsdocTypeSpecialNamePath") rightValue = transform2(result.right).name;
2394
+ else rightValue = quote(result.right.value, result.right.meta.quote);
2395
+ const joiner = result.pathType === "inner" ? "~" : result.pathType === "instance" ? "#" : ".";
2396
+ return makeName(`${leftResult.name}${joiner}${rightValue}`);
2397
+ },
2398
+ JsdocTypeSymbol: (result) => {
2399
+ let value = "";
2400
+ let element = result.element;
2401
+ let trailingDots = false;
2402
+ if ((element == null ? void 0 : element.type) === "JsdocTypeVariadic") {
2403
+ if (element.meta.position === "prefix") value = "...";
2404
+ else trailingDots = true;
2405
+ element = element.element;
2406
+ }
2407
+ if ((element == null ? void 0 : element.type) === "JsdocTypeName") value += element.value;
2408
+ else if ((element == null ? void 0 : element.type) === "JsdocTypeNumber") value += element.value.toString();
2409
+ if (trailingDots) value += "...";
2410
+ return makeName(`${result.value}(${value})`);
2411
+ },
2412
+ JsdocTypeParenthesis: (result, transform2) => transform2(assertRootResult(result.element)),
2413
+ JsdocTypeMappedType: notAvailableTransform,
2414
+ JsdocTypeIndexSignature: notAvailableTransform,
2415
+ JsdocTypeInfer: notAvailableTransform,
2416
+ JsdocTypeUniqueSymbol: notAvailableTransform,
2417
+ JsdocTypeImport: notAvailableTransform,
2418
+ JsdocTypeKeyof: notAvailableTransform,
2419
+ JsdocTypeTuple: notAvailableTransform,
2420
+ JsdocTypeTypeof: notAvailableTransform,
2421
+ JsdocTypeIntersection: notAvailableTransform,
2422
+ JsdocTypeProperty: notAvailableTransform,
2423
+ JsdocTypePredicate: notAvailableTransform,
2424
+ JsdocTypeAsserts: notAvailableTransform,
2425
+ JsdocTypeReadonlyArray: notAvailableTransform,
2426
+ JsdocTypeAssertsPlain: notAvailableTransform,
2427
+ JsdocTypeConditional: notAvailableTransform,
2428
+ JsdocTypeTypeParameter: notAvailableTransform,
2429
+ JsdocTypeCallSignature: notAvailableTransform,
2430
+ JsdocTypeConstructorSignature: notAvailableTransform,
2431
+ JsdocTypeMethodSignature: notAvailableTransform,
2432
+ JsdocTypeIndexedAccessIndex: notAvailableTransform,
2433
+ JsdocTypeTemplateLiteral: notAvailableTransform,
2434
+ JsdocTypeComputedProperty: notAvailableTransform,
2435
+ JsdocTypeComputedMethod: notAvailableTransform
2436
+ };
2437
+ function catharsisTransform(result) {
2438
+ return transform(catharsisTransformRules, result);
2439
+ }
2440
+ function getQuoteStyle(quote2) {
2441
+ switch (quote2) {
2442
+ case void 0:
2443
+ return "none";
2444
+ case "single":
2445
+ return "single";
2446
+ case "double":
2447
+ return "double";
2448
+ }
2449
+ }
2450
+ function getMemberType(type) {
2451
+ switch (type) {
2452
+ case "inner":
2453
+ return "INNER_MEMBER";
2454
+ case "instance":
2455
+ return "INSTANCE_MEMBER";
2456
+ case "property":
2457
+ return "MEMBER";
2458
+ case "property-brackets":
2459
+ return "MEMBER";
2460
+ }
2461
+ }
2462
+ function nestResults(type, results) {
2463
+ if (results.length === 2) return {
2464
+ type,
2465
+ left: results[0],
2466
+ right: results[1]
2467
+ };
2468
+ else return {
2469
+ type,
2470
+ left: results[0],
2471
+ right: nestResults(type, results.slice(1))
2472
+ };
2473
+ }
2474
+ var jtpRules = {
2475
+ JsdocTypeOptional: (result, transform2) => ({
2476
+ type: "OPTIONAL",
2477
+ value: transform2(result.element),
2478
+ meta: { syntax: result.meta.position === "prefix" ? "PREFIX_EQUAL_SIGN" : "SUFFIX_EQUALS_SIGN" }
2479
+ }),
2480
+ JsdocTypeNullable: (result, transform2) => ({
2481
+ type: "NULLABLE",
2482
+ value: transform2(result.element),
2483
+ meta: { syntax: result.meta.position === "prefix" ? "PREFIX_QUESTION_MARK" : "SUFFIX_QUESTION_MARK" }
2484
+ }),
2485
+ JsdocTypeNotNullable: (result, transform2) => ({
2486
+ type: "NOT_NULLABLE",
2487
+ value: transform2(result.element),
2488
+ meta: { syntax: result.meta.position === "prefix" ? "PREFIX_BANG" : "SUFFIX_BANG" }
2489
+ }),
2490
+ JsdocTypeVariadic: (result, transform2) => {
2491
+ const transformed = {
2492
+ type: "VARIADIC",
2493
+ meta: { syntax: result.meta.position === "prefix" ? "PREFIX_DOTS" : result.meta.position === "suffix" ? "SUFFIX_DOTS" : "ONLY_DOTS" }
2494
+ };
2495
+ if (result.element !== void 0) transformed.value = transform2(result.element);
2496
+ return transformed;
2497
+ },
2498
+ JsdocTypeName: (result) => ({
2499
+ type: "NAME",
2500
+ name: result.value
2501
+ }),
2502
+ JsdocTypeTypeof: (result, transform2) => ({
2503
+ type: "TYPE_QUERY",
2504
+ name: transform2(result.element)
2505
+ }),
2506
+ JsdocTypeTuple: (result, transform2) => ({
2507
+ type: "TUPLE",
2508
+ entries: result.elements.map(transform2)
2509
+ }),
2510
+ JsdocTypeKeyof: (result, transform2) => ({
2511
+ type: "KEY_QUERY",
2512
+ value: transform2(result.element)
2513
+ }),
2514
+ JsdocTypeImport: (result) => ({
2515
+ type: "IMPORT",
2516
+ path: {
2517
+ type: "STRING_VALUE",
2518
+ quoteStyle: getQuoteStyle(result.element.meta.quote),
2519
+ string: result.element.value
2520
+ }
2521
+ }),
2522
+ JsdocTypeUndefined: () => ({
2523
+ type: "NAME",
2524
+ name: "undefined"
2525
+ }),
2526
+ JsdocTypeAny: () => ({ type: "ANY" }),
2527
+ JsdocTypeFunction: (result, transform2) => {
2528
+ const specialParams = extractSpecialParams(result);
2529
+ const transformed = {
2530
+ type: result.arrow ? "ARROW" : "FUNCTION",
2531
+ params: specialParams.params.map((param) => {
2532
+ if (param.type === "JsdocTypeKeyValue") {
2533
+ if (param.right === void 0) throw new Error("Function parameter without ':' is not expected to be 'KEY_VALUE'");
2534
+ return {
2535
+ type: "NAMED_PARAMETER",
2536
+ name: param.key,
2537
+ typeName: transform2(param.right)
2538
+ };
2539
+ } else return transform2(param);
2540
+ }),
2541
+ new: null,
2542
+ returns: null
2543
+ };
2544
+ if (specialParams.this !== void 0) transformed.this = transform2(specialParams.this);
2545
+ else if (!result.arrow) transformed.this = null;
2546
+ if (specialParams.new !== void 0) transformed.new = transform2(specialParams.new);
2547
+ if (result.returnType !== void 0) transformed.returns = transform2(result.returnType);
2548
+ return transformed;
2549
+ },
2550
+ JsdocTypeGeneric: (result, transform2) => {
2551
+ const transformed = {
2552
+ type: "GENERIC",
2553
+ subject: transform2(result.left),
2554
+ objects: result.elements.map(transform2),
2555
+ meta: { syntax: result.meta.brackets === "square" ? "SQUARE_BRACKET" : result.meta.dot ? "ANGLE_BRACKET_WITH_DOT" : "ANGLE_BRACKET" }
2556
+ };
2557
+ if (result.meta.brackets === "square" && result.elements[0].type === "JsdocTypeFunction" && !result.elements[0].parenthesis) transformed.objects[0] = {
2558
+ type: "NAME",
2559
+ name: "function"
2560
+ };
2561
+ return transformed;
2562
+ },
2563
+ JsdocTypeObjectField: (result, transform2) => {
2564
+ if (typeof result.key !== "string") throw new Error("Index signatures and mapped types are not supported");
2565
+ if (result.right === void 0) return {
2566
+ type: "RECORD_ENTRY",
2567
+ key: result.key,
2568
+ quoteStyle: getQuoteStyle(result.meta.quote),
2569
+ value: null,
2570
+ readonly: false
2571
+ };
2572
+ let right = transform2(result.right);
2573
+ if (result.optional) right = {
2574
+ type: "OPTIONAL",
2575
+ value: right,
2576
+ meta: { syntax: "SUFFIX_KEY_QUESTION_MARK" }
2577
+ };
2578
+ return {
2579
+ type: "RECORD_ENTRY",
2580
+ key: result.key,
2581
+ quoteStyle: getQuoteStyle(result.meta.quote),
2582
+ value: right,
2583
+ readonly: false
2584
+ };
2585
+ },
2586
+ JsdocTypeJsdocObjectField: () => {
2587
+ throw new Error("Keys may not be typed in jsdoctypeparser.");
2588
+ },
2589
+ JsdocTypeKeyValue: (result, transform2) => {
2590
+ if (result.right === void 0) return {
2591
+ type: "RECORD_ENTRY",
2592
+ key: result.key,
2593
+ quoteStyle: "none",
2594
+ value: null,
2595
+ readonly: false
2596
+ };
2597
+ let right = transform2(result.right);
2598
+ if (result.optional) right = {
2599
+ type: "OPTIONAL",
2600
+ value: right,
2601
+ meta: { syntax: "SUFFIX_KEY_QUESTION_MARK" }
2602
+ };
2603
+ return {
2604
+ type: "RECORD_ENTRY",
2605
+ key: result.key,
2606
+ quoteStyle: "none",
2607
+ value: right,
2608
+ readonly: false
2609
+ };
2610
+ },
2611
+ JsdocTypeObject: (result, transform2) => {
2612
+ const entries = [];
2613
+ for (const field of result.elements) if (field.type === "JsdocTypeObjectField" || field.type === "JsdocTypeJsdocObjectField") entries.push(transform2(field));
2614
+ return {
2615
+ type: "RECORD",
2616
+ entries
2617
+ };
2618
+ },
2619
+ JsdocTypeSpecialNamePath: (result) => {
2620
+ if (result.specialType !== "module") throw new Error(`jsdoctypeparser does not support type ${result.specialType} at this point.`);
2621
+ return {
2622
+ type: "MODULE",
2623
+ value: {
2624
+ type: "FILE_PATH",
2625
+ quoteStyle: getQuoteStyle(result.meta.quote),
2626
+ path: result.value
2627
+ }
2628
+ };
2629
+ },
2630
+ JsdocTypeNamePath: (result, transform2) => {
2631
+ let hasEventPrefix = false;
2632
+ let name;
2633
+ let quoteStyle;
2634
+ if (result.right.type === "JsdocTypeIndexedAccessIndex") throw new TypeError("JsdocTypeIndexedAccessIndex not allowed in jtp");
2635
+ if (result.right.type === "JsdocTypeSpecialNamePath" && result.right.specialType === "event") {
2636
+ hasEventPrefix = true;
2637
+ name = result.right.value;
2638
+ quoteStyle = getQuoteStyle(result.right.meta.quote);
2639
+ } else {
2640
+ name = result.right.value;
2641
+ quoteStyle = getQuoteStyle(result.right.meta.quote);
2642
+ }
2643
+ const transformed = {
2644
+ type: getMemberType(result.pathType),
2645
+ owner: transform2(result.left),
2646
+ name,
2647
+ quoteStyle,
2648
+ hasEventPrefix
2649
+ };
2650
+ if (transformed.owner.type === "MODULE") {
2651
+ const tModule = transformed.owner;
2652
+ transformed.owner = transformed.owner.value;
2653
+ tModule.value = transformed;
2654
+ return tModule;
2655
+ } else return transformed;
2656
+ },
2657
+ JsdocTypeUnion: (result, transform2) => nestResults("UNION", result.elements.map(transform2)),
2658
+ JsdocTypeParenthesis: (result, transform2) => ({
2659
+ type: "PARENTHESIS",
2660
+ value: transform2(assertRootResult(result.element))
2661
+ }),
2662
+ JsdocTypeNull: () => ({
2663
+ type: "NAME",
2664
+ name: "null"
2665
+ }),
2666
+ JsdocTypeUnknown: () => ({ type: "UNKNOWN" }),
2667
+ JsdocTypeStringValue: (result) => ({
2668
+ type: "STRING_VALUE",
2669
+ quoteStyle: getQuoteStyle(result.meta.quote),
2670
+ string: result.value
2671
+ }),
2672
+ JsdocTypeIntersection: (result, transform2) => nestResults("INTERSECTION", result.elements.map(transform2)),
2673
+ JsdocTypeNumber: (result) => ({
2674
+ type: "NUMBER_VALUE",
2675
+ number: result.value.toString()
2676
+ }),
2677
+ JsdocTypeBigInt: (result) => ({
2678
+ type: "NUMBER_VALUE",
2679
+ number: `${result.value}n`
2680
+ }),
2681
+ JsdocTypeSymbol: notAvailableTransform,
2682
+ JsdocTypeProperty: notAvailableTransform,
2683
+ JsdocTypePredicate: notAvailableTransform,
2684
+ JsdocTypeMappedType: notAvailableTransform,
2685
+ JsdocTypeIndexSignature: notAvailableTransform,
2686
+ JsdocTypeInfer: notAvailableTransform,
2687
+ JsdocTypeUniqueSymbol: notAvailableTransform,
2688
+ JsdocTypeAsserts: notAvailableTransform,
2689
+ JsdocTypeReadonlyArray: notAvailableTransform,
2690
+ JsdocTypeAssertsPlain: notAvailableTransform,
2691
+ JsdocTypeConditional: notAvailableTransform,
2692
+ JsdocTypeTypeParameter: notAvailableTransform,
2693
+ JsdocTypeCallSignature: notAvailableTransform,
2694
+ JsdocTypeConstructorSignature: notAvailableTransform,
2695
+ JsdocTypeMethodSignature: notAvailableTransform,
2696
+ JsdocTypeIndexedAccessIndex: notAvailableTransform,
2697
+ JsdocTypeTemplateLiteral: notAvailableTransform,
2698
+ JsdocTypeComputedProperty: notAvailableTransform,
2699
+ JsdocTypeComputedMethod: notAvailableTransform
2700
+ };
2701
+ function jtpTransform(result) {
2702
+ return transform(jtpRules, result);
2703
+ }
2704
+ function identityTransformRules() {
2705
+ return {
2706
+ JsdocTypeIntersection: (result, transform2) => ({
2707
+ type: "JsdocTypeIntersection",
2708
+ elements: result.elements.map(transform2)
2709
+ }),
2710
+ JsdocTypeGeneric: (result, transform2) => ({
2711
+ type: "JsdocTypeGeneric",
2712
+ left: transform2(result.left),
2713
+ elements: result.elements.map(transform2),
2714
+ meta: {
2715
+ dot: result.meta.dot,
2716
+ brackets: result.meta.brackets
2717
+ }
2718
+ }),
2719
+ JsdocTypeNullable: (result) => result,
2720
+ JsdocTypeUnion: (result, transform2) => ({
2721
+ type: "JsdocTypeUnion",
2722
+ elements: result.elements.map(transform2)
2723
+ }),
2724
+ JsdocTypeUnknown: (result) => result,
2725
+ JsdocTypeUndefined: (result) => result,
2726
+ JsdocTypeTypeof: (result, transform2) => ({
2727
+ type: "JsdocTypeTypeof",
2728
+ element: transform2(result.element)
2729
+ }),
2730
+ JsdocTypeSymbol: (result, transform2) => {
2731
+ const transformed = {
2732
+ type: "JsdocTypeSymbol",
2733
+ value: result.value
2734
+ };
2735
+ if (result.element !== void 0) transformed.element = transform2(result.element);
2736
+ return transformed;
2737
+ },
2738
+ JsdocTypeOptional: (result, transform2) => ({
2739
+ type: "JsdocTypeOptional",
2740
+ element: transform2(result.element),
2741
+ meta: { position: result.meta.position }
2742
+ }),
2743
+ JsdocTypeObject: (result, transform2) => ({
2744
+ type: "JsdocTypeObject",
2745
+ meta: { separator: "comma" },
2746
+ elements: result.elements.map(transform2)
2747
+ }),
2748
+ JsdocTypeNumber: (result) => result,
2749
+ JsdocTypeBigInt: (result) => result,
2750
+ JsdocTypeNull: (result) => result,
2751
+ JsdocTypeNotNullable: (result, transform2) => ({
2752
+ type: "JsdocTypeNotNullable",
2753
+ element: transform2(result.element),
2754
+ meta: { position: result.meta.position }
2755
+ }),
2756
+ JsdocTypeSpecialNamePath: (result) => result,
2757
+ JsdocTypeObjectField: (result, transform2) => ({
2758
+ type: "JsdocTypeObjectField",
2759
+ key: result.key,
2760
+ right: result.right === void 0 ? void 0 : transform2(result.right),
2761
+ optional: result.optional,
2762
+ readonly: result.readonly,
2763
+ meta: result.meta
2764
+ }),
2765
+ JsdocTypeJsdocObjectField: (result, transform2) => ({
2766
+ type: "JsdocTypeJsdocObjectField",
2767
+ left: transform2(result.left),
2768
+ right: transform2(result.right)
2769
+ }),
2770
+ JsdocTypeKeyValue: (result, transform2) => ({
2771
+ type: "JsdocTypeKeyValue",
2772
+ key: result.key,
2773
+ right: result.right === void 0 ? void 0 : transform2(result.right),
2774
+ optional: result.optional,
2775
+ variadic: result.variadic
2776
+ }),
2777
+ JsdocTypeImport: (result, transform2) => ({
2778
+ type: "JsdocTypeImport",
2779
+ element: transform2(result.element)
2780
+ }),
2781
+ JsdocTypeAny: (result) => result,
2782
+ JsdocTypeStringValue: (result) => result,
2783
+ JsdocTypeNamePath: (result) => result,
2784
+ JsdocTypeVariadic: (result, transform2) => {
2785
+ const transformed = {
2786
+ type: "JsdocTypeVariadic",
2787
+ meta: {
2788
+ position: result.meta.position,
2789
+ squareBrackets: result.meta.squareBrackets
2790
+ }
2791
+ };
2792
+ if (result.element !== void 0) transformed.element = transform2(result.element);
2793
+ return transformed;
2794
+ },
2795
+ JsdocTypeTuple: (result, transform2) => ({
2796
+ type: "JsdocTypeTuple",
2797
+ elements: result.elements.map(transform2)
2798
+ }),
2799
+ JsdocTypeName: (result) => result,
2800
+ JsdocTypeInfer: (result, transform2) => ({
2801
+ type: "JsdocTypeInfer",
2802
+ element: transform2(result.element)
2803
+ }),
2804
+ JsdocTypeUniqueSymbol: (result) => result,
2805
+ JsdocTypeFunction: (result, transform2) => {
2806
+ const transformed = {
2807
+ type: "JsdocTypeFunction",
2808
+ arrow: result.arrow,
2809
+ parameters: result.parameters.map(transform2),
2810
+ constructor: result.constructor,
2811
+ parenthesis: result.parenthesis
2812
+ };
2813
+ if (result.returnType !== void 0) transformed.returnType = transform2(result.returnType);
2814
+ return transformed;
2815
+ },
2816
+ JsdocTypeKeyof: (result, transform2) => ({
2817
+ type: "JsdocTypeKeyof",
2818
+ element: transform2(result.element)
2819
+ }),
2820
+ JsdocTypeParenthesis: (result, transform2) => ({
2821
+ type: "JsdocTypeParenthesis",
2822
+ element: transform2(result.element)
2823
+ }),
2824
+ JsdocTypeProperty: (result) => result,
2825
+ JsdocTypePredicate: (result, transform2) => ({
2826
+ type: "JsdocTypePredicate",
2827
+ left: transform2(result.left),
2828
+ right: transform2(result.right)
2829
+ }),
2830
+ JsdocTypeIndexSignature: (result, transform2) => ({
2831
+ type: "JsdocTypeIndexSignature",
2832
+ key: result.key,
2833
+ right: transform2(result.right)
2834
+ }),
2835
+ JsdocTypeMappedType: (result, transform2) => ({
2836
+ type: "JsdocTypeMappedType",
2837
+ key: result.key,
2838
+ right: transform2(result.right)
2839
+ }),
2840
+ JsdocTypeAsserts: (result, transform2) => ({
2841
+ type: "JsdocTypeAsserts",
2842
+ left: transform2(result.left),
2843
+ right: transform2(result.right)
2844
+ }),
2845
+ JsdocTypeReadonlyArray: (result, transform2) => ({
2846
+ type: "JsdocTypeReadonlyArray",
2847
+ element: transform2(result.element)
2848
+ }),
2849
+ JsdocTypeAssertsPlain: (result, transform2) => ({
2850
+ type: "JsdocTypeAssertsPlain",
2851
+ element: transform2(result.element)
2852
+ }),
2853
+ JsdocTypeConditional: (result, transform2) => ({
2854
+ type: "JsdocTypeConditional",
2855
+ checksType: transform2(result.checksType),
2856
+ extendsType: transform2(result.extendsType),
2857
+ trueType: transform2(result.trueType),
2858
+ falseType: transform2(result.falseType)
2859
+ }),
2860
+ JsdocTypeTypeParameter: (result, transform2) => ({
2861
+ type: "JsdocTypeTypeParameter",
2862
+ name: transform2(result.name),
2863
+ constraint: result.constraint !== void 0 ? transform2(result.constraint) : void 0,
2864
+ defaultValue: result.defaultValue !== void 0 ? transform2(result.defaultValue) : void 0
2865
+ }),
2866
+ JsdocTypeCallSignature: (result, transform2) => ({
2867
+ type: "JsdocTypeCallSignature",
2868
+ parameters: result.parameters.map(transform2),
2869
+ returnType: transform2(result.returnType)
2870
+ }),
2871
+ JsdocTypeConstructorSignature: (result, transform2) => ({
2872
+ type: "JsdocTypeConstructorSignature",
2873
+ parameters: result.parameters.map(transform2),
2874
+ returnType: transform2(result.returnType)
2875
+ }),
2876
+ JsdocTypeMethodSignature: (result, transform2) => ({
2877
+ type: "JsdocTypeMethodSignature",
2878
+ name: result.name,
2879
+ parameters: result.parameters.map(transform2),
2880
+ returnType: transform2(result.returnType),
2881
+ meta: result.meta
2882
+ }),
2883
+ JsdocTypeIndexedAccessIndex: (result, transform2) => ({
2884
+ type: "JsdocTypeIndexedAccessIndex",
2885
+ right: transform2(result.right)
2886
+ }),
2887
+ JsdocTypeTemplateLiteral: (result, transform2) => ({
2888
+ type: "JsdocTypeTemplateLiteral",
2889
+ literals: result.literals,
2890
+ interpolations: result.interpolations.map(transform2)
2891
+ }),
2892
+ JsdocTypeComputedProperty: (result, transform2) => {
2893
+ if (result.value.type.startsWith("JsdocType")) return {
2894
+ type: "JsdocTypeComputedProperty",
2895
+ value: transform2(result.value)
2896
+ };
2897
+ else return {
2898
+ type: "JsdocTypeComputedProperty",
2899
+ value: structuredClone(result.value)
2900
+ };
2901
+ },
2902
+ JsdocTypeComputedMethod: (result, transform2) => {
2903
+ if (result.value.type.startsWith("JsdocType")) return {
2904
+ type: "JsdocTypeComputedMethod",
2905
+ value: transform2(result.value),
2906
+ optional: result.optional,
2907
+ parameters: result.parameters.map(transform2),
2908
+ returnType: transform2(result.returnType)
2909
+ };
2910
+ else return {
2911
+ type: "JsdocTypeComputedMethod",
2912
+ value: structuredClone(result.value),
2913
+ optional: result.optional,
2914
+ parameters: result.parameters.map(transform2),
2915
+ returnType: transform2(result.returnType)
2916
+ };
2917
+ }
2918
+ };
2919
+ }
2920
+ var visitorKeys = {
2921
+ JsdocTypeAny: [],
2922
+ JsdocTypeBigInt: [],
2923
+ JsdocTypeFunction: [
2924
+ "typeParameters",
2925
+ "parameters",
2926
+ "returnType"
2927
+ ],
2928
+ JsdocTypeGeneric: ["left", "elements"],
2929
+ JsdocTypeImport: ["element"],
2930
+ JsdocTypeIndexSignature: ["right"],
2931
+ JsdocTypeIntersection: ["elements"],
2932
+ JsdocTypeKeyof: ["element"],
2933
+ JsdocTypeKeyValue: ["right"],
2934
+ JsdocTypeMappedType: ["right"],
2935
+ JsdocTypeName: [],
2936
+ JsdocTypeInfer: ["element"],
2937
+ JsdocTypeUniqueSymbol: [],
2938
+ JsdocTypeNamePath: ["left", "right"],
2939
+ JsdocTypeNotNullable: ["element"],
2940
+ JsdocTypeNull: [],
2941
+ JsdocTypeNullable: ["element"],
2942
+ JsdocTypeNumber: [],
2943
+ JsdocTypeObject: ["elements"],
2944
+ JsdocTypeObjectField: ["key", "right"],
2945
+ JsdocTypeJsdocObjectField: ["left", "right"],
2946
+ JsdocTypeOptional: ["element"],
2947
+ JsdocTypeParenthesis: ["element"],
2948
+ JsdocTypeSpecialNamePath: [],
2949
+ JsdocTypeStringValue: [],
2950
+ JsdocTypeSymbol: ["element"],
2951
+ JsdocTypeTuple: ["elements"],
2952
+ JsdocTypeTypeof: ["element"],
2953
+ JsdocTypeUndefined: [],
2954
+ JsdocTypeUnion: ["elements"],
2955
+ JsdocTypeUnknown: [],
2956
+ JsdocTypeVariadic: ["element"],
2957
+ JsdocTypeProperty: [],
2958
+ JsdocTypePredicate: ["left", "right"],
2959
+ JsdocTypeAsserts: ["left", "right"],
2960
+ JsdocTypeReadonlyArray: ["element"],
2961
+ JsdocTypeAssertsPlain: ["element"],
2962
+ JsdocTypeConditional: [
2963
+ "checksType",
2964
+ "extendsType",
2965
+ "trueType",
2966
+ "falseType"
2967
+ ],
2968
+ JsdocTypeTypeParameter: [
2969
+ "name",
2970
+ "constraint",
2971
+ "defaultValue"
2972
+ ],
2973
+ JsdocTypeCallSignature: [
2974
+ "typeParameters",
2975
+ "parameters",
2976
+ "returnType"
2977
+ ],
2978
+ JsdocTypeConstructorSignature: [
2979
+ "typeParameters",
2980
+ "parameters",
2981
+ "returnType"
2982
+ ],
2983
+ JsdocTypeMethodSignature: [
2984
+ "typeParameters",
2985
+ "parameters",
2986
+ "returnType"
2987
+ ],
2988
+ JsdocTypeIndexedAccessIndex: ["right"],
2989
+ JsdocTypeTemplateLiteral: ["interpolations"],
2990
+ JsdocTypeComputedProperty: ["value"],
2991
+ JsdocTypeComputedMethod: [
2992
+ "value",
2993
+ "typeParameters",
2994
+ "parameters",
2995
+ "returnType"
2996
+ ]
2997
+ };
2998
+ function _traverse(node, parentNode, property, index, onEnter, onLeave) {
2999
+ onEnter == null ? void 0 : onEnter(node, parentNode, property, index);
3000
+ const keysToVisit = visitorKeys[node.type];
3001
+ for (const key of keysToVisit) {
3002
+ const value = node[key];
3003
+ if (value !== void 0) {
3004
+ if (Array.isArray(value)) for (const [index2, element] of value.entries()) _traverse(element, node, key, index2, onEnter, onLeave);
3005
+ else if (value !== null && typeof value === "object" && "type" in value) _traverse(value, node, key, void 0, onEnter, onLeave);
3006
+ }
3007
+ }
3008
+ onLeave == null ? void 0 : onLeave(node, parentNode, property, index);
3009
+ }
3010
+ function traverse(node, onEnter, onLeave) {
3011
+ _traverse(node, void 0, void 0, void 0, onEnter, onLeave);
3012
+ }
3013
+ // Annotate the CommonJS export names for ESM import in node:
3014
+ 0 && (module.exports = {
3015
+ catharsisTransform,
3016
+ identityTransformRules,
3017
+ jtpTransform,
3018
+ parse,
3019
+ parseName,
3020
+ parseNamePath,
3021
+ stringify,
3022
+ stringifyRules,
3023
+ transform,
3024
+ traverse,
3025
+ tryParse,
3026
+ visitorKeys
3027
+ });