@voidzero-dev/vite-plus-core 0.2.3 → 0.2.5

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.
Files changed (72) hide show
  1. package/LICENSE +7 -115
  2. package/dist/rolldown/cli.mjs +11 -8
  3. package/dist/rolldown/config.d.mts +15 -2
  4. package/dist/rolldown/config.mjs +2 -2
  5. package/dist/rolldown/experimental-index.d.mts +4 -4
  6. package/dist/rolldown/experimental-index.mjs +8 -8
  7. package/dist/rolldown/filter-index.d.mts +1 -1
  8. package/dist/rolldown/index.d.mts +3 -3
  9. package/dist/rolldown/index.mjs +10 -4
  10. package/dist/rolldown/parallel-plugin-worker.mjs +2 -2
  11. package/dist/rolldown/parallel-plugin.d.mts +1 -1
  12. package/dist/rolldown/parse-ast-index.d.mts +1 -1
  13. package/dist/rolldown/parse-ast-index.mjs +2 -2
  14. package/dist/rolldown/plugins-index.d.mts +3 -3
  15. package/dist/rolldown/plugins-index.mjs +2 -2
  16. package/dist/rolldown/shared/{binding-B1q9aYT-.d.mts → binding-D26QphWG.d.mts} +12 -0
  17. package/dist/rolldown/shared/{binding-BmkJW3Wy.mjs → binding-TuFFIE_J.mjs} +26 -26
  18. package/dist/rolldown/shared/{bindingify-input-options-Cmm60vfj.mjs → bindingify-input-options-CwbcQL6W.mjs} +11 -13
  19. package/dist/rolldown/shared/{constructors-2i1T9YcF.d.mts → constructors-BbWPse2X.d.mts} +2 -2
  20. package/dist/rolldown/shared/{constructors-CE6zZSUt.mjs → constructors-D_3i7dpX.mjs} +1 -1
  21. package/dist/rolldown/shared/{define-config-BBz954-q.d.mts → define-config-BhJ90aEv.d.mts} +79 -2
  22. package/dist/rolldown/shared/dist-DX3cAjHx.mjs +154 -0
  23. package/dist/rolldown/shared/{error-BlQ0-ek7.mjs → error-BHRSI0R7.mjs} +1 -1
  24. package/dist/rolldown/shared/{load-config-CVVMWSlg.mjs → load-config-Bd7MgqCK.mjs} +19 -2
  25. package/dist/rolldown/shared/{logs-aMKUxRpj.mjs → logs-ZGEh6uhb.mjs} +6 -1
  26. package/dist/rolldown/shared/{normalize-string-or-regex-BYkbbGqQ.mjs → normalize-string-or-regex-dnh67V_w.mjs} +2 -2
  27. package/dist/rolldown/shared/{parse-Dphnedsw.mjs → parse-B6_waszz.mjs} +2 -2
  28. package/dist/rolldown/shared/{prompt-Bgj-uEyc.mjs → prompt-pZFoa1TT.mjs} +59 -17
  29. package/dist/rolldown/shared/{resolve-tsconfig-CdIAR1Eb.mjs → resolve-tsconfig-DxqIJB3x.mjs} +2 -2
  30. package/dist/rolldown/shared/{rolldown-Bnp916iM.mjs → rolldown-CACDGVWV.mjs} +1 -1
  31. package/dist/rolldown/shared/{rolldown-build-Cs2iVJuw.mjs → rolldown-build-BV22mk7t.mjs} +33 -13
  32. package/dist/rolldown/shared/{transform-CEmFsvJW.d.mts → transform-BPrUvqEZ.d.mts} +1 -1
  33. package/dist/rolldown/shared/{watch-ECGr-_QS.mjs → watch-CS_JygCu.mjs} +5 -5
  34. package/dist/rolldown/utils-index.d.mts +3 -3
  35. package/dist/rolldown/utils-index.mjs +8 -6
  36. package/dist/tsdown/{build-B_nvJe4A-CvbtVBxy.js → build-BlM3pDGJ-C8Uovnt4.js} +166 -76
  37. package/dist/tsdown/{debug-DLdR-9XB-DQZ6QLC0.js → debug-B1wUEHkd-DhRzGJTf.js} +21 -6
  38. package/dist/tsdown/{detect-B97OSl92-BJPZyIKJ.js → detect-BNXt7gkp-DKAC9Z7n.js} +7 -2
  39. package/dist/tsdown/dist-Pjag7IPt.js +3206 -0
  40. package/dist/tsdown/fs-qxJxxoCE-B_amenYz.js +46 -0
  41. package/dist/tsdown/{general-Cp4NiJNK-CbyrS9q1.js → general-Cp4NiJNK-xAqmPhMP.js} +1 -1
  42. package/dist/tsdown/index-types.d.ts +1361 -1326
  43. package/dist/tsdown/index.js +7 -4
  44. package/dist/tsdown/internal-Bn6NGoha.js +3 -0
  45. package/dist/tsdown/npm_cjs_chunk_range.cjs +14 -13
  46. package/dist/tsdown/npm_cjs_chunk_semver.cjs +6 -6
  47. package/dist/tsdown/npm_entry_picomatch.cjs +44 -15
  48. package/dist/tsdown/npm_entry_semver_functions_coerce.cjs +2 -2
  49. package/dist/tsdown/npm_entry_semver_functions_satisfies.cjs +1 -1
  50. package/dist/tsdown/npm_entry_semver_ranges_min-version.cjs +1 -1
  51. package/dist/tsdown/run.js +3 -3
  52. package/dist/tsdown/{src-CISfE_A0.js → src-CK50m8R_.js} +5 -5
  53. package/dist/tsdown/target-CqeSqtms-CIvlAiuG.js +35 -0
  54. package/dist/tsdown/{tsc-CdZE7QwS.js → tsc-CilQvmj4.js} +15 -7
  55. package/dist/tsdown/{tsc-context-CX_GXdyS.js → tsc-context-BusiAGCd.js} +6 -2
  56. package/dist/tsdown/tsdown-css.js +74 -23
  57. package/dist/tsdown/tsdown-exe.js +27 -26
  58. package/dist/vite/client/client.mjs +4 -4
  59. package/dist/vite/node/chunks/build.js +194 -84
  60. package/dist/vite/node/chunks/dist2.js +1 -1
  61. package/dist/vite/node/chunks/lib.js +1 -1
  62. package/dist/vite/node/chunks/node.js +484 -71
  63. package/dist/vite/node/chunks/postcss-import.js +1 -1
  64. package/dist/vite/node/cli.js +3 -4
  65. package/dist/vite/node/index.d.ts +3 -3
  66. package/dist/vite/node/index.js +1 -2
  67. package/package.json +18 -16
  68. package/dist/tsdown/dist-CZtGyfn3.js +0 -200
  69. package/dist/tsdown/dist-CqbVlnVq.js +0 -32057
  70. package/dist/tsdown/internal-bfoxcI4F.js +0 -3
  71. package/dist/tsdown/target-CqeSqtms-FAqYuGyB.js +0 -79
  72. package/dist/vite/node/chunks/logger.js +0 -361
