@runtime-type-inspector/transpiler 4.0.5 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types.d.ts ADDED
@@ -0,0 +1,970 @@
1
+ type Stat$1 = {
2
+ /**
3
+ * - How often assertions were added to this kind of node.
4
+ */
5
+ checked: number;
6
+ /**
7
+ * - How often no assertions were added to this kind of node.
8
+ */
9
+ unchecked: number;
10
+ };
11
+
12
+ type Node$1 = any;
13
+ /**
14
+ * @typedef {import("@babel/types").Node} Node
15
+ */
16
+ declare class Stringifier {
17
+ forceCurly: boolean;
18
+ /** @type {Node[]} */
19
+ parents: Node$1[];
20
+ /**
21
+ * @param {Node} node - The Babel AST node.
22
+ * @returns {string} Stringification of the node.
23
+ */
24
+ toSource(node: any): string;
25
+ /**
26
+ * @param {Node} node - The Babel AST node.
27
+ * @returns {string} Stringification of the node.
28
+ */
29
+ toSource_(node: any): string;
30
+ parentProvidesSpaces(reverseIndex: any): boolean;
31
+ lastCommentBlockIndex: number;
32
+ /**
33
+ * @param {import("@babel/types").CommentBlock} node - The Babel AST node.
34
+ * @returns {string} Stringification of the node.
35
+ */
36
+ CommentBlock(node: any): string;
37
+ lastCommentLineIndex: number;
38
+ /**
39
+ * @param {import("@babel/types").CommentLine} node - The Babel AST node.
40
+ * @returns {string} Stringification of the node.
41
+ */
42
+ CommentLine(node: any): string;
43
+ leadingCommentsToSource(leadingComments: any): any;
44
+ trailingCommentsToSource(trailingComments: any): string;
45
+ /**
46
+ * @param {*} comment - The comment "node" (not a real Babel Node node though, hence this special treatment)
47
+ * @param {'leading'|'trailing'} pos - The position, either 'leading' or 'trailing'.
48
+ * @returns {string} The comment "node" as a string.
49
+ */
50
+ commentToSource(comment: any, pos: 'leading' | 'trailing'): string;
51
+ /**
52
+ * Only add { and } when requested (e.g. for Asserter).
53
+ * showAST("if (true) 2;") vs showAST("if (true) {2}")
54
+ * @param {Node} node - The Babel AST node.
55
+ * @returns {string} Stringification of the node.
56
+ */
57
+ toSourceCurly(node: any): string;
58
+ get parent(): any;
59
+ get parentType(): any;
60
+ get needSpaces(): boolean;
61
+ /**
62
+ * @param {Node[]} arr - Array of nodes to convert.
63
+ * @returns {string[]} Array of strings for each node.
64
+ */
65
+ mapToSource(arr: Node$1[]): string[];
66
+ /**
67
+ * Generates a string representing type checks for a given Babel AST node.
68
+ *
69
+ * Note: This method serves as a stub and should be overridden in subclasses.
70
+ * The actual implementation is expected to be provided in Asserter.mjs, where
71
+ * it would create runtime type assertions based on the AST node provided.
72
+ *
73
+ * @param {Node} node - The Babel AST node for which to generate type checks.
74
+ * @returns {string} A placeholder string, as this stub implementation does nothing; expected to be overridden.
75
+ */
76
+ generateTypeChecks(node: any): string;
77
+ numSpaces: number;
78
+ /**
79
+ * @returns {string} A string of two spaces per indentation.
80
+ */
81
+ get spaces(): string;
82
+ debugSpaces(): string;
83
+ /**
84
+ * > await something();
85
+ *
86
+ * @param {import("@babel/types").AwaitExpression} node - The Babel AST node.
87
+ * @returns {string} Stringification of the node.
88
+ */
89
+ AwaitExpression(node: any): string;
90
+ /**
91
+ * @param {import("@babel/types").ClassBody} node - The Babel AST node.
92
+ * @returns {string} Stringification of the node.
93
+ */
94
+ ClassBody(node: any): string;
95
+ /**
96
+ * @param {import("@babel/types").ClassMethod} node - The Babel AST node.
97
+ * @returns {string} Stringification of the node.
98
+ */
99
+ ClassMethod(node: any): string;
100
+ /**
101
+ * @param {import("@babel/types").ClassExpression} node - The Babel AST node.
102
+ * @returns {string} Stringification of the node.
103
+ */
104
+ ClassExpression(node: any): string;
105
+ /**
106
+ * @param {import("@babel/types").ClassDeclaration} node - The Babel AST node.
107
+ * @returns {string} Stringification of the node.
108
+ */
109
+ ClassDeclaration(node: any): string;
110
+ /**
111
+ * @param {import("@babel/types").ClassPrivateMethod} node - The Babel AST node.
112
+ * @returns {string} Stringification of the node.
113
+ */
114
+ ClassPrivateMethod(node: any): string;
115
+ /**
116
+ * > asd;
117
+ * > asd = 1;
118
+ * > static asd;
119
+ * > static asd = 1;
120
+ *
121
+ * @param {import("@babel/types").ClassProperty} node - The Babel AST node.
122
+ * @returns {string} Stringification of the node.
123
+ */
124
+ ClassProperty(node: any): string;
125
+ /**
126
+ * @param {import("@babel/types").ContinueStatement} node - The Babel AST node.
127
+ * @returns {string} Stringification of the node.
128
+ */
129
+ ContinueStatement(node: any): string;
130
+ /**
131
+ * Converts an array of Babel AST nodes representing function parameters into a comma-separated string.
132
+ *
133
+ * Each parameter node is converted to its source representation and combined into a single
134
+ * string suitable for inserting into a function declaration's parentheses.
135
+ *
136
+ * @param {Node[]} params - An array of Babel AST nodes representing the function parameters to be stringified.
137
+ * @returns {string} A string representing the serialized parameters, enclosed in parentheses.
138
+ */
139
+ FunctionDeclarationParams(params: Node$1[]): string;
140
+ /**
141
+ * @param {import("@babel/types").FunctionDeclaration} node - The Babel AST node.
142
+ * @returns {string} Stringification of the node.
143
+ */
144
+ FunctionDeclaration(node: any): string;
145
+ /**
146
+ * @param {import("@babel/types").FunctionExpression} node - The Babel AST node.
147
+ * @returns {string} Stringification of the node.
148
+ */
149
+ FunctionExpression(node: any): string;
150
+ /**
151
+ * @param {import("@babel/types").ArrowFunctionExpression} node - The Babel AST node.
152
+ * @returns {string} Stringification of the node.
153
+ */
154
+ ArrowFunctionExpression(node: any): string;
155
+ /**
156
+ * @param {import("@babel/types").BigIntLiteral} node - The Babel AST node.
157
+ * @returns {string} Stringification of the node.
158
+ */
159
+ BigIntLiteral(node: any): string;
160
+ /**
161
+ * @param {import("@babel/types").BlockStatement} node - The Babel AST node.
162
+ * @returns {string} Stringification of the node.
163
+ */
164
+ BlockStatement(node: any): string;
165
+ /**
166
+ * > 'use strict';
167
+ *
168
+ * @param {import("@babel/types").Directive} node - The Babel AST node.
169
+ * @returns {string} Stringification of the node.
170
+ */
171
+ Directive(node: any): string;
172
+ /**
173
+ * > 'use strict';
174
+ *
175
+ * @param {import("@babel/types").DirectiveLiteral} node - The Babel AST node.
176
+ * @returns {string} Stringification of the node.
177
+ */
178
+ DirectiveLiteral(node: any): string;
179
+ /**
180
+ * @param {import("@babel/types").ReturnStatement} node - The Babel AST node.
181
+ * @returns {string} Stringification of the node.
182
+ */
183
+ ReturnStatement(node: any): string;
184
+ /**
185
+ * @param {import("@babel/types").Identifier} node - The Babel AST node.
186
+ * @returns {string} Stringification of the node.
187
+ */
188
+ Identifier(node: any): string;
189
+ /**
190
+ * @param {import("@babel/types").IfStatement} node - The Babel AST node.
191
+ * @returns {string} Stringification of the node.
192
+ */
193
+ IfStatement(node: any): string;
194
+ /**
195
+ * @param {import("@babel/types").LabeledStatement} node - The Babel AST node.
196
+ * @returns {string} Stringification of the node.
197
+ */
198
+ LabeledStatement(node: any): string;
199
+ /**
200
+ * @example
201
+ * ts = require("typescript");
202
+ * ts.createSourceFile("repl.ts", "a = 1", ts.ScriptTarget.Latest);
203
+ * ts.createSourceFile("repl.ts", "!!(a = 1 + 2)", ts.ScriptTarget.Latest);
204
+ * showAST('!!(a = 1)');
205
+ * @param {import("@babel/types").UnaryExpression} node - The Babel AST node.
206
+ * @returns {string} Stringification of the node.
207
+ */
208
+ UnaryExpression(node: any): string;
209
+ /**
210
+ * @param {import("@babel/types").MemberExpression} node - The Babel AST node.
211
+ * @returns {string} Stringification of the node.
212
+ */
213
+ MemberExpression(node: any): string;
214
+ /**
215
+ * @param {import("@babel/types").MetaProperty} node - The Babel AST node.
216
+ * @returns {string} Stringification of the node.
217
+ */
218
+ MetaProperty(node: any): string;
219
+ /**
220
+ * @param {import("@babel/types").ExpressionStatement} node - The Babel AST node.
221
+ * @returns {string} Stringification of the node.
222
+ */
223
+ ExpressionStatement(node: any): string;
224
+ /**
225
+ * @param {import("@babel/types").CallExpression} node - The Babel AST node.
226
+ * @returns {string} Stringification of the node.
227
+ */
228
+ CallExpression(node: any, ...args: any[]): string;
229
+ /**
230
+ * We replicate the exact AST for validation:
231
+ * x = 1;
232
+ * y = {x,}
233
+ * z = {y};
234
+ * @param {import("@babel/types").ObjectExpression} node - The Babel AST node.
235
+ * @returns {string} Stringification of the node.
236
+ */
237
+ ObjectExpression(node: any): string;
238
+ /**
239
+ * @param {import("@babel/types").ObjectProperty} node - The Babel AST node.
240
+ * @returns {string} Stringification of the node.
241
+ */
242
+ ObjectProperty(node: any): string;
243
+ /**
244
+ * @param {import("@babel/types").BooleanLiteral} node - The Babel AST node.
245
+ * @returns {string} Stringification of the node.
246
+ */
247
+ BooleanLiteral(node: any): string;
248
+ /**
249
+ * @param {import("@babel/types").AssignmentExpression} node - The Babel AST node.
250
+ * @returns {string} Stringification of the node.
251
+ */
252
+ AssignmentExpression(node: any): string;
253
+ /**
254
+ * @param {import("@babel/types").BinaryExpression} node - The Babel AST node.
255
+ * @returns {string} Stringification of the node.
256
+ */
257
+ BinaryExpression(node: any): string;
258
+ /**
259
+ * @param {import("@babel/types").ThisExpression} node - The Babel AST node.
260
+ * @returns {string} Stringification of the node.
261
+ */
262
+ ThisExpression(node: any): string;
263
+ /**
264
+ * @param {import("@babel/types").ArrayExpression} node - The Babel AST node.
265
+ * @returns {string} Stringification of the node.
266
+ */
267
+ ArrayExpression(node: any): string;
268
+ /**
269
+ * @param {import("@babel/types").VariableDeclaration} node - The Babel AST node.
270
+ * @returns {string} Stringification of the node.
271
+ */
272
+ VariableDeclaration(node: any): string;
273
+ /**
274
+ * @param {import("@babel/types").VariableDeclarator} node - The Babel AST node.
275
+ * @returns {string} Stringification of the node.
276
+ */
277
+ VariableDeclarator(node: any): string;
278
+ /**
279
+ * @param {import("@babel/types").ConditionalExpression} node - The Babel AST node.
280
+ * @returns {string} Stringification of the node.
281
+ */
282
+ ConditionalExpression(node: any): string;
283
+ /**
284
+ * if (...)
285
+ *
286
+ * @param {import("@babel/types").LogicalExpression} node - The Babel AST node.
287
+ * @returns {string} Stringification of the node.
288
+ */
289
+ LogicalExpression(node: any): string;
290
+ /**
291
+ * TODO TEST: can init be undefined in for(;;)
292
+ *
293
+ * @param {import("@babel/types").ForStatement} node - The Babel AST node.
294
+ * @returns {string} Stringification of the node.
295
+ */
296
+ ForStatement(node: any): string;
297
+ /**
298
+ * showAST("++i")
299
+ *
300
+ * @param {import("@babel/types").UpdateExpression} node - The Babel AST node.
301
+ * @returns {string} Stringification of the node.
302
+ */
303
+ UpdateExpression(node: any): string;
304
+ /**
305
+ * @param {import("@babel/types").NewExpression} node - The Babel AST node.
306
+ * @returns {string} Stringification of the node.
307
+ */
308
+ NewExpression(node: any, ...args: any[]): string;
309
+ /**
310
+ * @example
311
+ * console.log(ast2json(parseSync("`${1} b ${2+3}c`").program.body[0]));
312
+ * @param {import("@babel/types").TemplateLiteral} node - The Babel AST node.
313
+ * @returns {string} Stringification of the node.
314
+ */
315
+ TemplateLiteral(node: any): string;
316
+ /**
317
+ * @param {import("@babel/types").TemplateElement} node - The Babel AST node.
318
+ * @returns {string} Stringification of the node.
319
+ */
320
+ TemplateElement(node: any): string;
321
+ /**
322
+ * @param {import("@babel/types").PrivateName} node - The Babel AST node.
323
+ * @returns {string} Stringification of the node.
324
+ */
325
+ PrivateName(node: any): string;
326
+ /**
327
+ * @param {import("@babel/types").ExportAllDeclaration} node - The Babel AST node.
328
+ * @returns {string} Stringification of the node.
329
+ */
330
+ ExportAllDeclaration(node: any): string;
331
+ /**
332
+ * @param {import("@babel/types").ExportNamedDeclaration} node - The Babel AST node.
333
+ * @returns {string} Stringification of the node.
334
+ */
335
+ ExportNamedDeclaration(node: any): string;
336
+ /**
337
+ * @param {import("@babel/types").ExportDefaultDeclaration} node - The Babel AST node.
338
+ * @returns {string} Stringification of the node.
339
+ */
340
+ ExportDefaultDeclaration(node: any): string;
341
+ /**
342
+ * @param {import("@babel/types").ExportSpecifier} node - The Babel AST node.
343
+ * @returns {string} Stringification of the node.
344
+ */
345
+ ExportSpecifier(node: any): string;
346
+ /**
347
+ * @param {import("@babel/types").Super} node - The Babel AST node.
348
+ * @returns {string} Stringification of the node.
349
+ */
350
+ Super(node: any): string;
351
+ /**
352
+ * @param {import("@babel/types").ForInStatement} node - The Babel AST node.
353
+ * @returns {string} Stringification of the node.
354
+ */
355
+ ForInStatement(node: any): string;
356
+ /**
357
+ * @param {import("@babel/types").ThrowStatement} node - The Babel AST node.
358
+ * @returns {string} Stringification of the node.
359
+ */
360
+ ThrowStatement(node: any): string;
361
+ /**
362
+ * @param {import("@babel/types").WhileStatement} node - The Babel AST node.
363
+ * @returns {string} Stringification of the node.
364
+ */
365
+ WhileStatement(node: any): string;
366
+ /**
367
+ * @param {import("@babel/types").BreakStatement} node - The Babel AST node.
368
+ * @returns {string} Stringification of the node.
369
+ */
370
+ BreakStatement(node: any): string;
371
+ /**
372
+ * @param {import("@babel/types").ForOfStatement} node - The Babel AST node.
373
+ * @returns {string} Stringification of the node.
374
+ */
375
+ ForOfStatement(node: any): string;
376
+ /**
377
+ * for (const [a, b] in c)
378
+ * --> [a, b] is the array pattern
379
+ *
380
+ * @param {import("@babel/types").ArrayPattern} node - The Babel AST node.
381
+ * @returns {string} Stringification of the node.
382
+ */
383
+ ArrayPattern(node: any): string;
384
+ /**
385
+ * @param {import("@babel/types").SwitchStatement} node - The Babel AST node.
386
+ * @returns {string} Stringification of the node.
387
+ */
388
+ SwitchStatement(node: any): string;
389
+ /**
390
+ * @param {import("@babel/types").SwitchCase} node - The Babel AST node.
391
+ * @returns {string} Stringification of the node.
392
+ */
393
+ SwitchCase(node: any): string;
394
+ /**
395
+ * @param {import("@babel/types").RegExpLiteral} node - The Babel AST node.
396
+ * @returns {string} Stringification of the node.
397
+ */
398
+ RegExpLiteral(node: any): string;
399
+ /**
400
+ * for (var i=0, n=arr.length; i<n; i++)
401
+ * sequence expression: var i=0, n=arr.length
402
+ *
403
+ * @param {import("@babel/types").SequenceExpression} node - The Babel AST node.
404
+ * @returns {string} Stringification of the node.
405
+ */
406
+ SequenceExpression(node: any): string;
407
+ /**
408
+ * showAST("if (true);");
409
+ *
410
+ * @param {import("@babel/types").EmptyStatement} node - The Babel AST node.
411
+ * @returns {string} Stringification of the node.
412
+ */
413
+ EmptyStatement(node: any): string;
414
+ /**
415
+ * @param {import("@babel/types").SpreadElement} node - The Babel AST node.
416
+ * @returns {string} Stringification of the node.
417
+ */
418
+ SpreadElement(node: any): string;
419
+ /**
420
+ * @param {import("@babel/types").ObjectMethod} node - The Babel AST node.
421
+ * @returns {string} Stringification of the node.
422
+ */
423
+ ObjectMethod(node: any): string;
424
+ /**
425
+ * E.g. function testComma({x,y,z,}) {}
426
+ * @param {import("@babel/types").ObjectPattern} node - The Babel AST node.
427
+ * @returns {string} Stringification of the node.
428
+ */
429
+ ObjectPattern(node: any): string;
430
+ /**
431
+ * > x?.y
432
+ * > x?.y.z
433
+ * > x[y?.z]
434
+ * > x?.[y?.z]
435
+ * > b?.file?.variants[variant]
436
+ *
437
+ * @param {import("@babel/types").OptionalMemberExpression} node - The Babel AST node.
438
+ * @returns {string} Stringification of the node.
439
+ */
440
+ OptionalMemberExpression(node: any): string;
441
+ /**
442
+ * > version?.indexOf('$');
443
+ * > version?.indexOf?.('$');
444
+ * > this.passEncoder?.pushDebugGroup(name);
445
+ *
446
+ * @param {import("@babel/types").OptionalCallExpression} node - The Babel AST node.
447
+ * @returns {string} Stringification of the node.
448
+ */
449
+ OptionalCallExpression(node: any, ...args: any[]): string;
450
+ /**
451
+ * @param {import("@babel/types").DoWhileStatement} node - The Babel AST node.
452
+ * @returns {string} Stringification of the node.
453
+ */
454
+ DoWhileStatement(node: any): string;
455
+ /**
456
+ * @param {import("@babel/types").TryStatement} node - The Babel AST node.
457
+ * @returns {string} Stringification of the node.
458
+ */
459
+ TryStatement(node: any): string;
460
+ /**
461
+ * @param {import("@babel/types").CatchClause} node - The Babel AST node.
462
+ * @returns {string} Stringification of the node.
463
+ */
464
+ CatchClause(node: any): string;
465
+ /**
466
+ * @param {import("@babel/types").RestElement} node - The Babel AST node.
467
+ * @returns {string} Stringification of the node.
468
+ */
469
+ RestElement(node: any): string;
470
+ /**
471
+ * @param {import("@babel/types").DebuggerStatement} node - The Babel AST node.
472
+ * @returns {string} Stringification of the node.
473
+ */
474
+ DebuggerStatement(node: any): string;
475
+ /**
476
+ * @param {import("@babel/types").Import} node - The Babel AST node.
477
+ * @returns {string} Stringification of the node.
478
+ */
479
+ Import(node: any): string;
480
+ /**
481
+ * @param {import("@babel/types").ImportDeclaration} node - The Babel AST node.
482
+ * @returns {string} Stringification of the node.
483
+ */
484
+ ImportDeclaration(node: any): string;
485
+ /**
486
+ * @param {import("@babel/types").ImportSpecifier} node - The Babel AST node.
487
+ * @returns {string} Stringification of the node.
488
+ */
489
+ ImportSpecifier(node: any): string;
490
+ /**
491
+ * @param {import("@babel/types").ImportDefaultSpecifier} node - The Babel AST node.
492
+ * @returns {string} Stringification of the node.
493
+ */
494
+ ImportDefaultSpecifier(node: any): string;
495
+ /**
496
+ * @param {import("@babel/types").ImportNamespaceSpecifier} node - The Babel AST node.
497
+ * @returns {string} Stringification of the node.
498
+ */
499
+ ImportNamespaceSpecifier(node: any): string;
500
+ /**
501
+ * @param {import("@babel/types").File} node - The Babel AST node.
502
+ * @returns {string} Stringification of the node.
503
+ */
504
+ File(node: any): string;
505
+ /**
506
+ * @param {import("@babel/types").Program} node - The Babel AST node.
507
+ * @returns {string} Stringification of the node.
508
+ */
509
+ Program(node: any): string;
510
+ /**
511
+ * @param {import("@babel/types").StringLiteral} node - The Babel AST node.
512
+ * @returns {string} Stringification of the node.
513
+ */
514
+ StringLiteral(node: any): string;
515
+ /**
516
+ * @param {import("@babel/types").NumericLiteral} node - The Babel AST node.
517
+ * @returns {string} Stringification of the node.
518
+ */
519
+ NumericLiteral(node: any): string;
520
+ /**
521
+ * @param {import("@babel/types").AssignmentPattern} node - The Babel AST node.
522
+ * @returns {string} Stringification of the node.
523
+ */
524
+ AssignmentPattern(node: any): string;
525
+ /**
526
+ * @param {import("@babel/types").NullLiteral} node - The Babel AST node.
527
+ * @returns {string} Stringification of the node.
528
+ */
529
+ NullLiteral(node: any): string;
530
+ /**
531
+ * @param {import("@babel/types").TaggedTemplateExpression} node - The Babel AST node.
532
+ * @returns {string} Stringification of the node.
533
+ */
534
+ TaggedTemplateExpression(node: any): string;
535
+ /**
536
+ * @param {import("@babel/types").YieldExpression} node - The Babel AST node.
537
+ * @returns {string} Stringification of the node.
538
+ */
539
+ YieldExpression(node: any): string;
540
+ }
541
+
542
+ type Node = any;
543
+ type ClassMethod = any;
544
+ type ClassPrivateMethod = any;
545
+ type Stat = Stat$1;
546
+ type Options = {
547
+ /**
548
+ * - Determines whether curly braces are enforced in Stringifier.
549
+ */
550
+ forceCurly?: boolean;
551
+ /**
552
+ * - Indicates whether division operations should be validated.
553
+ */
554
+ validateDivision?: boolean;
555
+ /**
556
+ * - A function that expands shorthand types into full descriptions.
557
+ */
558
+ expandType?: Function;
559
+ /**
560
+ * - The name of a file to which the instance pertains.
561
+ */
562
+ filename?: string;
563
+ };
564
+ /** @typedef {import('@babel/types').Node } Node */
565
+ /** @typedef {import("@babel/types").ClassMethod } ClassMethod */
566
+ /** @typedef {import("@babel/types").ClassPrivateMethod} ClassPrivateMethod */
567
+ /** @typedef {import('./stat.mjs').Stat } Stat */
568
+ /**
569
+ * @typedef {object} Options
570
+ * @property {boolean} [forceCurly] - Determines whether curly braces are enforced in Stringifier.
571
+ * @property {boolean} [validateDivision] - Indicates whether division operations should be validated.
572
+ * @property {Function} [expandType] - A function that expands shorthand types into full descriptions.
573
+ * @property {string} [filename] - The name of a file to which the instance pertains.
574
+ */
575
+ declare class Asserter extends Stringifier {
576
+ /**
577
+ * @param {Options} [options] - The options.
578
+ */
579
+ constructor({ forceCurly, validateDivision, expandType, filename }?: Options);
580
+ validateDivision: boolean;
581
+ expandType: Function;
582
+ filename: string;
583
+ /** @type {Record<string, Stat>} */
584
+ stats: Record<string, Stat>;
585
+ /**
586
+ * Finds the closest ancestor of the given node that matches the specified type.
587
+ *
588
+ * @param {Node} node - The starting node to search from.
589
+ * @param {string} type - The type of the node to search for.
590
+ * @returns {Node|undefined} The first ancestor node of the specified type, or undefined if none is found.
591
+ */
592
+ findParentOfType(node: any, type: string): Node | undefined;
593
+ /**
594
+ * Retrieves the node associated with the leading comments for an arrow function expression.
595
+ *
596
+ * This method travels up the syntax tree from the given node to find a parent node with leading comments.
597
+ * This search is bounded by function boundaries or a 'CallExpression' node, as per the logic defined within the loop.
598
+ * @param {Node} node - The node representing the arrow function expression for which to find the leading comments node.
599
+ * @returns {Node|undefined} The node that contains the leading comments, or `undefined`
600
+ * if none is found before reaching a different function or 'CallExpression'.
601
+ */
602
+ getLeadingCommentsNodeForArrowFunctionExpression(node: any): Node | undefined;
603
+ /**
604
+ * Emits a warning message to the console, optionally prefixed with the instance's filename.
605
+ * @param {...any} args - A list of arguments to be passed to the console.warn function.
606
+ */
607
+ warn(...args: any[]): void;
608
+ /**
609
+ * @param {Node} node - The Babel AST node.
610
+ * @returns {undefined | {}} The return value of `parseJSDoc`.
611
+ */
612
+ getJSDoc(node: any): undefined | {};
613
+ /**
614
+ * Retrieves the name of a parameter from a Babel AST node.
615
+ *
616
+ * This function expects a node representing a function parameter and attempts to extract
617
+ * the parameter's name directly or from an AssignmentPattern.
618
+ *
619
+ * @param {Node} param - The AST node representing the function parameter from which to extract the name.
620
+ * @returns {string} The name of the parameter as a string, or the parameter's source code if the extraction fails.
621
+ */
622
+ getNameOfParam(param: any): string;
623
+ statsReset(): void;
624
+ statsPrint(): void;
625
+ /**
626
+ * Retrieves statistical information for a given Babel AST node of this instance.
627
+ *
628
+ * @param {Node} node - The Babel AST node for which the statistical data is retrieved.
629
+ * @returns {Stat} An object containing the statistical data for the specified node. If the
630
+ * node type is unhandled, defaults to returning a dummy object with 'checked' and 'unchecked'
631
+ * properties both set to 0.
632
+ */
633
+ getStatsForNode(node: any): Stat;
634
+ /**
635
+ * Checks if a provided Babel AST node has a parameter with the given name.
636
+ *
637
+ * This function will look at the node's parameters if available and determine whether
638
+ * one of them matches the provided name. Supports various parameter types such as Identifiers
639
+ * and AssignmentPatterns.
640
+ *
641
+ * @param {Node} node - The Babel AST node to inspect. If it's a BlockStatement, the parent node is used instead.
642
+ * @param {string} name - The name of the parameter to look for within the node's parameters.
643
+ * @returns {boolean} True if the node has a parameter with the given name; false otherwise.
644
+ */
645
+ nodeHasParamName(node: any, name: string): boolean;
646
+ /**
647
+ * @param {Node} node - The Babel AST node.
648
+ * @returns {string} Stringification of the node.
649
+ */
650
+ getName(node: any): string;
651
+ /** @type {Record<string, object>} */
652
+ typedefs: Record<string, object>;
653
+ }
654
+
655
+ /**
656
+ * Simple facade which does all the processing. Processes the input
657
+ * source string, adding runtime type checks based on JSDoc comments.
658
+ *
659
+ * This function takes JavaScript source code as input, parses it to an AST, traverses the
660
+ * AST to find type annotations in JSDoc comments, and generates appropriate runtime type
661
+ * assertions. These are then inserted into the source, producing a new version of the code
662
+ * that includes runtime type checking based on the original JSDoc annotations.
663
+ *
664
+ * @param {string} src - The input source code containing JSDoc comments to be processed
665
+ * for type checks.
666
+ * @param {import('./Asserter.mjs').Options} [options] - Configuration options that dictate
667
+ * how the processing is performed.
668
+ * @returns {string} The transformed source code with inserted runtime type checks, or the
669
+ * original source code commented with an error if processing fails.
670
+ */
671
+ declare function addTypeChecks(src: string, options?: Options): string;
672
+
673
+ /**
674
+ * @param {object} ast - The Babel AST.
675
+ * @returns {string} String representation in JSON format for debugging/inspecting the AST.
676
+ */
677
+ declare function ast2json(ast: object): string;
678
+
679
+ /**
680
+ * @example
681
+ * setRight(ast2jsonForComparison(parseSync("/** *"))); // Close comment with / after last *
682
+ * @param {object} ast - The Babel AST.
683
+ * @returns {string} String representation in JSON format for debugging/inspecting the AST.
684
+ */
685
+ declare function ast2jsonForComparison(ast: object): string;
686
+
687
+ /**
688
+ * A roundtrip between code -> AST -> code to validate Stringifier.
689
+ * @param {string} code - The code.
690
+ * @returns {string | undefined} The new and once parsed and stringified code.
691
+ */
692
+ declare function code2ast2code(code: string): string | undefined;
693
+
694
+ /**
695
+ * @param {string} left - Left source code.
696
+ * @param {string} right - Right source code.
697
+ * @returns {boolean} Whether source codes are identical on the AST level.
698
+ */
699
+ declare function compareAST(left: string, right: string): boolean;
700
+
701
+ type TypeScriptType = {
702
+ /**
703
+ * - The type arguments.
704
+ */
705
+ typeArguments: object[] | undefined;
706
+ /**
707
+ * - The type name.
708
+ */
709
+ typeName: any;
710
+ /**
711
+ * - The kind for `ts.SyntaxKind[kind]`.
712
+ */
713
+ kind: number;
714
+ };
715
+ /**
716
+ * Transforms a type string into a structured type representation.
717
+ *
718
+ * This function parses a given type string and converts it into a TypeScript
719
+ * Abstract Syntax Tree (AST), then uses that AST to return a structured type
720
+ * representation that can be further utilized or interpreted.
721
+ *
722
+ * @todo Better handling of weird case: Array<>
723
+ * @todo implement TypeQuery, e.g. for expandType('typeof Number');
724
+ * @example
725
+ * const { expandType } = await import("./src-transpiler/expandType.mjs");
726
+ * expandType('[string, Array|AnyTypedArray, number[]]|[ONNXTensor]');
727
+ * expandType('(123) '); // Outputs: '123'
728
+ * expandType(' ( ( 123 ) ) '); // Outputs: '123'
729
+ * expandType('Array<number> '); // Outputs: {type: 'array', elementType: 'number'}
730
+ * expandType('Array<(123) > '); // Outputs: {type: 'array', elementType: '123'}
731
+ * expandType('Array<"abc" | 123> '); // Outputs: {type: 'array', elementType: { type: 'union', members: [ '"abc"', '123' ]}}
732
+ * expandType(' (string ) |(number ) '); // Outputs: {type: 'union', members: [ 'string', 'number']}
733
+ * expandType(' "apples" | ( "bananas") '); // Outputs: {type: 'union', members: [ '"apples"', '"bananas"']}
734
+ * expandType('123? '); // Outputs: {"type":"union","members":["123","null"]}
735
+ * expandType('123|null '); // Outputs: {"type":"union","members":["123","null"]}
736
+ * expandType('Map<string, any>');
737
+ * @param {string} type - The type string to be expanded into a structured representation.
738
+ * @todo Share type with expandTypeBabelTS and expandTypeDepFree
739
+ * @returns {string | {type: string, [key: string]: any} | undefined} The structured type
740
+ * representation obtained from parsing and converting the provided type string.
741
+ */
742
+ declare function expandType(type: string): string | {
743
+ [key: string]: any;
744
+ type: string;
745
+ };
746
+ /**
747
+ * @todo I want to use for example: import('typescript').Node
748
+ * But the TS types make no sense to me so far ... need to investigate more.
749
+ * @typedef TypeScriptType
750
+ * @property {object[]|undefined} typeArguments - The type arguments.
751
+ * @property {import('typescript').Node} typeName - The type name.
752
+ * @property {number} kind - The kind for `ts.SyntaxKind[kind]`.
753
+ */
754
+ /**
755
+ * @param {string} str - The type string.
756
+ * @returns {TypeScriptType} - The node containing all the information about the input type string.
757
+ */
758
+ declare function parseType(str: string): TypeScriptType;
759
+ /**
760
+ * Converts a TypeScript AST node to a source string representation or to an intermediate object describing the type.
761
+ *
762
+ * This function handles various TypeScript AST node types and converts them into a string
763
+ * or an object representing the type.
764
+ *
765
+ * @param {TypeScriptType} node - The TypeScript AST node to convert.
766
+ * @returns {string | {type: string, [key: string]: any} | undefined} The source string or an object with type information based on the node,
767
+ * or `undefined` if the node kind is not handled.
768
+ */
769
+ declare function toSourceTS(node: TypeScriptType): string | {
770
+ [key: string]: any;
771
+ type: string;
772
+ };
773
+
774
+ /**
775
+ * @todo Better handling of weird case: Array<>
776
+ * @todo implement TypeQuery, e.g. for expandTypeBabelTS('typeof Number');
777
+ * @example
778
+ * const { expandTypeBabelTS } = await import("./src-transpiler/expandTypeBabelTS.mjs");
779
+ * expandTypeBabelTS('[string, Array|AnyTypedArray, number[]]|[ONNXTensor]');
780
+ * expandTypeBabelTS('(123) '); // Outputs: '123'
781
+ * expandTypeBabelTS(' ( ( 123 ) ) '); // Outputs: '123'
782
+ * expandTypeBabelTS('Array<number> '); // Outputs: {type: 'array', elementType: 'number'}
783
+ * expandTypeBabelTS('Array<(123) > '); // Outputs: {type: 'array', elementType: '123'}
784
+ * expandTypeBabelTS('Array<"abc" | 123> '); // Outputs: {type: 'array', elementType: { type: 'union', members: [ '"abc"', '123' ]}}
785
+ * expandTypeBabelTS(' (string ) |(number ) '); // Outputs: {type: 'union', members: [ 'string', 'number']}
786
+ * expandTypeBabelTS(' "apples" | ( "bananas") '); // Outputs: {type: 'union', members: [ '"apples"', '"bananas"']}
787
+ * expandTypeBabelTS('123? '); // Outputs: {"type":"union","members":["123","null"]}
788
+ * expandTypeBabelTS('123|null '); // Outputs: {"type":"union","members":["123","null"]}
789
+ * expandTypeBabelTS('Map<string, any>');
790
+ * expandTypeBabelTS("(a: number, b: number) => number")
791
+ * @param {string} type - The input type.
792
+ * @returns {string|object|undefined} - See `toSourceBabelTS`.
793
+ */
794
+ declare function expandTypeBabelTS(type: string): string | object | undefined;
795
+ /**
796
+ * @param {string} str - The type string.
797
+ * @returns {import('@babel/types').Node} - The node containing all the information about the input type string.
798
+ */
799
+ declare function parseTypeBabelTS(str: string): any;
800
+ /**
801
+ * Converts a Babel AST node to its source string representation or structured type object.
802
+ *
803
+ * This function handles a variety of node types provided by Babel and converts them into a string
804
+ * or an intermediate object representing the type, depending on the complexity of the type described by the node.
805
+ *
806
+ * @param {import('@babel/types').Node} node - The Babel AST node to convert.
807
+ * @returns {string|object|undefined} - A string, object representing a structured type, or `undefined` for unhandled types.
808
+ * Depending on the node, it may return a simple type string (e.g., `"string"` for `TSStringKeyword`),
809
+ * a structured type object (e.g., a record type for `TSTypeReference` with type arguments),
810
+ * or `undefined` if the encountered type is not handled. Unhandled types trigger a warning and enter a debugger statement.
811
+ */
812
+ declare function toSourceBabelTS(node: any): string | object | undefined;
813
+
814
+ type ExpandTypeReturnValue = {
815
+ /**
816
+ * - The type.
817
+ */
818
+ type: 'array' | 'union' | 'record' | 'tuple' | 'object';
819
+ /**
820
+ * - For Array.
821
+ */
822
+ elementType?: object | string;
823
+ /**
824
+ * - For Record<key, val>
825
+ */
826
+ key?: object | string;
827
+ /**
828
+ * - For Record<key, val>
829
+ */
830
+ val?: object | string;
831
+ /**
832
+ * - For unions.
833
+ */
834
+ members?: (object | string)[];
835
+ /**
836
+ * - For objects.
837
+ */
838
+ properties?: object | string;
839
+ /**
840
+ * - For tuples.
841
+ */
842
+ elements?: (object | string)[];
843
+ };
844
+ /**
845
+ * @todo expandTypeDepFree doesn't support "complicated" types.
846
+ * For actual builds, we use expandType() anyway (which is based on TypeScript).
847
+ * But since TypeScript is a huge dependency, I'm looking into BabelFlow/BabelTypescript parser.
848
+ * Comparing AST's like this usually helps to find bugs or potential issues,
849
+ * while we can benchmark for best performance too.
850
+ * @example
851
+ * const tooComplex = 'Array<string|{chunks?: undefined|Array<{language: string|null, timestamp: Array<number|null>, text: string}>}>';
852
+ * console.log(expandTypeDepFree(tooComplex));
853
+ */
854
+ /**
855
+ * @typedef {object} ExpandTypeReturnValue
856
+ * @property {'array' | 'union' | 'record' | 'tuple' | 'object'} type - The type.
857
+ * @property {object | string} [elementType] - For Array.
858
+ * @property {object | string} [key] - For Record<key, val>
859
+ * @property {object | string} [val] - For Record<key, val>
860
+ * @property {(object | string)[]} [members] - For unions.
861
+ * @property {object | string} [properties] - For objects.
862
+ * @property {(object | string)[]} [elements] - For tuples.
863
+ */
864
+ /**
865
+ * 'DepFree' refers to the fact that this function has no dependencies,
866
+ * while `expandType` depends on TypeScript itself for maximum compatibility.
867
+ * @example
868
+ * expandTypeDepFree('(123) '); // Outputs: '123'
869
+ * expandTypeDepFree('Array<number> '); // Outputs: { type: 'array', elementType: 'number' }
870
+ * expandTypeDepFree('Array<(123) > '); // Outputs: { type: 'array', elementType: '123' }
871
+ * expandTypeDepFree(' ( ( 123 ) ) '); // Outputs: '123'
872
+ * expandTypeDepFree(' (string ) |(number ) '); // Outputs: { type: 'union', members: ['string', 'number'] }
873
+ * expandTypeDepFree(' (( Object ) ) '); // Outputs: { type: 'object', properties: {} }
874
+ * @param {string} type - The input type to expand.
875
+ * @returns {string | ExpandTypeReturnValue} Object containing parsed information from type string.
876
+ */
877
+ declare function expandTypeDepFree(type: string): string | ExpandTypeReturnValue;
878
+
879
+ /**
880
+ * Extracts the parameter name and its optionality from a JSDoc parameter string.
881
+ *
882
+ * This function takes a rest parameter string from a JSDoc comment, trims it, and determines the parameter's
883
+ * name and whether it is optional. The optionality is inferred based on the presence of square brackets around
884
+ * the parameter name.
885
+ *
886
+ * @param {string} rest - The rest part of a JSDoc parameter string to parse.
887
+ * @returns {[string, boolean]} A tuple where the first element is the name of the parameter,
888
+ * and the second element is a boolean indicating if the parameter is optional.
889
+ */
890
+ declare function extractNameAndOptionality(rest: string): [string, boolean];
891
+
892
+ type Function$1 = any;
893
+ /** @typedef {import('@babel/types').Node} Node */
894
+ /** @typedef {import('@babel/types').Function} Function */
895
+ /**
896
+ * Checks if the provided node is a function-like structure.
897
+ *
898
+ * @param {Node} node - The Babel AST node to be tested.
899
+ * @returns {node is Function} - `true` if the node is a function-like structure, otherwise `false`.
900
+ */
901
+ declare function nodeIsFunction(node: any): node is globalThis.Function;
902
+
903
+ /**
904
+ * Parses JSDoc comments to extract parameter type information.
905
+ *
906
+ * @param {string} src - The JSDoc comment string to parse.
907
+ * @param {Function} [expandType] - An optional function to process the types found in the JSDoc.
908
+ * @returns {Record<string, any> | undefined} An object mapping parameter names to their parsed types, or undefined if no parameters are found.
909
+ */
910
+ declare function parseJSDoc(src: string, expandType?: Function): Record<string, any> | undefined;
911
+
912
+ /**
913
+ * @param {string} src - JSDoc comment of the setter.
914
+ * @param {Function} expandType - The expandType function.
915
+ * @returns {string | DocType | undefined} The parsed and possibly expanded type from
916
+ * the JSDoc comment, or undefined if parsing fails to find `@type`.
917
+ */
918
+ declare function parseJSDocSetter(src: string, expandType?: Function): string | DocType | undefined;
919
+
920
+ /**
921
+ * Extracts the content of a string that is delimited by curly braces.
922
+ * @example
923
+ * extractCurlyContent('{ {inner} }'); // Returns: {content: ' {inner} ', nextIndex: 11}
924
+ * @param {string} line - The string to extract from.
925
+ * @returns {{content: string, nextIndex: number}} An object containing the extracted content,
926
+ * and the index of the character immediately following the closing curly brace.
927
+ */
928
+ declare function extractCurlyContent(line: string): {
929
+ content: string;
930
+ nextIndex: number;
931
+ };
932
+ /**
933
+ * Parses JSDoc comments to extract and expand typedefs and their associated properties.
934
+ *
935
+ * It iterates through the lines of a `CommentBlock` from the Babel AST, looking for `@typedef` and `@property`
936
+ * annotations. When it finds a typedef, it stores it in the `typedefs` record. When it finds a property,
937
+ * it adds it to the last found typedef if it is an object type.
938
+ * @param {Record<string, object>} typedefs - An object to store typedefs, mapping type names to their expanded definitions.
939
+ * @param {Console["warn"]} warn - A warn function used for emitting warnings about non-extensible types.
940
+ * @param {import("@babel/types").Comment} comment - A comment extracted from Babel's AST, expected to be a CommentBlock containing type definitions.
941
+ * @param {Function} expandType - A function that takes a type expression as a string and returns a structured representation of the type.
942
+ */
943
+ declare function parseJSDocTypedef(typedefs: Record<string, object>, warn: Console["warn"], comment: any, expandType: Function): void;
944
+
945
+ type DocType$1 = {
946
+ /**
947
+ * - Type is optional.
948
+ */
949
+ optional: boolean;
950
+ };
951
+ /**
952
+ * @typedef DocType
953
+ * @property {boolean} optional - Type is optional.
954
+ */
955
+ /**
956
+ * @param {string | DocType} type - The type.
957
+ * @param {boolean} optional - Optionality
958
+ * @returns {string | DocType} The simplified type.
959
+ */
960
+ declare function simplifyType(type: string | DocType$1, optional: boolean): string | DocType$1;
961
+
962
+ /**
963
+ * @example
964
+ * trimEndSpaces('test \n '); // Returns: 'test \n'
965
+ * @param {string} str - The input string.
966
+ * @returns {string} Output string without spaces at the end.
967
+ */
968
+ declare function trimEndSpaces(str: string): string;
969
+
970
+ export { Asserter, type ClassMethod, type ClassPrivateMethod, type DocType$1 as DocType, type ExpandTypeReturnValue, type Function$1 as Function, type Options, type Stat, Stringifier, type TypeScriptType, addTypeChecks, ast2json, ast2jsonForComparison, code2ast2code, compareAST, expandType, expandTypeBabelTS, expandTypeDepFree, extractCurlyContent, extractNameAndOptionality, nodeIsFunction, parseJSDoc, parseJSDocSetter, parseJSDocTypedef, parseType, parseTypeBabelTS, simplifyType, toSourceBabelTS, toSourceTS, trimEndSpaces };