@@ -0,0 +1,3206 @@
1
+ import { r as createDebug } from "./main-BlTcyuFi.js";
2
+ import { _ as filename_dts_to, b as replaceTemplateName, c as RE_CSS, d as RE_JS, f as RE_JSON, g as RE_VUE, h as RE_TS, l as RE_DTS, m as RE_ROLLDOWN_RUNTIME, o as at, p as RE_NODE_MODULES, s as ee, u as RE_DTS_MAP, v as filename_js_to_dts, x as resolveTemplateFn, y as filename_to_dts } from "./build-BlM3pDGJ-C8Uovnt4.js";
3
+ import { i as __require$1, n as globalContext, r as invalidateContextFile, t as createContext } from "./tsc-context-BusiAGCd.js";
4
+ import { createRequire } from "node:module";
5
+ import process from "node:process";
6
+ import { styleText } from "node:util";
7
+ import { fork, spawn } from "node:child_process";
8
+ import path, { dirname, extname } from "node:path";
9
+ import { existsSync } from "node:fs";
10
+ import { access, mkdtemp, readFile, rm } from "node:fs/promises";
11
+ import { importerId, include } from "@voidzero-dev/vite-plus-core/rolldown/filter";
12
+ import { tmpdir } from "node:os";
13
+ import { ResolverFactory, isolatedDeclarationSync } from "@voidzero-dev/vite-plus-core/rolldown/experimental";
14
+ import { print } from "yuku-codegen";
15
+ import { parse as parse$1, walk } from "yuku-parser";
16
+ //#region ../../node_modules/.pnpm/yuku-ast@0.1.7/node_modules/yuku-ast/dist/index.mjs
17
+ const span = {
18
+ start: 0,
19
+ end: 0
20
+ };
21
+ const isComputedKey = (key) => key.type !== "Identifier" && key.type !== "PrivateIdentifier";
22
+ const b = {
23
+ identifier(name, opts = {}) {
24
+ return {
25
+ type: "Identifier",
26
+ name,
27
+ ...opts,
28
+ ...span
29
+ };
30
+ },
31
+ privateIdentifier(name) {
32
+ return {
33
+ type: "PrivateIdentifier",
34
+ name,
35
+ ...span
36
+ };
37
+ },
38
+ stringLiteral(value) {
39
+ return {
40
+ type: "Literal",
41
+ value,
42
+ raw: JSON.stringify(value),
43
+ ...span
44
+ };
45
+ },
46
+ numericLiteral(value) {
47
+ return {
48
+ type: "Literal",
49
+ value,
50
+ raw: String(value),
51
+ ...span
52
+ };
53
+ },
54
+ booleanLiteral(value) {
55
+ return {
56
+ type: "Literal",
57
+ value,
58
+ raw: String(value),
59
+ ...span
60
+ };
61
+ },
62
+ nullLiteral() {
63
+ return {
64
+ type: "Literal",
65
+ value: null,
66
+ raw: "null",
67
+ ...span
68
+ };
69
+ },
70
+ bigIntLiteral(value) {
71
+ return {
72
+ type: "Literal",
73
+ value,
74
+ raw: `${value}n`,
75
+ bigint: String(value),
76
+ ...span
77
+ };
78
+ },
79
+ regExpLiteral(pattern, flags = "") {
80
+ let value = null;
81
+ try {
82
+ value = new RegExp(pattern, flags);
83
+ } catch {}
84
+ return {
85
+ type: "Literal",
86
+ value,
87
+ raw: `/${pattern}/${flags}`,
88
+ regex: {
89
+ pattern,
90
+ flags
91
+ },
92
+ ...span
93
+ };
94
+ },
95
+ templateLiteral(quasis, expressions) {
96
+ return {
97
+ type: "TemplateLiteral",
98
+ quasis,
99
+ expressions,
100
+ ...span
101
+ };
102
+ },
103
+ templateElement(cooked, tail = false) {
104
+ return {
105
+ type: "TemplateElement",
106
+ value: {
107
+ raw: cooked,
108
+ cooked
109
+ },
110
+ tail,
111
+ ...span
112
+ };
113
+ },
114
+ thisExpression() {
115
+ return {
116
+ type: "ThisExpression",
117
+ ...span
118
+ };
119
+ },
120
+ super() {
121
+ return {
122
+ type: "Super",
123
+ ...span
124
+ };
125
+ },
126
+ arrayPattern(elements) {
127
+ return {
128
+ type: "ArrayPattern",
129
+ elements,
130
+ ...span
131
+ };
132
+ },
133
+ objectPattern(properties) {
134
+ return {
135
+ type: "ObjectPattern",
136
+ properties,
137
+ ...span
138
+ };
139
+ },
140
+ assignmentPattern(left, right) {
141
+ return {
142
+ type: "AssignmentPattern",
143
+ left,
144
+ right,
145
+ ...span
146
+ };
147
+ },
148
+ restElement(argument) {
149
+ return {
150
+ type: "RestElement",
151
+ argument,
152
+ ...span
153
+ };
154
+ },
155
+ /** A member of an `ObjectExpression`. For an `ObjectPattern` member, use {@link bindingProperty}. */
156
+ objectProperty(key, value, opts = {}) {
157
+ return {
158
+ type: "Property",
159
+ kind: opts.kind ?? "init",
160
+ key,
161
+ value,
162
+ method: opts.method ?? false,
163
+ shorthand: opts.shorthand ?? false,
164
+ computed: opts.computed ?? isComputedKey(key),
165
+ ...span
166
+ };
167
+ },
168
+ /** A member of an `ObjectPattern`, whose value is a binding target. For an `ObjectExpression` member, use {@link objectProperty}. */
169
+ bindingProperty(key, value, opts = {}) {
170
+ return {
171
+ type: "Property",
172
+ kind: "init",
173
+ key,
174
+ value,
175
+ method: false,
176
+ shorthand: opts.shorthand ?? false,
177
+ computed: opts.computed ?? isComputedKey(key),
178
+ ...span
179
+ };
180
+ },
181
+ arrayExpression(elements = []) {
182
+ return {
183
+ type: "ArrayExpression",
184
+ elements,
185
+ ...span
186
+ };
187
+ },
188
+ objectExpression(properties = []) {
189
+ return {
190
+ type: "ObjectExpression",
191
+ properties,
192
+ ...span
193
+ };
194
+ },
195
+ spreadElement(argument) {
196
+ return {
197
+ type: "SpreadElement",
198
+ argument,
199
+ ...span
200
+ };
201
+ },
202
+ sequenceExpression(expressions) {
203
+ return {
204
+ type: "SequenceExpression",
205
+ expressions,
206
+ ...span
207
+ };
208
+ },
209
+ parenthesizedExpression(expression) {
210
+ return {
211
+ type: "ParenthesizedExpression",
212
+ expression,
213
+ ...span
214
+ };
215
+ },
216
+ unaryExpression(operator, argument) {
217
+ return {
218
+ type: "UnaryExpression",
219
+ operator,
220
+ prefix: true,
221
+ argument,
222
+ ...span
223
+ };
224
+ },
225
+ updateExpression(operator, argument, prefix = false) {
226
+ return {
227
+ type: "UpdateExpression",
228
+ operator,
229
+ argument,
230
+ prefix,
231
+ ...span
232
+ };
233
+ },
234
+ binaryExpression(operator, left, right) {
235
+ return {
236
+ type: "BinaryExpression",
237
+ operator,
238
+ left,
239
+ right,
240
+ ...span
241
+ };
242
+ },
243
+ logicalExpression(operator, left, right) {
244
+ return {
245
+ type: "LogicalExpression",
246
+ operator,
247
+ left,
248
+ right,
249
+ ...span
250
+ };
251
+ },
252
+ assignmentExpression(operator, left, right) {
253
+ return {
254
+ type: "AssignmentExpression",
255
+ operator,
256
+ left,
257
+ right,
258
+ ...span
259
+ };
260
+ },
261
+ conditionalExpression(test, consequent, alternate) {
262
+ return {
263
+ type: "ConditionalExpression",
264
+ test,
265
+ consequent,
266
+ alternate,
267
+ ...span
268
+ };
269
+ },
270
+ yieldExpression(argument = null, delegate = false) {
271
+ return {
272
+ type: "YieldExpression",
273
+ delegate,
274
+ argument,
275
+ ...span
276
+ };
277
+ },
278
+ awaitExpression(argument) {
279
+ return {
280
+ type: "AwaitExpression",
281
+ argument,
282
+ ...span
283
+ };
284
+ },
285
+ memberExpression(object, property, opts = {}) {
286
+ return {
287
+ type: "MemberExpression",
288
+ object,
289
+ property,
290
+ computed: opts.computed ?? isComputedKey(property),
291
+ optional: opts.optional ?? false,
292
+ ...span
293
+ };
294
+ },
295
+ callExpression(callee, args = [], opts = {}) {
296
+ return {
297
+ type: "CallExpression",
298
+ callee,
299
+ arguments: args,
300
+ optional: opts.optional ?? false,
301
+ ...opts,
302
+ ...span
303
+ };
304
+ },
305
+ newExpression(callee, args = [], opts = {}) {
306
+ return {
307
+ type: "NewExpression",
308
+ callee,
309
+ arguments: args,
310
+ ...opts,
311
+ ...span
312
+ };
313
+ },
314
+ chainExpression(expression) {
315
+ return {
316
+ type: "ChainExpression",
317
+ expression,
318
+ ...span
319
+ };
320
+ },
321
+ taggedTemplateExpression(tag, quasi, opts = {}) {
322
+ return {
323
+ type: "TaggedTemplateExpression",
324
+ tag,
325
+ quasi,
326
+ ...opts,
327
+ ...span
328
+ };
329
+ },
330
+ metaProperty(meta, property) {
331
+ return {
332
+ type: "MetaProperty",
333
+ meta: b.identifier(meta),
334
+ property: b.identifier(property),
335
+ ...span
336
+ };
337
+ },
338
+ importExpression(source, opts = {}) {
339
+ return {
340
+ type: "ImportExpression",
341
+ source,
342
+ options: opts.options ?? null,
343
+ phase: opts.phase ?? null,
344
+ ...span
345
+ };
346
+ },
347
+ arrowFunctionExpression(params, body, opts = {}) {
348
+ return {
349
+ type: "ArrowFunctionExpression",
350
+ id: null,
351
+ generator: false,
352
+ async: opts.async ?? false,
353
+ params,
354
+ body,
355
+ expression: body.type !== "BlockStatement",
356
+ ...opts,
357
+ ...span
358
+ };
359
+ },
360
+ functionExpression(params, body, opts = {}) {
361
+ return {
362
+ type: "FunctionExpression",
363
+ id: opts.id ?? null,
364
+ generator: opts.generator ?? false,
365
+ async: opts.async ?? false,
366
+ params,
367
+ body,
368
+ expression: false,
369
+ ...span
370
+ };
371
+ },
372
+ functionDeclaration(id, params, body, opts = {}) {
373
+ return {
374
+ type: "FunctionDeclaration",
375
+ id,
376
+ generator: opts.generator ?? false,
377
+ async: opts.async ?? false,
378
+ params,
379
+ body,
380
+ expression: false,
381
+ ...span
382
+ };
383
+ },
384
+ classDeclaration(id, body, opts = {}) {
385
+ return {
386
+ type: "ClassDeclaration",
387
+ decorators: opts.decorators ?? [],
388
+ id,
389
+ superClass: opts.superClass ?? null,
390
+ body,
391
+ ...opts,
392
+ ...span
393
+ };
394
+ },
395
+ classExpression(id, body, opts = {}) {
396
+ return {
397
+ type: "ClassExpression",
398
+ decorators: opts.decorators ?? [],
399
+ id,
400
+ superClass: opts.superClass ?? null,
401
+ body,
402
+ ...span
403
+ };
404
+ },
405
+ classBody(body = []) {
406
+ return {
407
+ type: "ClassBody",
408
+ body,
409
+ ...span
410
+ };
411
+ },
412
+ methodDefinition(key, value, opts = {}) {
413
+ return {
414
+ type: "MethodDefinition",
415
+ decorators: [],
416
+ key,
417
+ value,
418
+ kind: opts.kind ?? "method",
419
+ computed: opts.computed ?? isComputedKey(key),
420
+ static: opts.static ?? false,
421
+ ...span
422
+ };
423
+ },
424
+ propertyDefinition(key, value = null, opts = {}) {
425
+ return {
426
+ type: "PropertyDefinition",
427
+ decorators: opts.decorators ?? [],
428
+ key,
429
+ value,
430
+ computed: opts.computed ?? isComputedKey(key),
431
+ static: opts.static ?? false,
432
+ ...span
433
+ };
434
+ },
435
+ accessorProperty(key, value = null, opts = {}) {
436
+ return {
437
+ type: "AccessorProperty",
438
+ decorators: [],
439
+ key,
440
+ value,
441
+ computed: opts.computed ?? isComputedKey(key),
442
+ static: opts.static ?? false,
443
+ ...span
444
+ };
445
+ },
446
+ tsAbstractMethodDefinition(key, value, opts = {}) {
447
+ return {
448
+ type: "TSAbstractMethodDefinition",
449
+ decorators: [],
450
+ key,
451
+ value,
452
+ kind: opts.kind ?? "method",
453
+ computed: opts.computed ?? isComputedKey(key),
454
+ static: opts.static ?? false,
455
+ ...span
456
+ };
457
+ },
458
+ tsAbstractPropertyDefinition(key, value = null, opts = {}) {
459
+ return {
460
+ type: "TSAbstractPropertyDefinition",
461
+ decorators: [],
462
+ key,
463
+ value,
464
+ computed: opts.computed ?? isComputedKey(key),
465
+ static: opts.static ?? false,
466
+ ...span
467
+ };
468
+ },
469
+ tsAbstractAccessorProperty(key, value = null, opts = {}) {
470
+ return {
471
+ type: "TSAbstractAccessorProperty",
472
+ decorators: [],
473
+ key,
474
+ value,
475
+ computed: opts.computed ?? isComputedKey(key),
476
+ static: opts.static ?? false,
477
+ ...span
478
+ };
479
+ },
480
+ staticBlock(body = []) {
481
+ return {
482
+ type: "StaticBlock",
483
+ body,
484
+ ...span
485
+ };
486
+ },
487
+ decorator(expression) {
488
+ return {
489
+ type: "Decorator",
490
+ expression,
491
+ ...span
492
+ };
493
+ },
494
+ expressionStatement(expression) {
495
+ return {
496
+ type: "ExpressionStatement",
497
+ expression,
498
+ ...span
499
+ };
500
+ },
501
+ directive(value) {
502
+ return {
503
+ type: "ExpressionStatement",
504
+ expression: b.stringLiteral(value),
505
+ directive: value,
506
+ ...span
507
+ };
508
+ },
509
+ blockStatement(body = []) {
510
+ return {
511
+ type: "BlockStatement",
512
+ body,
513
+ ...span
514
+ };
515
+ },
516
+ emptyStatement() {
517
+ return {
518
+ type: "EmptyStatement",
519
+ ...span
520
+ };
521
+ },
522
+ debuggerStatement() {
523
+ return {
524
+ type: "DebuggerStatement",
525
+ ...span
526
+ };
527
+ },
528
+ returnStatement(argument = null) {
529
+ return {
530
+ type: "ReturnStatement",
531
+ argument,
532
+ ...span
533
+ };
534
+ },
535
+ ifStatement(test, consequent, alternate = null) {
536
+ return {
537
+ type: "IfStatement",
538
+ test,
539
+ consequent,
540
+ alternate,
541
+ ...span
542
+ };
543
+ },
544
+ switchStatement(discriminant, cases) {
545
+ return {
546
+ type: "SwitchStatement",
547
+ discriminant,
548
+ cases,
549
+ ...span
550
+ };
551
+ },
552
+ switchCase(test, consequent) {
553
+ return {
554
+ type: "SwitchCase",
555
+ test,
556
+ consequent,
557
+ ...span
558
+ };
559
+ },
560
+ throwStatement(argument) {
561
+ return {
562
+ type: "ThrowStatement",
563
+ argument,
564
+ ...span
565
+ };
566
+ },
567
+ tryStatement(block, handler = null, finalizer = null) {
568
+ return {
569
+ type: "TryStatement",
570
+ block,
571
+ handler,
572
+ finalizer,
573
+ ...span
574
+ };
575
+ },
576
+ catchClause(param, body) {
577
+ return {
578
+ type: "CatchClause",
579
+ param,
580
+ body,
581
+ ...span
582
+ };
583
+ },
584
+ whileStatement(test, body) {
585
+ return {
586
+ type: "WhileStatement",
587
+ test,
588
+ body,
589
+ ...span
590
+ };
591
+ },
592
+ doWhileStatement(body, test) {
593
+ return {
594
+ type: "DoWhileStatement",
595
+ body,
596
+ test,
597
+ ...span
598
+ };
599
+ },
600
+ forStatement(init, test, update, body) {
601
+ return {
602
+ type: "ForStatement",
603
+ init,
604
+ test,
605
+ update,
606
+ body,
607
+ ...span
608
+ };
609
+ },
610
+ forInStatement(left, right, body) {
611
+ return {
612
+ type: "ForInStatement",
613
+ left,
614
+ right,
615
+ body,
616
+ ...span
617
+ };
618
+ },
619
+ forOfStatement(left, right, body, isAwait = false) {
620
+ return {
621
+ type: "ForOfStatement",
622
+ left,
623
+ right,
624
+ body,
625
+ await: isAwait,
626
+ ...span
627
+ };
628
+ },
629
+ labeledStatement(label, body) {
630
+ return {
631
+ type: "LabeledStatement",
632
+ label,
633
+ body,
634
+ ...span
635
+ };
636
+ },
637
+ breakStatement(label = null) {
638
+ return {
639
+ type: "BreakStatement",
640
+ label,
641
+ ...span
642
+ };
643
+ },
644
+ continueStatement(label = null) {
645
+ return {
646
+ type: "ContinueStatement",
647
+ label,
648
+ ...span
649
+ };
650
+ },
651
+ withStatement(object, body) {
652
+ return {
653
+ type: "WithStatement",
654
+ object,
655
+ body,
656
+ ...span
657
+ };
658
+ },
659
+ variableDeclaration(kind, declarations) {
660
+ return {
661
+ type: "VariableDeclaration",
662
+ kind,
663
+ declarations,
664
+ ...span
665
+ };
666
+ },
667
+ variableDeclarator(id, init = null) {
668
+ return {
669
+ type: "VariableDeclarator",
670
+ id,
671
+ init,
672
+ ...span
673
+ };
674
+ },
675
+ importDeclaration(specifiers, source, opts = {}) {
676
+ return {
677
+ type: "ImportDeclaration",
678
+ specifiers,
679
+ source,
680
+ phase: opts.phase ?? null,
681
+ attributes: opts.attributes ?? [],
682
+ ...opts,
683
+ ...span
684
+ };
685
+ },
686
+ importSpecifier(imported, local) {
687
+ return {
688
+ type: "ImportSpecifier",
689
+ imported,
690
+ local,
691
+ ...span
692
+ };
693
+ },
694
+ importDefaultSpecifier(local) {
695
+ return {
696
+ type: "ImportDefaultSpecifier",
697
+ local,
698
+ ...span
699
+ };
700
+ },
701
+ importNamespaceSpecifier(local) {
702
+ return {
703
+ type: "ImportNamespaceSpecifier",
704
+ local,
705
+ ...span
706
+ };
707
+ },
708
+ importAttribute(key, value) {
709
+ return {
710
+ type: "ImportAttribute",
711
+ key,
712
+ value,
713
+ ...span
714
+ };
715
+ },
716
+ exportNamedDeclaration(declaration, specifiers = [], opts = {}) {
717
+ return {
718
+ type: "ExportNamedDeclaration",
719
+ declaration,
720
+ specifiers,
721
+ source: opts.source ?? null,
722
+ attributes: opts.attributes ?? [],
723
+ ...opts,
724
+ ...span
725
+ };
726
+ },
727
+ exportDefaultDeclaration(declaration) {
728
+ return {
729
+ type: "ExportDefaultDeclaration",
730
+ declaration,
731
+ ...span
732
+ };
733
+ },
734
+ exportAllDeclaration(source, opts = {}) {
735
+ return {
736
+ type: "ExportAllDeclaration",
737
+ exported: opts.exported ?? null,
738
+ source,
739
+ attributes: opts.attributes ?? [],
740
+ ...opts,
741
+ ...span
742
+ };
743
+ },
744
+ exportSpecifier(local, exported) {
745
+ return {
746
+ type: "ExportSpecifier",
747
+ local,
748
+ exported,
749
+ ...span
750
+ };
751
+ },
752
+ jsxIdentifier(name) {
753
+ return {
754
+ type: "JSXIdentifier",
755
+ name,
756
+ ...span
757
+ };
758
+ },
759
+ jsxNamespacedName(namespace, name) {
760
+ return {
761
+ type: "JSXNamespacedName",
762
+ namespace,
763
+ name,
764
+ ...span
765
+ };
766
+ },
767
+ jsxMemberExpression(object, property) {
768
+ return {
769
+ type: "JSXMemberExpression",
770
+ object,
771
+ property,
772
+ ...span
773
+ };
774
+ },
775
+ jsxElement(openingElement, children = [], closingElement = null) {
776
+ return {
777
+ type: "JSXElement",
778
+ openingElement,
779
+ children,
780
+ closingElement,
781
+ ...span
782
+ };
783
+ },
784
+ jsxOpeningElement(name, attributes = [], selfClosing = false) {
785
+ return {
786
+ type: "JSXOpeningElement",
787
+ name,
788
+ attributes,
789
+ selfClosing,
790
+ ...span
791
+ };
792
+ },
793
+ jsxClosingElement(name) {
794
+ return {
795
+ type: "JSXClosingElement",
796
+ name,
797
+ ...span
798
+ };
799
+ },
800
+ jsxOpeningFragment() {
801
+ return {
802
+ type: "JSXOpeningFragment",
803
+ ...span
804
+ };
805
+ },
806
+ jsxClosingFragment() {
807
+ return {
808
+ type: "JSXClosingFragment",
809
+ ...span
810
+ };
811
+ },
812
+ jsxFragment(children = []) {
813
+ return {
814
+ type: "JSXFragment",
815
+ openingFragment: b.jsxOpeningFragment(),
816
+ children,
817
+ closingFragment: b.jsxClosingFragment(),
818
+ ...span
819
+ };
820
+ },
821
+ jsxAttribute(name, value = null) {
822
+ return {
823
+ type: "JSXAttribute",
824
+ name,
825
+ value,
826
+ ...span
827
+ };
828
+ },
829
+ jsxSpreadAttribute(argument) {
830
+ return {
831
+ type: "JSXSpreadAttribute",
832
+ argument,
833
+ ...span
834
+ };
835
+ },
836
+ jsxExpressionContainer(expression) {
837
+ return {
838
+ type: "JSXExpressionContainer",
839
+ expression,
840
+ ...span
841
+ };
842
+ },
843
+ jsxEmptyExpression() {
844
+ return {
845
+ type: "JSXEmptyExpression",
846
+ ...span
847
+ };
848
+ },
849
+ jsxText(value) {
850
+ return {
851
+ type: "JSXText",
852
+ value,
853
+ raw: value,
854
+ ...span
855
+ };
856
+ },
857
+ jsxSpreadChild(expression) {
858
+ return {
859
+ type: "JSXSpreadChild",
860
+ expression,
861
+ ...span
862
+ };
863
+ },
864
+ tsTypeAnnotation(typeAnnotation) {
865
+ return {
866
+ type: "TSTypeAnnotation",
867
+ typeAnnotation,
868
+ ...span
869
+ };
870
+ },
871
+ tsAnyKeyword: () => ({
872
+ type: "TSAnyKeyword",
873
+ ...span
874
+ }),
875
+ tsUnknownKeyword: () => ({
876
+ type: "TSUnknownKeyword",
877
+ ...span
878
+ }),
879
+ tsNeverKeyword: () => ({
880
+ type: "TSNeverKeyword",
881
+ ...span
882
+ }),
883
+ tsVoidKeyword: () => ({
884
+ type: "TSVoidKeyword",
885
+ ...span
886
+ }),
887
+ tsNullKeyword: () => ({
888
+ type: "TSNullKeyword",
889
+ ...span
890
+ }),
891
+ tsUndefinedKeyword: () => ({
892
+ type: "TSUndefinedKeyword",
893
+ ...span
894
+ }),
895
+ tsStringKeyword: () => ({
896
+ type: "TSStringKeyword",
897
+ ...span
898
+ }),
899
+ tsNumberKeyword: () => ({
900
+ type: "TSNumberKeyword",
901
+ ...span
902
+ }),
903
+ tsBigIntKeyword: () => ({
904
+ type: "TSBigIntKeyword",
905
+ ...span
906
+ }),
907
+ tsBooleanKeyword: () => ({
908
+ type: "TSBooleanKeyword",
909
+ ...span
910
+ }),
911
+ tsSymbolKeyword: () => ({
912
+ type: "TSSymbolKeyword",
913
+ ...span
914
+ }),
915
+ tsObjectKeyword: () => ({
916
+ type: "TSObjectKeyword",
917
+ ...span
918
+ }),
919
+ tsIntrinsicKeyword: () => ({
920
+ type: "TSIntrinsicKeyword",
921
+ ...span
922
+ }),
923
+ tsThisType: () => ({
924
+ type: "TSThisType",
925
+ ...span
926
+ }),
927
+ tsTypeReference(typeName, typeArguments = null) {
928
+ return {
929
+ type: "TSTypeReference",
930
+ typeName,
931
+ typeArguments,
932
+ ...span
933
+ };
934
+ },
935
+ tsQualifiedName(left, right) {
936
+ return {
937
+ type: "TSQualifiedName",
938
+ left,
939
+ right,
940
+ ...span
941
+ };
942
+ },
943
+ tsTypeQuery(exprName, typeArguments = null) {
944
+ return {
945
+ type: "TSTypeQuery",
946
+ exprName,
947
+ typeArguments,
948
+ ...span
949
+ };
950
+ },
951
+ tsImportType(source, opts = {}) {
952
+ return {
953
+ type: "TSImportType",
954
+ source,
955
+ options: opts.options ?? null,
956
+ qualifier: opts.qualifier ?? null,
957
+ typeArguments: opts.typeArguments ?? null,
958
+ ...span
959
+ };
960
+ },
961
+ tsTypeParameter(name, opts = {}) {
962
+ return {
963
+ type: "TSTypeParameter",
964
+ name,
965
+ constraint: opts.constraint ?? null,
966
+ default: opts.default ?? null,
967
+ in: opts.in ?? false,
968
+ out: opts.out ?? false,
969
+ const: opts.const ?? false,
970
+ ...span
971
+ };
972
+ },
973
+ tsTypeParameterDeclaration(params) {
974
+ return {
975
+ type: "TSTypeParameterDeclaration",
976
+ params,
977
+ ...span
978
+ };
979
+ },
980
+ tsTypeParameterInstantiation(params) {
981
+ return {
982
+ type: "TSTypeParameterInstantiation",
983
+ params,
984
+ ...span
985
+ };
986
+ },
987
+ tsLiteralType(literal) {
988
+ return {
989
+ type: "TSLiteralType",
990
+ literal,
991
+ ...span
992
+ };
993
+ },
994
+ tsTemplateLiteralType(quasis, types) {
995
+ return {
996
+ type: "TSTemplateLiteralType",
997
+ quasis,
998
+ types,
999
+ ...span
1000
+ };
1001
+ },
1002
+ tsArrayType(elementType) {
1003
+ return {
1004
+ type: "TSArrayType",
1005
+ elementType,
1006
+ ...span
1007
+ };
1008
+ },
1009
+ tsIndexedAccessType(objectType, indexType) {
1010
+ return {
1011
+ type: "TSIndexedAccessType",
1012
+ objectType,
1013
+ indexType,
1014
+ ...span
1015
+ };
1016
+ },
1017
+ tsTupleType(elementTypes) {
1018
+ return {
1019
+ type: "TSTupleType",
1020
+ elementTypes,
1021
+ ...span
1022
+ };
1023
+ },
1024
+ tsNamedTupleMember(label, elementType, optional = false) {
1025
+ return {
1026
+ type: "TSNamedTupleMember",
1027
+ label,
1028
+ elementType,
1029
+ optional,
1030
+ ...span
1031
+ };
1032
+ },
1033
+ tsOptionalType(typeAnnotation) {
1034
+ return {
1035
+ type: "TSOptionalType",
1036
+ typeAnnotation,
1037
+ ...span
1038
+ };
1039
+ },
1040
+ tsRestType(typeAnnotation) {
1041
+ return {
1042
+ type: "TSRestType",
1043
+ typeAnnotation,
1044
+ ...span
1045
+ };
1046
+ },
1047
+ tsJSDocNullableType(typeAnnotation, postfix = false) {
1048
+ return {
1049
+ type: "TSJSDocNullableType",
1050
+ typeAnnotation,
1051
+ postfix,
1052
+ ...span
1053
+ };
1054
+ },
1055
+ tsJSDocNonNullableType(typeAnnotation, postfix = false) {
1056
+ return {
1057
+ type: "TSJSDocNonNullableType",
1058
+ typeAnnotation,
1059
+ postfix,
1060
+ ...span
1061
+ };
1062
+ },
1063
+ tsJSDocUnknownType() {
1064
+ return {
1065
+ type: "TSJSDocUnknownType",
1066
+ ...span
1067
+ };
1068
+ },
1069
+ tsUnionType(types) {
1070
+ return {
1071
+ type: "TSUnionType",
1072
+ types,
1073
+ ...span
1074
+ };
1075
+ },
1076
+ tsIntersectionType(types) {
1077
+ return {
1078
+ type: "TSIntersectionType",
1079
+ types,
1080
+ ...span
1081
+ };
1082
+ },
1083
+ tsConditionalType(checkType, extendsType, trueType, falseType) {
1084
+ return {
1085
+ type: "TSConditionalType",
1086
+ checkType,
1087
+ extendsType,
1088
+ trueType,
1089
+ falseType,
1090
+ ...span
1091
+ };
1092
+ },
1093
+ tsInferType(typeParameter) {
1094
+ return {
1095
+ type: "TSInferType",
1096
+ typeParameter,
1097
+ ...span
1098
+ };
1099
+ },
1100
+ tsTypeOperator(operator, typeAnnotation) {
1101
+ return {
1102
+ type: "TSTypeOperator",
1103
+ operator,
1104
+ typeAnnotation,
1105
+ ...span
1106
+ };
1107
+ },
1108
+ tsParenthesizedType(typeAnnotation) {
1109
+ return {
1110
+ type: "TSParenthesizedType",
1111
+ typeAnnotation,
1112
+ ...span
1113
+ };
1114
+ },
1115
+ tsFunctionType(params, returnType, typeParameters = null) {
1116
+ return {
1117
+ type: "TSFunctionType",
1118
+ typeParameters,
1119
+ params,
1120
+ returnType,
1121
+ ...span
1122
+ };
1123
+ },
1124
+ tsConstructorType(params, returnType, opts = {}) {
1125
+ return {
1126
+ type: "TSConstructorType",
1127
+ abstract: opts.abstract ?? false,
1128
+ typeParameters: opts.typeParameters ?? null,
1129
+ params,
1130
+ returnType,
1131
+ ...span
1132
+ };
1133
+ },
1134
+ tsTypePredicate(parameterName, typeAnnotation = null, asserts = false) {
1135
+ return {
1136
+ type: "TSTypePredicate",
1137
+ parameterName,
1138
+ typeAnnotation,
1139
+ asserts,
1140
+ ...span
1141
+ };
1142
+ },
1143
+ tsTypeLiteral(members) {
1144
+ return {
1145
+ type: "TSTypeLiteral",
1146
+ members,
1147
+ ...span
1148
+ };
1149
+ },
1150
+ tsMappedType(key, constraint, opts = {}) {
1151
+ return {
1152
+ type: "TSMappedType",
1153
+ key,
1154
+ constraint,
1155
+ nameType: opts.nameType ?? null,
1156
+ typeAnnotation: opts.typeAnnotation ?? null,
1157
+ optional: opts.optional ?? false,
1158
+ readonly: opts.readonly ?? null,
1159
+ ...span
1160
+ };
1161
+ },
1162
+ tsPropertySignature(key, opts = {}) {
1163
+ return {
1164
+ type: "TSPropertySignature",
1165
+ key,
1166
+ typeAnnotation: opts.typeAnnotation ?? null,
1167
+ computed: opts.computed ?? isComputedKey(key),
1168
+ optional: opts.optional ?? false,
1169
+ readonly: opts.readonly ?? false,
1170
+ accessibility: null,
1171
+ static: false,
1172
+ ...span
1173
+ };
1174
+ },
1175
+ tsMethodSignature(key, params, opts = {}) {
1176
+ return {
1177
+ type: "TSMethodSignature",
1178
+ key,
1179
+ computed: opts.computed ?? isComputedKey(key),
1180
+ optional: opts.optional ?? false,
1181
+ kind: opts.kind ?? "method",
1182
+ typeParameters: opts.typeParameters ?? null,
1183
+ params,
1184
+ returnType: opts.returnType ?? null,
1185
+ accessibility: null,
1186
+ readonly: false,
1187
+ static: false,
1188
+ ...span
1189
+ };
1190
+ },
1191
+ tsCallSignatureDeclaration(params, returnType = null, typeParameters = null) {
1192
+ return {
1193
+ type: "TSCallSignatureDeclaration",
1194
+ typeParameters,
1195
+ params,
1196
+ returnType,
1197
+ ...span
1198
+ };
1199
+ },
1200
+ tsConstructSignatureDeclaration(params, returnType = null, typeParameters = null) {
1201
+ return {
1202
+ type: "TSConstructSignatureDeclaration",
1203
+ typeParameters,
1204
+ params,
1205
+ returnType,
1206
+ ...span
1207
+ };
1208
+ },
1209
+ tsIndexSignature(parameters, typeAnnotation, opts = {}) {
1210
+ return {
1211
+ type: "TSIndexSignature",
1212
+ parameters,
1213
+ typeAnnotation,
1214
+ readonly: opts.readonly ?? false,
1215
+ static: opts.static ?? false,
1216
+ accessibility: null,
1217
+ ...span
1218
+ };
1219
+ },
1220
+ tsTypeAliasDeclaration(id, typeAnnotation, opts = {}) {
1221
+ return {
1222
+ type: "TSTypeAliasDeclaration",
1223
+ id,
1224
+ typeParameters: opts.typeParameters ?? null,
1225
+ typeAnnotation,
1226
+ declare: opts.declare ?? false,
1227
+ ...span
1228
+ };
1229
+ },
1230
+ tsInterfaceDeclaration(id, body, opts = {}) {
1231
+ return {
1232
+ type: "TSInterfaceDeclaration",
1233
+ id,
1234
+ typeParameters: opts.typeParameters ?? null,
1235
+ extends: opts.extends ?? [],
1236
+ body,
1237
+ declare: opts.declare ?? false,
1238
+ ...span
1239
+ };
1240
+ },
1241
+ tsInterfaceBody(body) {
1242
+ return {
1243
+ type: "TSInterfaceBody",
1244
+ body,
1245
+ ...span
1246
+ };
1247
+ },
1248
+ tsInterfaceHeritage(expression, typeArguments = null) {
1249
+ return {
1250
+ type: "TSInterfaceHeritage",
1251
+ expression,
1252
+ typeArguments,
1253
+ ...span
1254
+ };
1255
+ },
1256
+ tsClassImplements(expression, typeArguments = null) {
1257
+ return {
1258
+ type: "TSClassImplements",
1259
+ expression,
1260
+ typeArguments,
1261
+ ...span
1262
+ };
1263
+ },
1264
+ tsEnumDeclaration(id, body, opts = {}) {
1265
+ return {
1266
+ type: "TSEnumDeclaration",
1267
+ id,
1268
+ body,
1269
+ const: opts.const ?? false,
1270
+ declare: opts.declare ?? false,
1271
+ ...span
1272
+ };
1273
+ },
1274
+ tsEnumBody(members) {
1275
+ return {
1276
+ type: "TSEnumBody",
1277
+ members,
1278
+ ...span
1279
+ };
1280
+ },
1281
+ tsEnumMember(id, initializer = null) {
1282
+ return {
1283
+ type: "TSEnumMember",
1284
+ id,
1285
+ initializer,
1286
+ computed: false,
1287
+ ...span
1288
+ };
1289
+ },
1290
+ tsModuleDeclaration(id, body, opts = {}) {
1291
+ return {
1292
+ type: "TSModuleDeclaration",
1293
+ id,
1294
+ body,
1295
+ kind: opts.kind ?? "module",
1296
+ declare: opts.declare ?? false,
1297
+ global: opts.global ?? false,
1298
+ ...span
1299
+ };
1300
+ },
1301
+ tsModuleBlock(body = []) {
1302
+ return {
1303
+ type: "TSModuleBlock",
1304
+ body,
1305
+ ...span
1306
+ };
1307
+ },
1308
+ tsParameterProperty(parameter, opts = {}) {
1309
+ return {
1310
+ type: "TSParameterProperty",
1311
+ decorators: opts.decorators ?? [],
1312
+ parameter,
1313
+ override: opts.override ?? false,
1314
+ readonly: opts.readonly ?? false,
1315
+ accessibility: opts.accessibility ?? null,
1316
+ static: false,
1317
+ ...span
1318
+ };
1319
+ },
1320
+ tsAsExpression(expression, typeAnnotation) {
1321
+ return {
1322
+ type: "TSAsExpression",
1323
+ expression,
1324
+ typeAnnotation,
1325
+ ...span
1326
+ };
1327
+ },
1328
+ tsSatisfiesExpression(expression, typeAnnotation) {
1329
+ return {
1330
+ type: "TSSatisfiesExpression",
1331
+ expression,
1332
+ typeAnnotation,
1333
+ ...span
1334
+ };
1335
+ },
1336
+ tsTypeAssertion(typeAnnotation, expression) {
1337
+ return {
1338
+ type: "TSTypeAssertion",
1339
+ typeAnnotation,
1340
+ expression,
1341
+ ...span
1342
+ };
1343
+ },
1344
+ tsNonNullExpression(expression) {
1345
+ return {
1346
+ type: "TSNonNullExpression",
1347
+ expression,
1348
+ ...span
1349
+ };
1350
+ },
1351
+ tsInstantiationExpression(expression, typeArguments) {
1352
+ return {
1353
+ type: "TSInstantiationExpression",
1354
+ expression,
1355
+ typeArguments,
1356
+ ...span
1357
+ };
1358
+ },
1359
+ tsExportAssignment(expression) {
1360
+ return {
1361
+ type: "TSExportAssignment",
1362
+ expression,
1363
+ ...span
1364
+ };
1365
+ },
1366
+ tsNamespaceExportDeclaration(id) {
1367
+ return {
1368
+ type: "TSNamespaceExportDeclaration",
1369
+ id,
1370
+ ...span
1371
+ };
1372
+ },
1373
+ tsImportEqualsDeclaration(id, moduleReference, importKind = "value") {
1374
+ return {
1375
+ type: "TSImportEqualsDeclaration",
1376
+ id,
1377
+ moduleReference,
1378
+ importKind,
1379
+ ...span
1380
+ };
1381
+ },
1382
+ tsExternalModuleReference(expression) {
1383
+ return {
1384
+ type: "TSExternalModuleReference",
1385
+ expression,
1386
+ ...span
1387
+ };
1388
+ },
1389
+ tsDeclareFunction(id, params, opts = {}) {
1390
+ return {
1391
+ type: "TSDeclareFunction",
1392
+ id,
1393
+ generator: opts.generator ?? false,
1394
+ async: opts.async ?? false,
1395
+ params,
1396
+ body: null,
1397
+ expression: false,
1398
+ declare: opts.declare ?? false,
1399
+ typeParameters: opts.typeParameters ?? null,
1400
+ returnType: opts.returnType ?? null,
1401
+ ...span
1402
+ };
1403
+ },
1404
+ tsEmptyBodyFunctionExpression(params, opts = {}) {
1405
+ return {
1406
+ type: "TSEmptyBodyFunctionExpression",
1407
+ id: opts.id ?? null,
1408
+ generator: false,
1409
+ async: false,
1410
+ params,
1411
+ body: null,
1412
+ expression: false,
1413
+ declare: false,
1414
+ typeParameters: opts.typeParameters ?? null,
1415
+ returnType: opts.returnType ?? null,
1416
+ ...span
1417
+ };
1418
+ },
1419
+ hashbang(value) {
1420
+ return {
1421
+ type: "Hashbang",
1422
+ value,
1423
+ ...span
1424
+ };
1425
+ },
1426
+ program(body = [], opts = {}) {
1427
+ return {
1428
+ type: "Program",
1429
+ sourceType: opts.sourceType ?? "module",
1430
+ hashbang: opts.hashbang ?? null,
1431
+ body,
1432
+ ...span
1433
+ };
1434
+ }
1435
+ };
1436
+ /**
1437
+ * Node types grouped under a shared alias. Membership is by node `type`, and
1438
+ * each group backs an alias guard such as `is.Expression` or `is.Function`.
1439
+ */
1440
+ const ALIAS_GROUPS = {
1441
+ Expression: [
1442
+ "Identifier",
1443
+ "Literal",
1444
+ "ThisExpression",
1445
+ "Super",
1446
+ "ArrayExpression",
1447
+ "ObjectExpression",
1448
+ "FunctionExpression",
1449
+ "ArrowFunctionExpression",
1450
+ "ClassExpression",
1451
+ "TaggedTemplateExpression",
1452
+ "TemplateLiteral",
1453
+ "MemberExpression",
1454
+ "CallExpression",
1455
+ "NewExpression",
1456
+ "ChainExpression",
1457
+ "SequenceExpression",
1458
+ "ParenthesizedExpression",
1459
+ "BinaryExpression",
1460
+ "LogicalExpression",
1461
+ "ConditionalExpression",
1462
+ "UnaryExpression",
1463
+ "UpdateExpression",
1464
+ "AssignmentExpression",
1465
+ "YieldExpression",
1466
+ "AwaitExpression",
1467
+ "ImportExpression",
1468
+ "MetaProperty",
1469
+ "TSAsExpression",
1470
+ "TSSatisfiesExpression",
1471
+ "TSTypeAssertion",
1472
+ "TSNonNullExpression",
1473
+ "TSInstantiationExpression",
1474
+ "JSXElement",
1475
+ "JSXFragment"
1476
+ ],
1477
+ Statement: [
1478
+ "ExpressionStatement",
1479
+ "BlockStatement",
1480
+ "EmptyStatement",
1481
+ "DebuggerStatement",
1482
+ "ReturnStatement",
1483
+ "LabeledStatement",
1484
+ "BreakStatement",
1485
+ "ContinueStatement",
1486
+ "IfStatement",
1487
+ "SwitchStatement",
1488
+ "ThrowStatement",
1489
+ "TryStatement",
1490
+ "WhileStatement",
1491
+ "DoWhileStatement",
1492
+ "ForStatement",
1493
+ "ForInStatement",
1494
+ "ForOfStatement",
1495
+ "WithStatement",
1496
+ "FunctionDeclaration",
1497
+ "ClassDeclaration",
1498
+ "VariableDeclaration",
1499
+ "TSDeclareFunction",
1500
+ "TSTypeAliasDeclaration",
1501
+ "TSInterfaceDeclaration",
1502
+ "TSEnumDeclaration",
1503
+ "TSModuleDeclaration",
1504
+ "TSImportEqualsDeclaration"
1505
+ ],
1506
+ Declaration: [
1507
+ "FunctionDeclaration",
1508
+ "ClassDeclaration",
1509
+ "VariableDeclaration",
1510
+ "TSDeclareFunction",
1511
+ "TSTypeAliasDeclaration",
1512
+ "TSInterfaceDeclaration",
1513
+ "TSEnumDeclaration",
1514
+ "TSModuleDeclaration",
1515
+ "TSImportEqualsDeclaration"
1516
+ ],
1517
+ ModuleDeclaration: [
1518
+ "ImportDeclaration",
1519
+ "ExportNamedDeclaration",
1520
+ "ExportDefaultDeclaration",
1521
+ "ExportAllDeclaration",
1522
+ "TSExportAssignment",
1523
+ "TSNamespaceExportDeclaration"
1524
+ ],
1525
+ Function: [
1526
+ "FunctionDeclaration",
1527
+ "FunctionExpression",
1528
+ "ArrowFunctionExpression",
1529
+ "TSDeclareFunction",
1530
+ "TSEmptyBodyFunctionExpression"
1531
+ ],
1532
+ Class: ["ClassDeclaration", "ClassExpression"],
1533
+ Method: ["MethodDefinition", "TSAbstractMethodDefinition"],
1534
+ Loop: [
1535
+ "ForStatement",
1536
+ "ForInStatement",
1537
+ "ForOfStatement",
1538
+ "WhileStatement",
1539
+ "DoWhileStatement"
1540
+ ],
1541
+ Pattern: [
1542
+ "Identifier",
1543
+ "ArrayPattern",
1544
+ "ObjectPattern",
1545
+ "AssignmentPattern",
1546
+ "RestElement"
1547
+ ],
1548
+ JSX: [
1549
+ "JSXElement",
1550
+ "JSXOpeningElement",
1551
+ "JSXClosingElement",
1552
+ "JSXFragment",
1553
+ "JSXOpeningFragment",
1554
+ "JSXClosingFragment",
1555
+ "JSXIdentifier",
1556
+ "JSXNamespacedName",
1557
+ "JSXMemberExpression",
1558
+ "JSXAttribute",
1559
+ "JSXSpreadAttribute",
1560
+ "JSXExpressionContainer",
1561
+ "JSXEmptyExpression",
1562
+ "JSXText",
1563
+ "JSXSpreadChild"
1564
+ ],
1565
+ TSType: [
1566
+ "TSAnyKeyword",
1567
+ "TSUnknownKeyword",
1568
+ "TSNeverKeyword",
1569
+ "TSVoidKeyword",
1570
+ "TSNullKeyword",
1571
+ "TSUndefinedKeyword",
1572
+ "TSStringKeyword",
1573
+ "TSNumberKeyword",
1574
+ "TSBigIntKeyword",
1575
+ "TSBooleanKeyword",
1576
+ "TSSymbolKeyword",
1577
+ "TSObjectKeyword",
1578
+ "TSIntrinsicKeyword",
1579
+ "TSThisType",
1580
+ "TSTypeReference",
1581
+ "TSTypeQuery",
1582
+ "TSImportType",
1583
+ "TSLiteralType",
1584
+ "TSTemplateLiteralType",
1585
+ "TSArrayType",
1586
+ "TSIndexedAccessType",
1587
+ "TSTupleType",
1588
+ "TSNamedTupleMember",
1589
+ "TSJSDocNullableType",
1590
+ "TSJSDocNonNullableType",
1591
+ "TSJSDocUnknownType",
1592
+ "TSUnionType",
1593
+ "TSIntersectionType",
1594
+ "TSConditionalType",
1595
+ "TSInferType",
1596
+ "TSTypeOperator",
1597
+ "TSParenthesizedType",
1598
+ "TSFunctionType",
1599
+ "TSConstructorType",
1600
+ "TSTypePredicate",
1601
+ "TSTypeLiteral",
1602
+ "TSMappedType"
1603
+ ]
1604
+ };
1605
+ /**
1606
+ * Every concrete node `type` in the AST. Drives the per-type guards in `is`.
1607
+ * The compile-time checks below keep it exhaustive: a node type added to or
1608
+ * removed from the parser fails to build until this list is brought in line.
1609
+ */
1610
+ const NODE_TYPES = [
1611
+ "Program",
1612
+ "Hashbang",
1613
+ "Identifier",
1614
+ "PrivateIdentifier",
1615
+ "Literal",
1616
+ "TemplateElement",
1617
+ "Super",
1618
+ "ThisExpression",
1619
+ "ArrayPattern",
1620
+ "ObjectPattern",
1621
+ "AssignmentPattern",
1622
+ "RestElement",
1623
+ "Property",
1624
+ "SequenceExpression",
1625
+ "ParenthesizedExpression",
1626
+ "BinaryExpression",
1627
+ "LogicalExpression",
1628
+ "ConditionalExpression",
1629
+ "UnaryExpression",
1630
+ "UpdateExpression",
1631
+ "AssignmentExpression",
1632
+ "YieldExpression",
1633
+ "AwaitExpression",
1634
+ "ArrayExpression",
1635
+ "ObjectExpression",
1636
+ "SpreadElement",
1637
+ "MemberExpression",
1638
+ "CallExpression",
1639
+ "ChainExpression",
1640
+ "TaggedTemplateExpression",
1641
+ "NewExpression",
1642
+ "MetaProperty",
1643
+ "ImportExpression",
1644
+ "TemplateLiteral",
1645
+ "ExpressionStatement",
1646
+ "BlockStatement",
1647
+ "IfStatement",
1648
+ "SwitchStatement",
1649
+ "SwitchCase",
1650
+ "ForStatement",
1651
+ "ForInStatement",
1652
+ "ForOfStatement",
1653
+ "WhileStatement",
1654
+ "DoWhileStatement",
1655
+ "BreakStatement",
1656
+ "ContinueStatement",
1657
+ "LabeledStatement",
1658
+ "WithStatement",
1659
+ "ReturnStatement",
1660
+ "ThrowStatement",
1661
+ "TryStatement",
1662
+ "CatchClause",
1663
+ "DebuggerStatement",
1664
+ "EmptyStatement",
1665
+ "VariableDeclaration",
1666
+ "VariableDeclarator",
1667
+ "FunctionDeclaration",
1668
+ "FunctionExpression",
1669
+ "TSDeclareFunction",
1670
+ "TSEmptyBodyFunctionExpression",
1671
+ "ArrowFunctionExpression",
1672
+ "ClassDeclaration",
1673
+ "ClassExpression",
1674
+ "ClassBody",
1675
+ "MethodDefinition",
1676
+ "TSAbstractMethodDefinition",
1677
+ "PropertyDefinition",
1678
+ "TSAbstractPropertyDefinition",
1679
+ "AccessorProperty",
1680
+ "TSAbstractAccessorProperty",
1681
+ "StaticBlock",
1682
+ "Decorator",
1683
+ "ImportDeclaration",
1684
+ "ImportSpecifier",
1685
+ "ImportDefaultSpecifier",
1686
+ "ImportNamespaceSpecifier",
1687
+ "ImportAttribute",
1688
+ "ExportNamedDeclaration",
1689
+ "ExportDefaultDeclaration",
1690
+ "ExportAllDeclaration",
1691
+ "ExportSpecifier",
1692
+ "JSXElement",
1693
+ "JSXOpeningElement",
1694
+ "JSXClosingElement",
1695
+ "JSXFragment",
1696
+ "JSXOpeningFragment",
1697
+ "JSXClosingFragment",
1698
+ "JSXIdentifier",
1699
+ "JSXNamespacedName",
1700
+ "JSXMemberExpression",
1701
+ "JSXAttribute",
1702
+ "JSXSpreadAttribute",
1703
+ "JSXExpressionContainer",
1704
+ "JSXEmptyExpression",
1705
+ "JSXText",
1706
+ "JSXSpreadChild",
1707
+ "TSTypeAnnotation",
1708
+ "TSAnyKeyword",
1709
+ "TSUnknownKeyword",
1710
+ "TSNeverKeyword",
1711
+ "TSVoidKeyword",
1712
+ "TSNullKeyword",
1713
+ "TSUndefinedKeyword",
1714
+ "TSStringKeyword",
1715
+ "TSNumberKeyword",
1716
+ "TSBigIntKeyword",
1717
+ "TSBooleanKeyword",
1718
+ "TSSymbolKeyword",
1719
+ "TSObjectKeyword",
1720
+ "TSIntrinsicKeyword",
1721
+ "TSThisType",
1722
+ "TSTypeReference",
1723
+ "TSQualifiedName",
1724
+ "TSTypeQuery",
1725
+ "TSImportType",
1726
+ "TSTypeParameter",
1727
+ "TSTypeParameterDeclaration",
1728
+ "TSTypeParameterInstantiation",
1729
+ "TSLiteralType",
1730
+ "TSTemplateLiteralType",
1731
+ "TSArrayType",
1732
+ "TSIndexedAccessType",
1733
+ "TSTupleType",
1734
+ "TSNamedTupleMember",
1735
+ "TSOptionalType",
1736
+ "TSRestType",
1737
+ "TSJSDocNullableType",
1738
+ "TSJSDocNonNullableType",
1739
+ "TSJSDocUnknownType",
1740
+ "TSUnionType",
1741
+ "TSIntersectionType",
1742
+ "TSConditionalType",
1743
+ "TSInferType",
1744
+ "TSTypeOperator",
1745
+ "TSParenthesizedType",
1746
+ "TSFunctionType",
1747
+ "TSConstructorType",
1748
+ "TSTypePredicate",
1749
+ "TSTypeLiteral",
1750
+ "TSMappedType",
1751
+ "TSPropertySignature",
1752
+ "TSMethodSignature",
1753
+ "TSCallSignatureDeclaration",
1754
+ "TSConstructSignatureDeclaration",
1755
+ "TSIndexSignature",
1756
+ "TSTypeAliasDeclaration",
1757
+ "TSInterfaceDeclaration",
1758
+ "TSInterfaceBody",
1759
+ "TSInterfaceHeritage",
1760
+ "TSClassImplements",
1761
+ "TSEnumDeclaration",
1762
+ "TSEnumBody",
1763
+ "TSEnumMember",
1764
+ "TSModuleDeclaration",
1765
+ "TSModuleBlock",
1766
+ "TSParameterProperty",
1767
+ "TSAsExpression",
1768
+ "TSSatisfiesExpression",
1769
+ "TSTypeAssertion",
1770
+ "TSNonNullExpression",
1771
+ "TSInstantiationExpression",
1772
+ "TSExportAssignment",
1773
+ "TSNamespaceExportDeclaration",
1774
+ "TSImportEqualsDeclaration",
1775
+ "TSExternalModuleReference"
1776
+ ];
1777
+ function aliasGuard(name) {
1778
+ const set = new Set(ALIAS_GROUPS[name]);
1779
+ return (node) => node != null && set.has(node.type);
1780
+ }
1781
+ const is = {
1782
+ ...Object.fromEntries(NODE_TYPES.map((type) => [type, (node) => node != null && node.type === type])),
1783
+ /** True when `node`'s `type` is one of `types`, narrowing to that union. */
1784
+ oneOf: (node, types) => node != null && types.includes(node.type),
1785
+ /** An `Identifier`, optionally with the exact `name` (e.g. `is.Identifier(node, "this")`). */
1786
+ Identifier: (node, name) => node?.type === "Identifier" && (name === void 0 || node.name === name),
1787
+ Expression: aliasGuard("Expression"),
1788
+ Statement: aliasGuard("Statement"),
1789
+ Declaration: aliasGuard("Declaration"),
1790
+ ModuleDeclaration: aliasGuard("ModuleDeclaration"),
1791
+ Function: aliasGuard("Function"),
1792
+ Class: aliasGuard("Class"),
1793
+ Method: aliasGuard("Method"),
1794
+ Loop: aliasGuard("Loop"),
1795
+ Pattern: aliasGuard("Pattern"),
1796
+ JSX: aliasGuard("JSX"),
1797
+ TSType: aliasGuard("TSType"),
1798
+ StringLiteral: (node) => node?.type === "Literal" && typeof node.value === "string",
1799
+ NumericLiteral: (node) => node?.type === "Literal" && typeof node.value === "number",
1800
+ BooleanLiteral: (node) => node?.type === "Literal" && typeof node.value === "boolean",
1801
+ NullLiteral: (node) => node?.type === "Literal" && node.raw === "null",
1802
+ BigIntLiteral: (node) => node?.type === "Literal" && "bigint" in node,
1803
+ RegExpLiteral: (node) => node?.type === "Literal" && "regex" in node,
1804
+ ComputedMemberExpression: (node) => node?.type === "MemberExpression" && node.computed,
1805
+ StaticMemberExpression: (node) => node?.type === "MemberExpression" && !node.computed && node.property.type === "Identifier",
1806
+ PrivateFieldExpression: (node) => node?.type === "MemberExpression" && node.property.type === "PrivateIdentifier",
1807
+ Directive: (node) => node?.type === "ExpressionStatement" && node.directive != null
1808
+ };
1809
+ //#endregion
1810
+ //#region ../../node_modules/.pnpm/yuku-ast@0.1.7/node_modules/yuku-ast/dist/identifier.mjs
1811
+ const IDENTIFIER_NAME = /^[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*$/u;
1812
+ /**
1813
+ * Returns `true` if `name` is a valid ECMAScript `IdentifierName`: the grammar
1814
+ * an identifier token must satisfy. Validates a raw string, not an AST node.
1815
+ *
1816
+ * @example
1817
+ * isIdentifierName("foo"); // true
1818
+ * isIdentifierName("$_0"); // true
1819
+ * isIdentifierName("π"); // true
1820
+ * isIdentifierName("class"); // true - syntactically an IdentifierName
1821
+ * isIdentifierName("1foo"); // false - starts with a digit
1822
+ * isIdentifierName("foo-bar"); // false - `-` is not an identifier character
1823
+ * isIdentifierName(""); // false
1824
+ */
1825
+ function isIdentifierName(name) {
1826
+ return IDENTIFIER_NAME.test(name);
1827
+ }
1828
+ //#endregion
1829
+ //#region ../../node_modules/.pnpm/yuku-ast@0.1.7/node_modules/yuku-ast/dist/utils.mjs
1830
+ /**
1831
+ * The static name a node denotes: an `Identifier`'s `name`, or a string
1832
+ * `Literal`'s `value`. Returns `null` for anything else, and for `null` or
1833
+ * `undefined`, so the common `Identifier | StringLiteral` name slots (a
1834
+ * `ModuleExportName`, or a static property or member key) read in one call.
1835
+ *
1836
+ * @example
1837
+ * nameOf(b.identifier("x")) // "x"
1838
+ * nameOf(b.stringLiteral("y")) // "y"
1839
+ * nameOf(b.numericLiteral(1)) // null
1840
+ */
1841
+ function nameOf(node) {
1842
+ if (node == null) return null;
1843
+ if (node.type === "Identifier") return node.name;
1844
+ if (node.type === "Literal" && typeof node.value === "string") return node.value;
1845
+ return null;
1846
+ }
1847
+ //#endregion
1848
+ //#region ../../node_modules/.pnpm/dts-resolver@3.0.0_oxc-resolver@11.21.3/node_modules/dts-resolver/dist/index.mjs
1849
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
1850
+ function createResolver({ tsconfig, cwd = process.cwd(), resolveNodeModules = false, ResolverFactory } = {}) {
1851
+ ResolverFactory ||= __require("oxc-resolver").ResolverFactory;
1852
+ const resolver = new ResolverFactory({
1853
+ mainFields: [
1854
+ "types",
1855
+ "typings",
1856
+ "module",
1857
+ "main"
1858
+ ],
1859
+ conditionNames: [
1860
+ "types",
1861
+ "typings",
1862
+ "import",
1863
+ "require"
1864
+ ],
1865
+ extensions: [
1866
+ ".d.ts",
1867
+ ".d.mts",
1868
+ ".d.cts",
1869
+ ".ts",
1870
+ ".mts",
1871
+ ".cts",
1872
+ ".tsx",
1873
+ ".js",
1874
+ ".mjs",
1875
+ ".cjs",
1876
+ ".jsx"
1877
+ ],
1878
+ extensionAlias: {
1879
+ ".js": [
1880
+ ".d.ts",
1881
+ ".ts",
1882
+ ".tsx",
1883
+ ".js",
1884
+ ".jsx"
1885
+ ],
1886
+ ".jsx": [
1887
+ ".d.ts",
1888
+ ".ts",
1889
+ ".tsx",
1890
+ ".jsx",
1891
+ ".js"
1892
+ ],
1893
+ ".mjs": [
1894
+ ".d.mts",
1895
+ ".mts",
1896
+ ".mjs"
1897
+ ],
1898
+ ".cjs": [
1899
+ ".d.cts",
1900
+ ".cts",
1901
+ ".cjs"
1902
+ ],
1903
+ ".ts": [
1904
+ ".d.ts",
1905
+ ".ts",
1906
+ ".tsx",
1907
+ ".js",
1908
+ ".jsx"
1909
+ ],
1910
+ ".tsx": [
1911
+ ".d.ts",
1912
+ ".tsx",
1913
+ ".ts",
1914
+ ".js",
1915
+ ".jsx"
1916
+ ],
1917
+ ".mts": [
1918
+ ".d.mts",
1919
+ ".mts",
1920
+ ".mjs"
1921
+ ],
1922
+ ".cts": [
1923
+ ".d.cts",
1924
+ ".cts",
1925
+ ".cjs"
1926
+ ]
1927
+ },
1928
+ modules: resolveNodeModules ? ["node_modules", "node_modules/@types"] : [],
1929
+ tsconfig: tsconfig ? {
1930
+ configFile: tsconfig,
1931
+ references: "auto"
1932
+ } : void 0
1933
+ });
1934
+ return (id, importer) => {
1935
+ const directory = importer ? dirname(importer) : cwd;
1936
+ const resolution = resolver.sync(directory, id);
1937
+ if (!resolution.path) return null;
1938
+ const resolved = resolution.path;
1939
+ return ensureValue(resolved);
1940
+ };
1941
+ }
1942
+ const ALLOW_EXTENSIONS = /* @__PURE__ */ new Set([
1943
+ ".js",
1944
+ ".cjs",
1945
+ ".mjs",
1946
+ ".jsx",
1947
+ ".ts",
1948
+ ".cts",
1949
+ ".mts",
1950
+ ".tsx",
1951
+ ".json",
1952
+ ".vue",
1953
+ ".svelte",
1954
+ ".astro"
1955
+ ]);
1956
+ function ensureValue(value) {
1957
+ return value && ALLOW_EXTENSIONS.has(extname(value)) ? value.replaceAll("\\", "/") : null;
1958
+ }
1959
+ //#endregion
1960
+ //#region ../../node_modules/.pnpm/rolldown-plugin-dts@0.27.9_@typescript+native-preview@7.0.0-dev.20260605.1_oxc-resolver_9f43f644337e3a4030148b21b794fdcf/node_modules/rolldown-plugin-dts/dist/index.mjs
1961
+ function createDtsInputPlugin({ sideEffects }) {
1962
+ return {
1963
+ name: "rolldown-plugin-dts:dts-input",
1964
+ options: sideEffects === false ? (options) => {
1965
+ return {
1966
+ treeshake: options.treeshake === false ? false : {
1967
+ ...options.treeshake === true ? {} : options.treeshake,
1968
+ moduleSideEffects: false
1969
+ },
1970
+ ...options
1971
+ };
1972
+ } : void 0,
1973
+ outputOptions(options) {
1974
+ return {
1975
+ ...options,
1976
+ entryFileNames(chunk) {
1977
+ const { entryFileNames } = options;
1978
+ if (entryFileNames) {
1979
+ const nameTemplate = resolveTemplateFn(entryFileNames, chunk);
1980
+ const renderedName = replaceTemplateName(nameTemplate, chunk.name);
1981
+ if (RE_DTS.test(renderedName)) return nameTemplate;
1982
+ const renderedNameWithD = replaceTemplateName(nameTemplate, `${chunk.name}.d`);
1983
+ if (RE_DTS.test(renderedNameWithD)) return renderedNameWithD;
1984
+ }
1985
+ if (RE_DTS.test(chunk.name)) return chunk.name;
1986
+ if (chunk.name.endsWith(".d")) return "[name].ts";
1987
+ return "[name].d.ts";
1988
+ }
1989
+ };
1990
+ }
1991
+ };
1992
+ }
1993
+ function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }) {
1994
+ let declarationIdx = 0;
1995
+ const declarationMap = /* @__PURE__ */ new Map();
1996
+ const commentsMap = /* @__PURE__ */ new Map();
1997
+ const moduleExportsMap = /* @__PURE__ */ new Map();
1998
+ const warnedCjsDtsInputs = /* @__PURE__ */ new Set();
1999
+ return {
2000
+ name: "rolldown-plugin-dts:fake-js",
2001
+ outputOptions(options) {
2002
+ if (options.format === "cjs" || options.format === "commonjs") throw new Error("[rolldown-plugin-dts] Cannot bundle dts files with `cjs` format.");
2003
+ const { chunkFileNames, entryFileNames } = options;
2004
+ return {
2005
+ ...options,
2006
+ sourcemap: options.sourcemap || sourcemap,
2007
+ chunkFileNames(chunk) {
2008
+ const nameTemplate = resolveTemplateFn(chunk.isEntry ? entryFileNames || "[name].js" : chunkFileNames || "[name]-[hash].js", chunk);
2009
+ if (chunk.name.endsWith(".d")) {
2010
+ const renderedNameWithoutD = filename_js_to_dts(replaceTemplateName(nameTemplate, chunk.name.slice(0, -2)));
2011
+ if (RE_DTS.test(renderedNameWithoutD)) return renderedNameWithoutD;
2012
+ const renderedName = filename_js_to_dts(replaceTemplateName(nameTemplate, chunk.name));
2013
+ if (RE_DTS.test(renderedName)) return renderedName;
2014
+ }
2015
+ return nameTemplate;
2016
+ }
2017
+ };
2018
+ },
2019
+ transform: {
2020
+ filter: { id: RE_DTS },
2021
+ handler: transform
2022
+ },
2023
+ renderChunk,
2024
+ generateBundle(options, bundle) {
2025
+ for (const chunk of Object.values(bundle)) {
2026
+ if (!RE_DTS_MAP.test(chunk.fileName)) continue;
2027
+ if (sourcemap) {
2028
+ if (chunk.type === "chunk" || typeof chunk.source !== "string") continue;
2029
+ const map = JSON.parse(chunk.source);
2030
+ map.sourcesContent = void 0;
2031
+ chunk.source = JSON.stringify(map);
2032
+ } else delete bundle[chunk.fileName];
2033
+ }
2034
+ }
2035
+ };
2036
+ async function transform(code, id) {
2037
+ let file;
2038
+ try {
2039
+ file = parse$1(code, {
2040
+ lang: "dts",
2041
+ sourceType: "module",
2042
+ attachComments: true
2043
+ });
2044
+ } catch (error) {
2045
+ throw new Error(`Failed to parse ${id}. This may be caused by a syntax error in the declaration file or a bug in the plugin. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts\n${error}`, { cause: error });
2046
+ }
2047
+ const { program } = file;
2048
+ moduleExportsMap.set(id, await collectModuleExports(this, program.body, id));
2049
+ const identifierMap = Object.create(null);
2050
+ if (!warnedCjsDtsInputs.has(id) && program.body.some(isCjsDtsInputSyntax)) {
2051
+ warnedCjsDtsInputs.add(id);
2052
+ this.warn(`${id} uses CommonJS dts syntax. ${RE_NODE_MODULES.test(id) ? `CommonJS dts modules cannot be bundled by rolldown-plugin-dts. Please mark this module as external in your Rolldown config.` : `rolldown-plugin-dts does not support bundling CommonJS dts input.`}`);
2053
+ }
2054
+ const directives = collectReferenceDirectives(file.comments);
2055
+ if (directives.length) commentsMap.set(id, directives);
2056
+ const appendStmts = [];
2057
+ const namespaceStmts = /* @__PURE__ */ new Map();
2058
+ for (const [i, stmt] of program.body.entries()) {
2059
+ const setStmt = (stmt) => program.body[i] = stmt;
2060
+ if (rewriteImportExport(stmt, setStmt)) continue;
2061
+ const sideEffect = stmt.type === "TSModuleDeclaration" && stmt.kind !== "namespace";
2062
+ if (sideEffect && stmt.type === "TSModuleDeclaration" && is.StringLiteral(stmt.id) && stmt.id.value[0] === ".") this.warn(`\`declare module ${JSON.stringify(stmt.id.value)}\` will be kept as-is in the output. Relative module declaration may cause unexpected issues. Found in ${id}.`);
2063
+ if (sideEffect && id.endsWith(".vue.d.ts") && code.slice(stmt.start, stmt.end).includes("__VLS_")) continue;
2064
+ const isDefaultExport = stmt.type === "ExportDefaultDeclaration";
2065
+ const isExportDecl = is.oneOf(stmt, ["ExportNamedDeclaration", "ExportDefaultDeclaration"]) && !!stmt.declaration;
2066
+ const decl = isExportDecl ? stmt.declaration : stmt;
2067
+ const setDecl = isExportDecl ? (decl) => stmt.declaration = decl : setStmt;
2068
+ if (decl.type !== "TSDeclareFunction" && !is.Declaration(decl)) continue;
2069
+ if (is.oneOf(decl, [
2070
+ "TSEnumDeclaration",
2071
+ "ClassDeclaration",
2072
+ "FunctionDeclaration",
2073
+ "TSDeclareFunction",
2074
+ "TSModuleDeclaration",
2075
+ "VariableDeclaration"
2076
+ ])) decl.declare = true;
2077
+ const bindings = [];
2078
+ if (decl.type === "VariableDeclaration") bindings.push(...decl.declarations.map((decl) => decl.id));
2079
+ else if ("id" in decl && decl.id) {
2080
+ let binding = decl.id;
2081
+ if (binding.type === "TSQualifiedName") binding = getIdFromTSEntityName(binding);
2082
+ if (sideEffect) binding = b.identifier(`_${getIdentifierIndex(identifierMap, "")}`);
2083
+ if (binding.type !== "Identifier") throw new Error(`Unexpected ${binding.type} declaration id`);
2084
+ bindings.push(binding);
2085
+ } else {
2086
+ const binding = b.identifier("export_default");
2087
+ bindings.push(binding);
2088
+ decl.id = binding;
2089
+ }
2090
+ const params = collectParams(decl);
2091
+ const childrenSet = /* @__PURE__ */ new Set();
2092
+ const deps = await collectDependencies(this, decl, id, namespaceStmts, childrenSet, identifierMap);
2093
+ const children = Array.from(childrenSet).filter((child) => bindings.every((b) => child !== b));
2094
+ if (decl !== stmt) decl.comments = stmt.comments;
2095
+ const declarationId = registerDeclaration({
2096
+ decl,
2097
+ deps,
2098
+ bindings,
2099
+ params,
2100
+ children
2101
+ });
2102
+ const declarationIdNode = b.numericLiteral(declarationId);
2103
+ const depsBody = b.arrayExpression(deps);
2104
+ const depsNode = b.arrowFunctionExpression(params.map(({ name }) => b.identifier(name)), depsBody);
2105
+ const childrenNode = b.arrayExpression(children.map((node) => {
2106
+ const placeholder = b.stringLiteral("");
2107
+ placeholder.start = node.start;
2108
+ placeholder.end = node.end;
2109
+ return placeholder;
2110
+ }));
2111
+ const sideEffectNode = sideEffect && b.callExpression(b.identifier("sideEffect"), [bindings[0]]);
2112
+ const runtimeArrayNode = runtimeBindingArrayExpression([
2113
+ declarationIdNode,
2114
+ depsNode,
2115
+ childrenNode,
2116
+ ...sideEffectNode ? [sideEffectNode] : []
2117
+ ]);
2118
+ const runtimeAssignment = b.variableDeclaration("var", [b.variableDeclarator(b.arrayPattern(bindings.map((binding) => ({
2119
+ ...binding,
2120
+ typeAnnotation: null
2121
+ }))), runtimeArrayNode)]);
2122
+ if (isDefaultExport) {
2123
+ appendStmts.push(b.exportNamedDeclaration(null, [b.exportSpecifier(bindings[0], b.identifier("default"))]));
2124
+ setStmt(runtimeAssignment);
2125
+ } else setDecl(runtimeAssignment);
2126
+ }
2127
+ if (sideEffects) appendStmts.push(b.expressionStatement(b.callExpression(b.identifier("sideEffect"), [])));
2128
+ program.body = [
2129
+ ...Array.from(namespaceStmts.values()).map(({ stmt }) => stmt),
2130
+ ...program.body,
2131
+ ...appendStmts
2132
+ ];
2133
+ const result = print(program, {
2134
+ comments: false,
2135
+ ...sourcemap && { sourceMaps: {
2136
+ source: code,
2137
+ sourceFileName: id
2138
+ } }
2139
+ });
2140
+ return {
2141
+ code: result.code,
2142
+ map: result.map ?? null
2143
+ };
2144
+ }
2145
+ function renderChunk(code, chunk) {
2146
+ if (!RE_DTS.test(chunk.fileName)) return;
2147
+ const exportInfo = collectChunkExportInfo(chunk, moduleExportsMap);
2148
+ let file;
2149
+ try {
2150
+ file = parse$1(code, {
2151
+ lang: "ts",
2152
+ sourceType: "module",
2153
+ attachComments: true
2154
+ });
2155
+ } catch (error) {
2156
+ throw new Error(`Failed to parse generated code for chunk ${chunk.fileName}. This may be caused by a bug in the plugin. Please report this issue to https://github.com/sxzz/rolldown-plugin-dts\n${error}`, { cause: error });
2157
+ }
2158
+ const { program } = file;
2159
+ program.body = patchTsNamespace(program.body);
2160
+ program.body = patchReExport(program.body);
2161
+ program.body = program.body.map((node) => {
2162
+ if (isHelperImport(node)) return null;
2163
+ if (node.type === "ExpressionStatement") return null;
2164
+ const newNode = patchImportExport(node, exportInfo, cjsDefault);
2165
+ if (newNode || newNode === false) return newNode;
2166
+ if (node.type !== "VariableDeclaration") return node;
2167
+ if (!isRuntimeBindingVariableDeclaration(node)) return null;
2168
+ const decl = node.declarations[0];
2169
+ const [declarationIdNode, depsFn, children] = decl.init.elements;
2170
+ const declarationId = declarationIdNode.value;
2171
+ const declaration = getDeclaration(declarationId);
2172
+ if (sourcemap) walk(declaration.decl, { enter(node) {
2173
+ node.start = void 0;
2174
+ node.end = void 0;
2175
+ } });
2176
+ for (const [i, id] of decl.id.elements.entries()) {
2177
+ const transformedBinding = {
2178
+ ...id,
2179
+ typeAnnotation: declaration.bindings[i].typeAnnotation
2180
+ };
2181
+ overwriteNode(declaration.bindings[i], transformedBinding);
2182
+ }
2183
+ if (sourcemap) for (const [i, child] of children.elements.entries()) Object.assign(declaration.children[i], {
2184
+ start: child.start,
2185
+ end: child.end
2186
+ });
2187
+ const transformedParams = depsFn.params;
2188
+ for (const [i, transformedParam] of transformedParams.entries()) {
2189
+ const transformedName = transformedParam.name;
2190
+ for (const originalTypeParam of declaration.params[i].typeParams) originalTypeParam.name = transformedName;
2191
+ }
2192
+ const transformedDeps = depsFn.body.elements;
2193
+ for (const [i, originalDep] of declaration.deps.entries()) {
2194
+ let transformedDep = transformedDeps[i];
2195
+ if (transformedDep.type === "UnaryExpression" && transformedDep.operator === "void") {
2196
+ const undefinedDep = b.identifier("undefined");
2197
+ undefinedDep.start = transformedDep.start;
2198
+ undefinedDep.end = transformedDep.end;
2199
+ transformedDep = undefinedDep;
2200
+ } else if (isInfer(transformedDep)) transformedDep.name = "__Infer";
2201
+ if (originalDep.replace) originalDep.replace(transformedDep);
2202
+ else Object.assign(originalDep, transformedDep);
2203
+ }
2204
+ return inheritNodeComments(node, declaration.decl);
2205
+ }).filter((node) => !!node);
2206
+ if (program.body.length === 0) return {
2207
+ code: "export { };",
2208
+ map: null
2209
+ };
2210
+ const comments = /* @__PURE__ */ new Set();
2211
+ const commentsValue = /* @__PURE__ */ new Set();
2212
+ for (const id of chunk.moduleIds) {
2213
+ const preserveComments = commentsMap.get(id);
2214
+ if (preserveComments) {
2215
+ preserveComments.forEach((c) => {
2216
+ const id = c.type + c.value;
2217
+ if (commentsValue.has(id)) return;
2218
+ commentsValue.add(id);
2219
+ comments.add(c);
2220
+ });
2221
+ commentsMap.delete(id);
2222
+ }
2223
+ }
2224
+ if (comments.size) {
2225
+ program.body[0].comments ||= [];
2226
+ program.body[0].comments.unshift(...Array.from(comments, (c) => ({
2227
+ type: c.type,
2228
+ value: c.value,
2229
+ position: "before",
2230
+ sameLine: false
2231
+ })));
2232
+ }
2233
+ const result = print(program, {
2234
+ comments: true,
2235
+ ...sourcemap && { sourceMaps: {
2236
+ source: code,
2237
+ sourceFileName: chunk.fileName
2238
+ } }
2239
+ });
2240
+ return {
2241
+ code: result.code,
2242
+ map: result.map ?? null
2243
+ };
2244
+ }
2245
+ function registerDeclaration(info) {
2246
+ const declarationId = declarationIdx++;
2247
+ declarationMap.set(declarationId, info);
2248
+ return declarationId;
2249
+ }
2250
+ function getDeclaration(declarationId) {
2251
+ return declarationMap.get(declarationId);
2252
+ }
2253
+ }
2254
+ async function collectModuleExports(context, nodes, id) {
2255
+ const info = {
2256
+ typeOnlyLocals: /* @__PURE__ */ new Set(),
2257
+ exports: /* @__PURE__ */ new Map(),
2258
+ reExports: [],
2259
+ exportAlls: []
2260
+ };
2261
+ for (const node of nodes) collectTypeOnlyLocals(node, info.typeOnlyLocals);
2262
+ for (const node of nodes) await collectExportInfo(context, node, id, info);
2263
+ return info;
2264
+ }
2265
+ function collectTypeOnlyLocals(node, typeOnlyLocals) {
2266
+ if (node.type !== "ImportDeclaration") return;
2267
+ for (const specifier of node.specifiers) if (node.importKind === "type" || "importKind" in specifier && specifier.importKind === "type") typeOnlyLocals.add(specifier.local.name);
2268
+ }
2269
+ function collectDeclarationNames(node) {
2270
+ if (node.type === "VariableDeclaration") return node.declarations.flatMap((decl) => collectPatternNames(decl.id));
2271
+ if ("id" in node && node.id) {
2272
+ if (node.id.type !== "Identifier" && node.id.type !== "TSQualifiedName") return [];
2273
+ const id = getIdFromTSEntityName(node.id);
2274
+ return id.type === "Identifier" ? [id.name] : [];
2275
+ }
2276
+ return [];
2277
+ }
2278
+ function collectPatternNames(node) {
2279
+ if (!node) return [];
2280
+ if (node.type === "Identifier") return [node.name];
2281
+ if (node.type === "RestElement") return collectPatternNames(node.argument);
2282
+ if (node.type === "AssignmentPattern") return collectPatternNames(node.left);
2283
+ if (node.type === "ArrayPattern") return node.elements.flatMap((element) => collectPatternNames(element));
2284
+ if (node.type === "ObjectPattern") return node.properties.flatMap((property) => {
2285
+ if (property.type === "RestElement") return collectPatternNames(property.argument);
2286
+ return collectPatternNames(property.value);
2287
+ });
2288
+ return [];
2289
+ }
2290
+ function isTypeOnlyExport(node, specifier) {
2291
+ return node.exportKind === "type" || specifier.exportKind === "type";
2292
+ }
2293
+ async function collectExportInfo(context, node, id, info) {
2294
+ if (node.type === "ExportNamedDeclaration") {
2295
+ if (node.declaration) {
2296
+ for (const name of collectDeclarationNames(node.declaration)) info.exports.set(name, false);
2297
+ return;
2298
+ }
2299
+ const source = await resolveExportSource(context, node.source, id);
2300
+ for (const specifier of node.specifiers) {
2301
+ const typeOnly = isTypeOnlyExport(node, specifier);
2302
+ const exported = nameOf(specifier.exported);
2303
+ const local = nameOf(specifier.local);
2304
+ if (source) info.reExports.push({
2305
+ source,
2306
+ local,
2307
+ exported,
2308
+ typeOnly
2309
+ });
2310
+ else info.exports.set(exported, typeOnly || info.typeOnlyLocals.has(local));
2311
+ }
2312
+ return;
2313
+ }
2314
+ if (node.type === "ExportDefaultDeclaration") {
2315
+ info.exports.set("default", false);
2316
+ return;
2317
+ }
2318
+ if (node.type === "ExportAllDeclaration") {
2319
+ if (node.exported) {
2320
+ info.exports.set(nameOf(node.exported), node.exportKind === "type");
2321
+ return;
2322
+ }
2323
+ info.exportAlls.push({
2324
+ source: await resolveExportSource(context, node.source, id),
2325
+ rawSource: node.source.value,
2326
+ typeOnly: node.exportKind === "type"
2327
+ });
2328
+ }
2329
+ }
2330
+ async function resolveExportSource(context, source, importer) {
2331
+ if (!source) return;
2332
+ const resolved = await context.resolve(source.value, importer);
2333
+ if (!resolved || resolved.external) return;
2334
+ return resolved.id;
2335
+ }
2336
+ function collectChunkExportInfo(chunk, moduleExportsMap) {
2337
+ const exportsByModule = resolveAllModuleExports(moduleExportsMap);
2338
+ const roots = chunk.facadeModuleId && moduleExportsMap.has(chunk.facadeModuleId) ? [chunk.facadeModuleId] : chunk.moduleIds;
2339
+ const mergedExports = /* @__PURE__ */ new Map();
2340
+ const typeOnlyExportAllSources = /* @__PURE__ */ new Set();
2341
+ for (const root of roots) {
2342
+ const exports = exportsByModule.get(root);
2343
+ if (exports) for (const [name, typeOnly] of exports) setExportTypeOnly(mergedExports, name, typeOnly);
2344
+ const moduleExports = moduleExportsMap.get(root);
2345
+ if (!moduleExports) continue;
2346
+ for (const exportAll of moduleExports.exportAlls) {
2347
+ if (!exportAll.typeOnly || exportAll.source) continue;
2348
+ typeOnlyExportAllSources.add(exportAll.rawSource);
2349
+ }
2350
+ }
2351
+ const typeOnlyNames = /* @__PURE__ */ new Set();
2352
+ for (const [name, typeOnly] of mergedExports) if (typeOnly) typeOnlyNames.add(name);
2353
+ return {
2354
+ typeOnlyNames,
2355
+ typeOnlyExportAllSources
2356
+ };
2357
+ }
2358
+ function resolveAllModuleExports(moduleExportsMap) {
2359
+ const exportsByModule = /* @__PURE__ */ new Map();
2360
+ for (const [id, info] of moduleExportsMap) exportsByModule.set(id, new Map(info.exports));
2361
+ let changed = true;
2362
+ while (changed) {
2363
+ changed = false;
2364
+ for (const [id, info] of moduleExportsMap) {
2365
+ const exports = exportsByModule.get(id);
2366
+ for (const reExport of info.reExports) {
2367
+ const sourceTypeOnly = (reExport.source ? exportsByModule.get(reExport.source) : void 0)?.get(reExport.local) ?? false;
2368
+ if (setExportTypeOnly(exports, reExport.exported, reExport.typeOnly || sourceTypeOnly)) changed = true;
2369
+ }
2370
+ for (const exportAll of info.exportAlls) {
2371
+ if (!exportAll.source) continue;
2372
+ const sourceExports = exportsByModule.get(exportAll.source);
2373
+ if (!sourceExports) continue;
2374
+ for (const [name, typeOnly] of sourceExports) {
2375
+ if (name === "default") continue;
2376
+ if (setExportTypeOnly(exports, name, exportAll.typeOnly || typeOnly)) changed = true;
2377
+ }
2378
+ }
2379
+ }
2380
+ }
2381
+ return exportsByModule;
2382
+ }
2383
+ function setExportTypeOnly(exports, name, typeOnly) {
2384
+ const current = exports.get(name);
2385
+ if (current === false || current === typeOnly) return false;
2386
+ if (current === void 0 || !typeOnly) {
2387
+ exports.set(name, typeOnly);
2388
+ return true;
2389
+ }
2390
+ return false;
2391
+ }
2392
+ /**
2393
+ * Collects all TSTypeParameter nodes from the given node and groups them by
2394
+ * their name. One name can associate with one or more type parameters. These
2395
+ * names will be used as the parameter name in the generated JavaScript
2396
+ * dependency function.
2397
+ */
2398
+ function collectParams(node) {
2399
+ const typeParams = [];
2400
+ walk(node, { leave(node) {
2401
+ if ("typeParameters" in node && node.typeParameters?.type === "TSTypeParameterDeclaration") typeParams.push(...node.typeParameters.params.map(({ name }) => name));
2402
+ } });
2403
+ const paramMap = /* @__PURE__ */ new Map();
2404
+ for (const typeParam of typeParams) {
2405
+ const name = typeParam.name;
2406
+ const group = paramMap.get(name);
2407
+ if (group) group.push(typeParam);
2408
+ else paramMap.set(name, [typeParam]);
2409
+ }
2410
+ return Array.from(paramMap.entries()).map(([name, typeParams]) => ({
2411
+ name,
2412
+ typeParams
2413
+ }));
2414
+ }
2415
+ async function collectDependencies(context, node, importer, namespaceStmts, children, identifierMap) {
2416
+ const deps = /* @__PURE__ */ new Set();
2417
+ const seen = /* @__PURE__ */ new Set();
2418
+ const preserveImportTypeCache = /* @__PURE__ */ new Map();
2419
+ const importSources = /* @__PURE__ */ new Set();
2420
+ walk(node, { TSImportType(node) {
2421
+ importSources.add(node.source.value);
2422
+ } });
2423
+ if (importSources.size) await Promise.all(Array.from(importSources, async (source) => {
2424
+ const resolved = await context.resolve(source, importer);
2425
+ preserveImportTypeCache.set(source, !resolved || !!resolved.external);
2426
+ }));
2427
+ const inferredStack = [];
2428
+ let currentInferred = /* @__PURE__ */ new Set();
2429
+ function isInferred(node) {
2430
+ return node.type === "Identifier" && currentInferred.has(node.name);
2431
+ }
2432
+ walk(node, {
2433
+ enter(node) {
2434
+ if (node.type === "TSConditionalType") {
2435
+ const inferred = collectInferredNames(node.extendsType);
2436
+ inferredStack.push(inferred);
2437
+ }
2438
+ },
2439
+ leave(node, path) {
2440
+ const { parent } = path;
2441
+ if (node.type === "TSConditionalType") inferredStack.pop();
2442
+ else if (parent?.type === "TSConditionalType") {
2443
+ const trueBranch = parent.trueType === node;
2444
+ currentInferred = new Set((trueBranch ? inferredStack : inferredStack.slice(0, -1)).flat());
2445
+ } else currentInferred = /* @__PURE__ */ new Set();
2446
+ if (node.type === "ExportNamedDeclaration") {
2447
+ for (const specifier of node.specifiers) if (specifier.type === "ExportSpecifier") addDependency(specifier.local);
2448
+ } else if (node.type === "TSInterfaceDeclaration" && node.extends) for (const heritage of node.extends || []) addDependency(heritage.expression);
2449
+ else if (node.type === "ClassDeclaration") {
2450
+ if (node.superClass) addDependency(node.superClass);
2451
+ if (node.implements) for (const implement of node.implements) addDependency(implement.expression);
2452
+ } else if (is.oneOf(node, [
2453
+ "Property",
2454
+ "PropertyDefinition",
2455
+ "TSAbstractPropertyDefinition",
2456
+ "MethodDefinition",
2457
+ "TSAbstractMethodDefinition",
2458
+ "TSPropertySignature",
2459
+ "TSMethodSignature"
2460
+ ])) {
2461
+ if (node.computed && isReferenceId(node.key)) addDependency(node.key);
2462
+ if ("value" in node && isReferenceId(node.value)) addDependency(node.value);
2463
+ } else switch (node.type) {
2464
+ case "TSTypeReference":
2465
+ addDependency(TSEntityNameToRuntime(node.typeName));
2466
+ break;
2467
+ case "TSTypeQuery":
2468
+ if (seen.has(node.exprName)) return;
2469
+ if (node.exprName.type === "TSImportType") break;
2470
+ addDependency(TSEntityNameToRuntime(node.exprName));
2471
+ break;
2472
+ case "TSImportType": {
2473
+ seen.add(node);
2474
+ const { source, qualifier } = node;
2475
+ const dep = importNamespace(node, qualifier, source, namespaceStmts, identifierMap, preserveImportTypeCache);
2476
+ if (dep) addDependency(dep);
2477
+ break;
2478
+ }
2479
+ }
2480
+ if (parent && !deps.has(node) && isChildSymbol(node, parent)) children.add(node);
2481
+ }
2482
+ });
2483
+ return Array.from(deps);
2484
+ function addDependency(node) {
2485
+ if (isThisExpression(node) || isInferred(node)) return;
2486
+ deps.add(node);
2487
+ }
2488
+ }
2489
+ function importNamespace(node, imported, source, namespaceStmts, identifierMap, preserveCache) {
2490
+ if (preserveCache.get(source.value) ?? true) return;
2491
+ const sourceText = source.value.replaceAll(/\W/g, "_");
2492
+ const localName = `_$${isIdentifierName(source.value) ? source.value : `${sourceText}${getIdentifierIndex(identifierMap, sourceText)}`}`;
2493
+ let local = b.identifier(localName);
2494
+ if (namespaceStmts.has(source.value)) local = namespaceStmts.get(source.value).local;
2495
+ else namespaceStmts.set(source.value, {
2496
+ stmt: b.importDeclaration([b.importNamespaceSpecifier(local)], source),
2497
+ local
2498
+ });
2499
+ if (imported) {
2500
+ const importedLeft = getIdFromTSEntityName(imported);
2501
+ if (imported.type === "ThisExpression" || importedLeft.type === "ThisExpression") throw new Error("Cannot import `this` from module.");
2502
+ overwriteNode(importedLeft, b.tsQualifiedName(local, { ...importedLeft }));
2503
+ local = imported;
2504
+ }
2505
+ let replacement = node;
2506
+ if (node.typeArguments) {
2507
+ overwriteNode(node, b.tsTypeReference(local, node.typeArguments));
2508
+ replacement = local;
2509
+ } else overwriteNode(node, local);
2510
+ return {
2511
+ ...TSEntityNameToRuntime(local),
2512
+ replace(newNode) {
2513
+ overwriteNode(replacement, newNode);
2514
+ }
2515
+ };
2516
+ }
2517
+ function isChildSymbol(node, parent) {
2518
+ if (node.type === "Identifier") return true;
2519
+ if (is.oneOf(parent, ["TSPropertySignature", "TSMethodSignature"]) && parent.key === node) return true;
2520
+ return false;
2521
+ }
2522
+ function collectInferredNames(node) {
2523
+ const inferred = [];
2524
+ walk(node, { enter(node) {
2525
+ if (node.type === "TSInferType" && node.typeParameter) inferred.push(node.typeParameter.name.name);
2526
+ } });
2527
+ return inferred;
2528
+ }
2529
+ const REFERENCE_RE = /\/\s*<reference\s+(?:path|types)=/;
2530
+ function collectReferenceDirectives(comment, negative = false) {
2531
+ return comment.filter((c) => REFERENCE_RE.test(c.value) !== negative);
2532
+ }
2533
+ const SOURCE_MAP_PRAGMA_RE = /^#\s*source(?:Mapping)?URL=/;
2534
+ function isSourceMapPragma(comment) {
2535
+ return SOURCE_MAP_PRAGMA_RE.test(comment.value);
2536
+ }
2537
+ function isCjsDtsInputSyntax(node) {
2538
+ return node.type === "TSExportAssignment" || node.type === "TSImportEqualsDeclaration" && node.moduleReference.type === "TSExternalModuleReference";
2539
+ }
2540
+ /**
2541
+ * Check if the given node is a {@link RuntimeBindingVariableDeclration}
2542
+ */
2543
+ function isRuntimeBindingVariableDeclaration(node) {
2544
+ return node?.type === "VariableDeclaration" && node.declarations.length === 1 && node.declarations[0].type === "VariableDeclarator" && node.declarations[0].id.type === "ArrayPattern" && isRuntimeBindingArrayExpression(node.declarations[0].init);
2545
+ }
2546
+ /**
2547
+ * Check if the given node is a {@link RuntimeBindingArrayExpression}
2548
+ */
2549
+ function isRuntimeBindingArrayExpression(node) {
2550
+ return node?.type === "ArrayExpression" && isRuntimeBindingArrayElements(node.elements);
2551
+ }
2552
+ /**
2553
+ * Check if the given array is a {@link RuntimeBindingArrayElements}
2554
+ */
2555
+ function isRuntimeBindingArrayElements(elements) {
2556
+ const [declarationId, deps, children, effect] = elements;
2557
+ return is.NumericLiteral(declarationId) && deps?.type === "ArrowFunctionExpression" && children?.type === "ArrayExpression" && (!effect || effect.type === "CallExpression");
2558
+ }
2559
+ function runtimeBindingArrayExpression(elements) {
2560
+ return b.arrayExpression([...elements]);
2561
+ }
2562
+ function isThisExpression(node) {
2563
+ return is.Identifier(node, "this") || node.type === "ThisExpression" || node.type === "MemberExpression" && isThisExpression(node.object);
2564
+ }
2565
+ function isInfer(node) {
2566
+ return is.Identifier(node, "infer");
2567
+ }
2568
+ function TSEntityNameToRuntime(node) {
2569
+ if (node.type === "Identifier" || node.type === "ThisExpression") return node;
2570
+ const left = TSEntityNameToRuntime(node.left);
2571
+ return Object.assign(node, {
2572
+ type: "MemberExpression",
2573
+ object: left,
2574
+ property: node.right,
2575
+ computed: false
2576
+ });
2577
+ }
2578
+ function getIdFromTSEntityName(node) {
2579
+ if (node.type === "Identifier" || node.type === "ThisExpression") return node;
2580
+ return getIdFromTSEntityName(node.left);
2581
+ }
2582
+ function isReferenceId(node) {
2583
+ return is.oneOf(node, ["Identifier", "MemberExpression"]);
2584
+ }
2585
+ function isHelperImport(node) {
2586
+ return node.type === "ImportDeclaration" && node.specifiers.length && node.specifiers.every((spec) => spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && ["__exportAll", "__reExport"].includes(spec.local.name));
2587
+ }
2588
+ /**
2589
+ * patch `.d.ts` suffix in import source to `.js`
2590
+ */
2591
+ function patchImportExport(node, exportInfo, cjsDefault) {
2592
+ if (node.type === "ExportNamedDeclaration" && !node.declaration && !node.source && !node.specifiers.length && !node.attributes?.length) return false;
2593
+ if (node.type === "ImportDeclaration" && node.specifiers.length) {
2594
+ for (const specifier of node.specifiers) if (isInfer(specifier.local)) specifier.local.name = "__Infer";
2595
+ }
2596
+ if (is.oneOf(node, [
2597
+ "ImportDeclaration",
2598
+ "ExportAllDeclaration",
2599
+ "ExportNamedDeclaration"
2600
+ ])) {
2601
+ if (node.type === "ExportAllDeclaration" && node.source && exportInfo.typeOnlyExportAllSources.has(node.source.value)) node.exportKind = "type";
2602
+ if (node.type === "ExportNamedDeclaration" && exportInfo.typeOnlyNames.size) {
2603
+ for (const spec of node.specifiers) {
2604
+ const name = nameOf(spec.exported);
2605
+ if (exportInfo.typeOnlyNames.has(name)) if (spec.type === "ExportSpecifier") spec.exportKind = "type";
2606
+ else node.exportKind = "type";
2607
+ }
2608
+ normalizeTypeOnlyExport(node);
2609
+ }
2610
+ if (node.source?.value && RE_DTS.test(node.source.value)) {
2611
+ node.source.value = filename_dts_to(node.source.value, "js");
2612
+ return node;
2613
+ }
2614
+ if (cjsDefault && node.type === "ExportNamedDeclaration" && !node.source && node.specifiers.length === 1 && node.specifiers[0].type === "ExportSpecifier" && nameOf(node.specifiers[0].exported) === "default") {
2615
+ const defaultExport = node.specifiers[0];
2616
+ return b.tsExportAssignment(defaultExport.local);
2617
+ }
2618
+ }
2619
+ }
2620
+ function normalizeTypeOnlyExport(node) {
2621
+ if (node.declaration || !node.specifiers.length) return;
2622
+ for (const specifier of node.specifiers) if (specifier.type !== "ExportSpecifier" || specifier.exportKind !== "type") return;
2623
+ node.exportKind = "type";
2624
+ for (const specifier of node.specifiers) if (specifier.type === "ExportSpecifier") specifier.exportKind = "value";
2625
+ }
2626
+ /**
2627
+ * Handle `__exportAll` call
2628
+ */
2629
+ function patchTsNamespace(nodes) {
2630
+ const removed = /* @__PURE__ */ new Set();
2631
+ for (const [i, node] of nodes.entries()) {
2632
+ const result = getExportAllNamespace(node);
2633
+ if (!result) continue;
2634
+ const [binding, exports] = result;
2635
+ if (!exports.properties.length) continue;
2636
+ const namespaceExport = b.exportNamedDeclaration(null, exports.properties.filter((property) => property.type === "Property").map((property) => {
2637
+ const local = property.value.body;
2638
+ const exported = property.key;
2639
+ return b.exportSpecifier(local, exported);
2640
+ }));
2641
+ nodes[i] = b.tsModuleDeclaration(binding, b.tsModuleBlock([namespaceExport]), {
2642
+ kind: "namespace",
2643
+ declare: true
2644
+ });
2645
+ }
2646
+ return nodes.filter((node) => !removed.has(node));
2647
+ }
2648
+ function getExportAllNamespace(node) {
2649
+ if (node.type !== "VariableDeclaration" || node.declarations.length !== 1 || node.declarations[0].id.type !== "Identifier" || node.declarations[0].init?.type !== "CallExpression" || node.declarations[0].init.callee.type !== "Identifier" || node.declarations[0].init.callee.name !== "__exportAll" || node.declarations[0].init.arguments.length !== 1 || node.declarations[0].init.arguments[0].type !== "ObjectExpression") return false;
2650
+ return [node.declarations[0].id, node.declarations[0].init.arguments[0]];
2651
+ }
2652
+ /**
2653
+ * Handle `__reExport` call
2654
+ */
2655
+ function patchReExport(nodes) {
2656
+ const exportsNames = /* @__PURE__ */ new Map();
2657
+ for (const [i, node] of nodes.entries()) if (node.type === "ImportDeclaration" && node.specifiers.length === 1 && node.specifiers[0].type === "ImportSpecifier" && node.specifiers[0].local.type === "Identifier" && node.specifiers[0].local.name.endsWith("_exports")) exportsNames.set(node.specifiers[0].local.name, node.specifiers[0].local.name);
2658
+ else if (node.type === "ExpressionStatement" && node.expression.type === "CallExpression" && is.Identifier(node.expression.callee, "__reExport")) {
2659
+ const args = node.expression.arguments;
2660
+ exportsNames.set(args[0].name, args[1].name);
2661
+ } else if (node.type === "VariableDeclaration" && node.declarations.length === 1 && node.declarations[0].init?.type === "MemberExpression" && node.declarations[0].init.object.type === "Identifier" && exportsNames.has(node.declarations[0].init.object.name)) nodes[i] = b.tsTypeAliasDeclaration(b.identifier(node.declarations[0].id.name), b.tsTypeReference(b.tsQualifiedName(b.identifier(exportsNames.get(node.declarations[0].init.object.name)), b.identifier(node.declarations[0].init.property.name))));
2662
+ else if (node.type === "ExportNamedDeclaration" && node.specifiers.length === 1 && node.specifiers[0].type === "ExportSpecifier" && node.specifiers[0].local.type === "Identifier" && exportsNames.has(node.specifiers[0].local.name)) node.specifiers[0].local.name = exportsNames.get(node.specifiers[0].local.name);
2663
+ return nodes;
2664
+ }
2665
+ function rewriteImportExport(node, set) {
2666
+ if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" && !node.declaration) {
2667
+ for (const specifier of node.specifiers) if (specifier.type === "ImportSpecifier") specifier.importKind = "value";
2668
+ else if (specifier.type === "ExportSpecifier") specifier.exportKind = "value";
2669
+ if (node.type === "ImportDeclaration") node.importKind = "value";
2670
+ else if (node.type === "ExportNamedDeclaration") node.exportKind = "value";
2671
+ return true;
2672
+ } else if (node.type === "ExportAllDeclaration") {
2673
+ node.exportKind = "value";
2674
+ return true;
2675
+ } else if (node.type === "TSImportEqualsDeclaration") {
2676
+ if (node.moduleReference.type === "TSExternalModuleReference") set(b.importDeclaration([b.importDefaultSpecifier(node.id)], node.moduleReference.expression));
2677
+ return true;
2678
+ } else if (node.type === "TSExportAssignment" && node.expression.type === "Identifier") {
2679
+ set(b.exportNamedDeclaration(null, [b.exportSpecifier(node.expression, b.identifier("default"))]));
2680
+ return true;
2681
+ } else if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "Identifier") {
2682
+ set(b.exportNamedDeclaration(null, [b.exportSpecifier(node.declaration, b.identifier("default"))]));
2683
+ return true;
2684
+ }
2685
+ return false;
2686
+ }
2687
+ function overwriteNode(node, newNode) {
2688
+ for (const key of Object.keys(node)) Reflect.deleteProperty(node, key);
2689
+ Object.assign(node, newNode);
2690
+ return node;
2691
+ }
2692
+ function inheritNodeComments(oldNode, newNode) {
2693
+ newNode.comments ||= [];
2694
+ const pragmas = oldNode.comments?.filter((comment) => comment.position === "before" && comment.value.startsWith("#") && !isSourceMapPragma(comment));
2695
+ if (pragmas) newNode.comments.unshift(...pragmas);
2696
+ newNode.comments = newNode.comments.filter((comment) => !REFERENCE_RE.test(comment.value) && !isSourceMapPragma(comment));
2697
+ return newNode;
2698
+ }
2699
+ function getIdentifierIndex(identifierMap, name) {
2700
+ if (name in identifierMap) return ++identifierMap[name];
2701
+ return identifierMap[name] = 0;
2702
+ }
2703
+ const require$1 = createRequire(import.meta.url);
2704
+ const debug$4 = createDebug("rolldown-plugin-dts:tsgo");
2705
+ function isTS70Installed() {
2706
+ try {
2707
+ const { versionMajorMinor } = require$1("typescript");
2708
+ return versionMajorMinor === "7.0";
2709
+ } catch {}
2710
+ return false;
2711
+ }
2712
+ const spawnAsync = (...args) => new Promise((resolve, reject) => {
2713
+ const child = spawn(...args);
2714
+ child.on("close", () => resolve());
2715
+ child.on("error", (error) => reject(error));
2716
+ });
2717
+ let tsgoPathCache;
2718
+ async function getTsgoPathFromNodeModules(logger) {
2719
+ if (tsgoPathCache) return tsgoPathCache;
2720
+ const pkgName = isTS70Installed() ? "typescript" : "@typescript/native-preview";
2721
+ const tsgoPkg = import.meta.resolve(`${pkgName}/package.json`);
2722
+ const { default: { version } } = await import(tsgoPkg, { with: { type: "json" } });
2723
+ logger.info(`Emit types with ${styleText("underline", `${pkgName}@${version}`)}`);
2724
+ const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPkg).href);
2725
+ return tsgoPathCache = getExePath();
2726
+ }
2727
+ async function runTsgo(logger, rootDir, tsconfig, sourcemap, tsgoPath) {
2728
+ debug$4("[tsgo] rootDir", rootDir);
2729
+ let tsgo;
2730
+ if (tsgoPath) {
2731
+ tsgo = tsgoPath;
2732
+ debug$4("[tsgo] using custom path", tsgo);
2733
+ } else {
2734
+ tsgo = await getTsgoPathFromNodeModules(logger);
2735
+ debug$4("[tsgo] using tsgo from node_modules", tsgo);
2736
+ }
2737
+ const tsgoDist = await mkdtemp(path.join(tmpdir(), "rolldown-plugin-dts-"));
2738
+ debug$4("[tsgo] tsgoDist", tsgoDist);
2739
+ const args = [
2740
+ "--noEmit",
2741
+ "false",
2742
+ "--declaration",
2743
+ "--emitDeclarationOnly",
2744
+ "-p",
2745
+ tsconfig,
2746
+ "--outDir",
2747
+ tsgoDist,
2748
+ "--rootDir",
2749
+ rootDir,
2750
+ "--noCheck",
2751
+ ...sourcemap ? ["--declarationMap"] : []
2752
+ ];
2753
+ debug$4("[tsgo] args %o", args);
2754
+ await spawnAsync(tsgo, args, { stdio: "inherit" });
2755
+ return {
2756
+ path: tsgoDist,
2757
+ async dispose() {
2758
+ if (debug$4.enabled) debug$4("[tsgo] skip cleanup of tsgoDist", tsgoDist);
2759
+ else {
2760
+ debug$4("[tsgo] disposing tsgoDist", tsgoDist);
2761
+ await rm(tsgoDist, {
2762
+ recursive: true,
2763
+ force: true
2764
+ }).catch(() => {});
2765
+ }
2766
+ }
2767
+ };
2768
+ }
2769
+ const debug$3 = createDebug("rolldown-plugin-dts:generate");
2770
+ const WORKER_URL = "./tsc-worker.mjs";
2771
+ function createGeneratePlugin({ generator, entry, tsconfig, tsconfigRaw, build, incremental, cwd, oxc, emitDtsOnly, vue, tsMacro, parallel, eager, tsgo, newContext, emitJs, sourcemap, logger }) {
2772
+ const entryIncludes = entry?.filter((p) => p[0] !== "!");
2773
+ const entryIgnores = entry?.filter((p) => p[0] === "!").map((p) => p.slice(1));
2774
+ const entryMatcher = entry ? (file) => entryIncludes.some((p) => path.matchesGlob(file, p)) && !entryIgnores.some((p) => path.matchesGlob(file, p)) : void 0;
2775
+ const dtsMap = /* @__PURE__ */ new Map();
2776
+ /**
2777
+ * A map of input id to output file name
2778
+ *
2779
+ * @example
2780
+ *
2781
+ * inputAlias = new Map([
2782
+ * ['/absolute/path/to/src/source_file.ts', 'dist/foo/index'],
2783
+ * ])
2784
+ */
2785
+ const inputAliasMap = /* @__PURE__ */ new Map();
2786
+ let tscWorker;
2787
+ let tscModule;
2788
+ let tscContext;
2789
+ let tsgoContext;
2790
+ const rootDir = tsconfig ? path.dirname(tsconfig) : cwd;
2791
+ return {
2792
+ name: "rolldown-plugin-dts:generate",
2793
+ async buildStart(options) {
2794
+ if (generator === "tsgo") tsgoContext = await runTsgo(logger, rootDir, tsconfig, sourcemap, tsgo.path);
2795
+ else if (generator === "tsc") if (parallel) tscWorker = createTscWorker();
2796
+ else {
2797
+ tscModule = await import("./tsc-CilQvmj4.js");
2798
+ if (newContext) tscContext = createContext();
2799
+ }
2800
+ if (!Array.isArray(options.input)) for (const [name, id] of Object.entries(options.input)) {
2801
+ debug$3("resolving input alias %s -> %s", name, id);
2802
+ let resolved = await this.resolve(id);
2803
+ if (!id.startsWith("./")) resolved ||= await this.resolve(`./${id}`);
2804
+ const resolvedId = resolved?.id || id;
2805
+ debug$3("resolved input alias %s -> %s", id, resolvedId);
2806
+ inputAliasMap.set(resolvedId, name);
2807
+ }
2808
+ },
2809
+ outputOptions(options) {
2810
+ return {
2811
+ ...options,
2812
+ entryFileNames(chunk) {
2813
+ const { entryFileNames } = options;
2814
+ const nameTemplate = resolveTemplateFn(entryFileNames || "[name].js", chunk);
2815
+ if (chunk.name.endsWith(".d")) {
2816
+ if (RE_DTS.test(nameTemplate)) return replaceTemplateName(nameTemplate, chunk.name.slice(0, -2));
2817
+ if (RE_JS.test(nameTemplate)) return nameTemplate.replace(RE_JS, ".$1ts");
2818
+ }
2819
+ return nameTemplate;
2820
+ }
2821
+ };
2822
+ },
2823
+ resolveId(id) {
2824
+ if (dtsMap.has(id)) {
2825
+ debug$3("resolve dts id %s", id);
2826
+ return { id };
2827
+ }
2828
+ },
2829
+ transform: {
2830
+ order: "pre",
2831
+ filter: { id: {
2832
+ include: [
2833
+ RE_JS,
2834
+ RE_TS,
2835
+ RE_VUE,
2836
+ RE_JSON
2837
+ ],
2838
+ exclude: [
2839
+ RE_DTS,
2840
+ RE_NODE_MODULES,
2841
+ RE_ROLLDOWN_RUNTIME
2842
+ ]
2843
+ } },
2844
+ handler(code, id) {
2845
+ const jsFile = RE_JS.test(id);
2846
+ if (!jsFile || emitJs) {
2847
+ const mod = this.getModuleInfo(id);
2848
+ const isEntry = entryMatcher ? entryMatcher(path.relative(cwd, id)) : !!mod?.isEntry;
2849
+ const dtsId = filename_to_dts(id);
2850
+ dtsMap.set(dtsId, {
2851
+ code,
2852
+ id,
2853
+ isEntry,
2854
+ jsFile
2855
+ });
2856
+ debug$3("register dts source: %s", id);
2857
+ if (isEntry) {
2858
+ const name = inputAliasMap.get(id);
2859
+ this.emitFile({
2860
+ type: "chunk",
2861
+ id: dtsId,
2862
+ name: name ? `${name}.d` : void 0
2863
+ });
2864
+ }
2865
+ }
2866
+ if (emitDtsOnly) {
2867
+ if (RE_JSON.test(id)) return "{}";
2868
+ return "export { }";
2869
+ }
2870
+ }
2871
+ },
2872
+ load: {
2873
+ filter: { id: {
2874
+ include: [RE_DTS],
2875
+ exclude: [RE_NODE_MODULES]
2876
+ } },
2877
+ async handler(dtsId) {
2878
+ const module = dtsMap.get(dtsId);
2879
+ if (!module) return;
2880
+ const { code, id, jsFile } = module;
2881
+ if (jsFile && await access(dtsId).then(() => true).catch(() => false)) {
2882
+ debug$3("dts file already exists for %s, skipping generation", id);
2883
+ return;
2884
+ }
2885
+ let dtsCode;
2886
+ let map;
2887
+ debug$3("generate dts %s from %s", dtsId, id);
2888
+ if (generator === "tsgo") {
2889
+ if (RE_VUE.test(id)) throw new Error("tsgo does not support Vue files.");
2890
+ const dtsPath = path.resolve(tsgoContext.path, path.relative(path.resolve(rootDir), filename_to_dts(id)));
2891
+ if (!existsSync(dtsPath)) {
2892
+ debug$3("[tsgo]", dtsPath, "is missing");
2893
+ throw new Error(`tsgo did not generate dts file for ${id}, please check your tsconfig.`);
2894
+ }
2895
+ dtsCode = await readFile(dtsPath, "utf8");
2896
+ const mapPath = `${dtsPath}.map`;
2897
+ if (existsSync(mapPath)) {
2898
+ const mapRaw = await readFile(mapPath, "utf8");
2899
+ map = {
2900
+ ...JSON.parse(mapRaw),
2901
+ sources: [id]
2902
+ };
2903
+ }
2904
+ } else if (generator === "oxc" && !RE_VUE.test(id)) {
2905
+ const result = isolatedDeclarationSync(id, code, oxc);
2906
+ if (result.errors.length) {
2907
+ const [error] = result.errors;
2908
+ return this.error({
2909
+ message: error.message,
2910
+ frame: error.codeframe || void 0
2911
+ });
2912
+ }
2913
+ dtsCode = result.code;
2914
+ if (result.map) {
2915
+ map = result.map;
2916
+ map.sourcesContent = void 0;
2917
+ }
2918
+ } else {
2919
+ const options = {
2920
+ tsconfig,
2921
+ tsconfigRaw,
2922
+ build,
2923
+ incremental,
2924
+ cwd,
2925
+ entries: eager ? void 0 : Array.from(dtsMap.values()).filter((v) => v.isEntry).map((v) => v.id),
2926
+ id,
2927
+ sourcemap,
2928
+ vue,
2929
+ tsMacro,
2930
+ context: tscContext
2931
+ };
2932
+ let result;
2933
+ if (parallel) result = await tscWorker.emit(options);
2934
+ else result = tscModule.tscEmit(options);
2935
+ if (result.error) return this.error(result.error);
2936
+ dtsCode = result.code;
2937
+ map = result.map;
2938
+ if (dtsCode && RE_JSON.test(id)) if (dtsCode.includes("declare const _exports")) {
2939
+ if (dtsCode.includes("declare const _exports: {") && !dtsCode.includes("\n}[];")) {
2940
+ const exports = collectJsonExports(dtsCode);
2941
+ let i = 0;
2942
+ dtsCode += exports.map((e) => {
2943
+ const valid = `_${e.replaceAll(/[^\w$]/g, "_")}${i++}`;
2944
+ const jsonKey = JSON.stringify(e);
2945
+ return `declare let ${valid}: typeof _exports[${jsonKey}]\nexport { ${valid} as ${jsonKey} }`;
2946
+ }).join("\n");
2947
+ }
2948
+ } else {
2949
+ const exportMap = collectJsonExportMap(dtsCode);
2950
+ dtsCode += `
2951
+ declare namespace __json_default_export {
2952
+ export { ${Array.from(exportMap.entries()).map(([exported, local]) => exported === local ? exported : `${local} as ${exported}`).join(", ")} }
2953
+ }
2954
+ export { __json_default_export as default }`;
2955
+ }
2956
+ }
2957
+ return {
2958
+ code: dtsCode || "",
2959
+ map
2960
+ };
2961
+ }
2962
+ },
2963
+ generateBundle: emitDtsOnly ? (options, bundle) => {
2964
+ for (const fileName of Object.keys(bundle)) if (bundle[fileName].type === "chunk" && !RE_DTS.test(fileName) && !RE_DTS_MAP.test(fileName)) delete bundle[fileName];
2965
+ } : void 0,
2966
+ async buildEnd() {
2967
+ tscWorker?.kill();
2968
+ tscWorker = void 0;
2969
+ await tsgoContext?.dispose();
2970
+ tsgoContext = void 0;
2971
+ if (newContext) tscContext = void 0;
2972
+ },
2973
+ watchChange(id) {
2974
+ if (tscModule) invalidateContextFile(tscContext || globalContext, id);
2975
+ }
2976
+ };
2977
+ }
2978
+ function createTscWorker() {
2979
+ const childProcess = fork(new URL(WORKER_URL, import.meta.url), {
2980
+ stdio: "inherit",
2981
+ serialization: "advanced"
2982
+ });
2983
+ const pending = /* @__PURE__ */ new Map();
2984
+ let nextId = 0;
2985
+ childProcess.on("message", (response) => {
2986
+ const handler = pending.get(response.id);
2987
+ if (!handler) return;
2988
+ pending.delete(response.id);
2989
+ if (response.error) handler.reject(response.error);
2990
+ else handler.resolve(response.result);
2991
+ });
2992
+ childProcess.on("exit", (code) => {
2993
+ for (const handler of pending.values()) handler.reject(/* @__PURE__ */ new Error(`tsc worker exited with code ${code}`));
2994
+ pending.clear();
2995
+ });
2996
+ return {
2997
+ emit: (options) => new Promise((resolve, reject) => {
2998
+ const id = nextId++;
2999
+ pending.set(id, {
3000
+ resolve,
3001
+ reject
3002
+ });
3003
+ childProcess.send({
3004
+ id,
3005
+ options
3006
+ });
3007
+ }),
3008
+ kill: () => childProcess.kill()
3009
+ };
3010
+ }
3011
+ function collectJsonExportMap(code) {
3012
+ const exportMap = /* @__PURE__ */ new Map();
3013
+ const { program } = parse$1(code, {
3014
+ sourceType: "module",
3015
+ lang: "dts"
3016
+ });
3017
+ for (const decl of program.body) if (decl.type === "ExportNamedDeclaration") {
3018
+ if (decl.declaration) {
3019
+ if (decl.declaration.type === "VariableDeclaration") {
3020
+ for (const vdecl of decl.declaration.declarations) if (vdecl.id.type === "Identifier") exportMap.set(vdecl.id.name, vdecl.id.name);
3021
+ } else if (decl.declaration.type === "TSModuleDeclaration" && decl.declaration.id.type === "Identifier") exportMap.set(decl.declaration.id.name, decl.declaration.id.name);
3022
+ } else if (decl.specifiers.length) {
3023
+ for (const spec of decl.specifiers) if (spec.type === "ExportSpecifier" && spec.exported.type === "Identifier") exportMap.set(spec.exported.name, spec.local.type === "Identifier" ? spec.local.name : spec.exported.name);
3024
+ }
3025
+ }
3026
+ return exportMap;
3027
+ }
3028
+ /** `declare const _exports` mode */
3029
+ function collectJsonExports(code) {
3030
+ const exports = [];
3031
+ const { program } = parse$1(code, {
3032
+ sourceType: "module",
3033
+ lang: "dts"
3034
+ });
3035
+ const members = program.body[0].declarations[0].id.typeAnnotation.typeAnnotation.members;
3036
+ for (const member of members) if (member.key.type === "Identifier") exports.push(member.key.name);
3037
+ else if (is.StringLiteral(member.key)) exports.push(member.key.value);
3038
+ return exports;
3039
+ }
3040
+ const debug$2 = createDebug("rolldown-plugin-dts:options");
3041
+ let warnedTsgo = false;
3042
+ function resolveOptions({ generator, entry, cwd = process.cwd(), dtsInput = false, emitDtsOnly = false, tsconfig, tsconfigRaw: overriddenTsconfigRaw = {}, compilerOptions = {}, sourcemap, resolver = "oxc", cjsDefault = false, sideEffects = false, logger = console, build = false, incremental = false, vue = false, tsMacro = false, parallel = false, eager = false, newContext = false, emitJs, oxc, tsgo }) {
3043
+ let resolvedTsconfig;
3044
+ if (tsconfig === true || tsconfig == null) {
3045
+ const { config, path } = at(cwd) || {};
3046
+ tsconfig = path;
3047
+ resolvedTsconfig = config;
3048
+ } else if (typeof tsconfig === "string") {
3049
+ tsconfig = path.resolve(cwd || process.cwd(), tsconfig);
3050
+ resolvedTsconfig = ee(tsconfig).config;
3051
+ } else tsconfig = void 0;
3052
+ compilerOptions = {
3053
+ ...resolvedTsconfig?.compilerOptions,
3054
+ ...compilerOptions
3055
+ };
3056
+ incremental ||= compilerOptions.incremental || !!compilerOptions.tsBuildInfoFile;
3057
+ sourcemap ??= !!compilerOptions.declarationMap;
3058
+ compilerOptions.declarationMap = sourcemap;
3059
+ const tsconfigRaw = {
3060
+ ...resolvedTsconfig,
3061
+ ...overriddenTsconfigRaw,
3062
+ compilerOptions
3063
+ };
3064
+ if (vue || tsMacro) {
3065
+ if (isTS70Installed()) throw new Error("TypeScript 7.0 does not yet have a stable API and is experimental. The `vue` and `tsMacro` options are not yet supported with TypeScript 7.0.");
3066
+ if (generator && generator !== "tsc") logger.warn("The `vue` and `tsMacro` options are enabled, which requires the `tsc` generator. The `generator` option is ignored.");
3067
+ generator = "tsc";
3068
+ }
3069
+ if (!generator) if (tsgo) generator = "tsgo";
3070
+ else if (oxc || compilerOptions?.isolatedDeclarations) generator = "oxc";
3071
+ else if (isTS70Installed()) generator = "tsgo";
3072
+ else generator = "tsc";
3073
+ if (generator === "tsc") try {
3074
+ __require$1.resolve("typescript");
3075
+ } catch {
3076
+ throw new Error("TypeScript is not installed. You can install `typescript` package, or enable `isolatedDeclarations` in your `tsconfig.json` to use Oxc instead.");
3077
+ }
3078
+ else if (generator === "tsgo") {
3079
+ if (!tsconfig) throw new Error("tsgo generator requires a tsconfig file to be specified.");
3080
+ if (!warnedTsgo) {
3081
+ warnedTsgo = true;
3082
+ logger.warn("TypeScript 7.0 does not yet have a stable API and is experimental. Some options will be unavailable.");
3083
+ }
3084
+ }
3085
+ if (oxc === true || !oxc) oxc = {};
3086
+ if (oxc) {
3087
+ oxc.stripInternal ??= !!compilerOptions?.stripInternal;
3088
+ oxc.sourcemap = !!compilerOptions.declarationMap;
3089
+ }
3090
+ if (tsgo === true || !tsgo) tsgo = {};
3091
+ emitJs ??= !!(compilerOptions.checkJs || compilerOptions.allowJs);
3092
+ const resolved = {
3093
+ generator,
3094
+ entry: entry ? Array.isArray(entry) ? entry : [entry] : void 0,
3095
+ cwd,
3096
+ dtsInput,
3097
+ emitDtsOnly,
3098
+ tsconfig,
3099
+ tsconfigRaw,
3100
+ sourcemap,
3101
+ resolver,
3102
+ cjsDefault,
3103
+ sideEffects,
3104
+ build,
3105
+ incremental,
3106
+ vue,
3107
+ tsMacro,
3108
+ parallel,
3109
+ eager,
3110
+ newContext,
3111
+ emitJs,
3112
+ oxc,
3113
+ tsgo,
3114
+ logger
3115
+ };
3116
+ debug$2("Resolved Options: %O", resolved);
3117
+ return resolved;
3118
+ }
3119
+ const debug$1 = createDebug("rolldown-plugin-dts:resolver");
3120
+ function isSourceFile(id) {
3121
+ return RE_TS.test(id) || RE_VUE.test(id) || RE_JSON.test(id);
3122
+ }
3123
+ function createDtsResolvePlugin({ cwd, tsconfig, tsconfigRaw, resolver, sideEffects }) {
3124
+ const baseDtsResolver = createResolver({
3125
+ tsconfig,
3126
+ resolveNodeModules: true,
3127
+ ResolverFactory
3128
+ });
3129
+ const moduleSideEffects = sideEffects ? true : null;
3130
+ return {
3131
+ name: "rolldown-plugin-dts:resolver",
3132
+ resolveId: {
3133
+ order: "pre",
3134
+ filter: [include(importerId(RE_DTS))],
3135
+ async handler(id, importer, options) {
3136
+ if (!importer) return;
3137
+ const external = {
3138
+ id,
3139
+ external: true,
3140
+ moduleSideEffects: sideEffects
3141
+ };
3142
+ const rolldownResolution = await this.resolve(id, importer, options);
3143
+ debug$1("Rolldown resolution for dts import %O from %O: %O", id, importer, rolldownResolution);
3144
+ if (rolldownResolution?.external) {
3145
+ debug$1("Rolldown marked dts import as external:", id);
3146
+ return rolldownResolution;
3147
+ }
3148
+ const dtsResolution = await resolveDtsPath(id, importer, rolldownResolution);
3149
+ debug$1("Dts resolution for dts import %O from %O: %O", id, importer, dtsResolution);
3150
+ if (!dtsResolution) {
3151
+ if (RE_CSS.test(id)) {
3152
+ debug$1("Externalizing css import:", id);
3153
+ return external;
3154
+ }
3155
+ debug$1("Unresolvable dts import:", id, "from", importer);
3156
+ return isFilePath(id) ? null : external;
3157
+ }
3158
+ if (RE_DTS.test(dtsResolution)) {
3159
+ debug$1("Resolving dts import to declaration file:", id);
3160
+ return {
3161
+ id: dtsResolution,
3162
+ moduleSideEffects
3163
+ };
3164
+ }
3165
+ if (isSourceFile(dtsResolution)) {
3166
+ debug$1("Resolving dts import to source file:", id);
3167
+ await this.load({ id: dtsResolution });
3168
+ return {
3169
+ id: filename_to_dts(dtsResolution),
3170
+ moduleSideEffects
3171
+ };
3172
+ }
3173
+ }
3174
+ }
3175
+ };
3176
+ async function resolveDtsPath(id, importer, rolldownResolution) {
3177
+ let dtsPath;
3178
+ if (resolver === "tsc") {
3179
+ const { tscResolve } = await import("./resolver-DtsKFXi2-B8Z3WwZh.js");
3180
+ dtsPath = tscResolve(id, importer, cwd, tsconfig, tsconfigRaw);
3181
+ } else dtsPath = baseDtsResolver(id, importer);
3182
+ debug$1("Using %s for dts import: %O -> %O", resolver, id, dtsPath);
3183
+ if (dtsPath) dtsPath = path.normalize(dtsPath);
3184
+ if (!dtsPath || !isSourceFile(dtsPath)) {
3185
+ if (rolldownResolution && isFilePath(rolldownResolution.id) && isSourceFile(rolldownResolution.id) && !rolldownResolution.external) return rolldownResolution.id;
3186
+ return null;
3187
+ }
3188
+ return dtsPath;
3189
+ }
3190
+ }
3191
+ function isFilePath(id) {
3192
+ return id.startsWith(".") || path.isAbsolute(id);
3193
+ }
3194
+ const debug = createDebug("rolldown-plugin-dts:options");
3195
+ function dts(options = {}) {
3196
+ debug("resolving dts options");
3197
+ const resolved = resolveOptions(options);
3198
+ debug("resolved dts options %o", resolved);
3199
+ const plugins = [];
3200
+ if (options.dtsInput) plugins.push(createDtsInputPlugin(resolved));
3201
+ else plugins.push(createGeneratePlugin(resolved));
3202
+ plugins.push(createDtsResolvePlugin(resolved), createFakeJsPlugin(resolved));
3203
+ return plugins;
3204
+ }
3205
+ //#endregion
3206
+ export { dts };