@teyik0/furin 0.3.0-alpha.1 → 0.4.0-alpha.1

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 (144) hide show
  1. package/dist/adapter/bun.d.ts +1 -1
  2. package/dist/build/client.d.ts +2 -2
  3. package/dist/build/entry-template.d.ts +4 -0
  4. package/dist/build/entry-template.ts +17 -3
  5. package/dist/build/index.d.ts +1 -1
  6. package/dist/build/index.js +8288 -6629
  7. package/dist/build/route-types.d.ts +2 -22
  8. package/dist/build/shared.d.ts +1 -1
  9. package/dist/build/ssg-cache.d.ts +1 -1
  10. package/dist/build/types.d.ts +1 -1
  11. package/dist/cli/index.js +7862 -6168
  12. package/dist/client/boundaries.d.ts +2 -0
  13. package/dist/client/define-route.d.ts +35 -0
  14. package/dist/client/document.d.ts +26 -0
  15. package/dist/client/hmr.d.ts +10 -0
  16. package/dist/client/internal/runtime-types.d.ts +3 -1
  17. package/dist/client/link.js +1177 -894
  18. package/dist/client/router/index.d.ts +1 -1
  19. package/dist/client/router/link-utils.d.ts +9 -0
  20. package/dist/client/router/search/index.d.ts +3 -7
  21. package/dist/client/router/types.d.ts +32 -24
  22. package/dist/client.d.ts +4 -159
  23. package/dist/client.js +183 -21
  24. package/dist/config.d.ts +8 -8
  25. package/dist/config.js +8 -8
  26. package/dist/define-route.d.ts +1355 -0
  27. package/dist/furin.d.ts +17 -33
  28. package/dist/furin.js +13444 -10301
  29. package/dist/plugin/index.js +953 -244
  30. package/dist/plugin/route-config-autofix.d.ts +31 -0
  31. package/dist/plugin/routes.d.ts +27 -0
  32. package/dist/routes.d.ts +6 -0
  33. package/dist/routes.js +1 -0
  34. package/dist/rsc/build/index.d.ts +1 -1
  35. package/dist/rsc.js +3 -3
  36. package/dist/server/dev-page-plugin.d.ts +7 -5
  37. package/dist/server/devtools/instrumentation.d.ts +2 -2
  38. package/dist/server/devtools/instrumentation.production.d.ts +2 -2
  39. package/dist/server/devtools/plugin.d.ts +2 -2
  40. package/dist/server/internal.d.ts +3 -0
  41. package/dist/server/logger.d.ts +4 -0
  42. package/dist/server/render/assemble.d.ts +0 -9
  43. package/dist/server/render/document.d.ts +4 -0
  44. package/dist/server/render/element.d.ts +2 -1
  45. package/dist/server/render/index.d.ts +1 -1
  46. package/dist/server/render/index.ts +0 -1
  47. package/dist/server/render/isr.d.ts +1 -1
  48. package/dist/server/render/loaders.d.ts +1 -1
  49. package/dist/server/render/not-found.d.ts +1 -1
  50. package/dist/server/render/ppr-route.d.ts +1 -1
  51. package/dist/server/render/ssg.d.ts +1 -1
  52. package/dist/server/render/ssr.d.ts +7 -6
  53. package/dist/server/render/template.d.ts +4 -0
  54. package/dist/server/router/defined-route.d.ts +24 -0
  55. package/dist/server/router/hmr.d.ts +16 -8
  56. package/dist/server/router/patterns.d.ts +6 -0
  57. package/dist/server/router/plugin.d.ts +4 -3
  58. package/dist/server/router/schema-merge.d.ts +2 -2
  59. package/dist/server/router/schemas.d.ts +5 -5
  60. package/dist/server/router/source-version.d.ts +2 -0
  61. package/dist/server/router/types.d.ts +1 -0
  62. package/dist/server/sync/index.js +961 -806
  63. package/dist/server/sync/postgres/migrate.js +3 -2
  64. package/dist/shared/await.d.ts +6 -7
  65. package/dist/shared/elysia-contract.d.ts +41 -0
  66. package/dist/shared/route-map.d.ts +5 -0
  67. package/dist/shared/utils/index.d.ts +1 -3
  68. package/package.json +44 -41
  69. package/src/adapter/bun.ts +42 -22
  70. package/src/adapter/package.ts +20 -14
  71. package/src/adapter/static.ts +4 -3
  72. package/src/build/client.ts +20 -3
  73. package/src/build/entry-template.ts +17 -3
  74. package/src/build/hydrate.ts +98 -28
  75. package/src/build/index.ts +2 -2
  76. package/src/build/route-types.ts +19 -114
  77. package/src/build/shared.ts +1 -1
  78. package/src/build/ssg-cache.ts +2 -5
  79. package/src/build/types.ts +1 -1
  80. package/src/cli/config.ts +3 -3
  81. package/src/cli/index.ts +7 -7
  82. package/src/client/boundaries.tsx +9 -1
  83. package/src/client/define-route.ts +48 -0
  84. package/src/client/document.tsx +165 -0
  85. package/src/client/hmr.ts +40 -0
  86. package/src/client/internal/runtime-types.ts +3 -1
  87. package/src/client/link.tsx +21 -6
  88. package/src/client/router/index.ts +1 -0
  89. package/src/client/router/link-utils.ts +26 -0
  90. package/src/client/router/provider.tsx +25 -2
  91. package/src/client/router/search/index.ts +4 -12
  92. package/src/client/router/types.ts +50 -24
  93. package/src/client.ts +14 -316
  94. package/src/config.ts +10 -10
  95. package/src/define-route.ts +959 -0
  96. package/src/devtools/devtools-element.js +11 -10
  97. package/src/furin.ts +303 -53
  98. package/src/plugin/route-config-autofix.ts +1140 -0
  99. package/src/plugin/routes.ts +891 -0
  100. package/src/plugin/transform-client.ts +132 -266
  101. package/src/plugin/transform-isomorphic.ts +1 -1
  102. package/src/routes.ts +6 -0
  103. package/src/rsc/build/index.ts +1 -1
  104. package/src/server/auto-invalidate/registry.ts +2 -2
  105. package/src/server/dev-page-plugin.ts +31 -12
  106. package/src/server/devtools/instrumentation.production.ts +2 -2
  107. package/src/server/devtools/instrumentation.ts +2 -2
  108. package/src/server/devtools/plugin.ts +5 -3
  109. package/src/server/instance.ts +3 -3
  110. package/src/server/internal.ts +3 -0
  111. package/src/server/logger.ts +21 -0
  112. package/src/server/render/assemble.ts +0 -41
  113. package/src/server/render/document.tsx +25 -0
  114. package/src/server/render/element.tsx +13 -1
  115. package/src/server/render/index.ts +0 -1
  116. package/src/server/render/isr.ts +31 -10
  117. package/src/server/render/loaders.ts +31 -6
  118. package/src/server/render/not-found.ts +51 -27
  119. package/src/server/render/ppr-route.ts +1 -1
  120. package/src/server/render/ssg.ts +1 -1
  121. package/src/server/render/ssr.ts +271 -113
  122. package/src/server/render/template.ts +91 -1
  123. package/src/server/router/defined-route.ts +110 -0
  124. package/src/server/router/discovery.ts +129 -29
  125. package/src/server/router/hmr.ts +111 -40
  126. package/src/server/router/patterns.ts +40 -12
  127. package/src/server/router/plugin.ts +63 -46
  128. package/src/server/router/schema-merge.ts +4 -14
  129. package/src/server/router/schemas.ts +11 -8
  130. package/src/server/router/source-version.ts +16 -0
  131. package/src/server/router/types.ts +2 -0
  132. package/src/server/sync/postgres/migrate.ts +3 -2
  133. package/src/server/sync/response.ts +14 -10
  134. package/src/shared/await.tsx +6 -7
  135. package/src/shared/elysia-contract.ts +63 -0
  136. package/src/shared/route-map.ts +37 -0
  137. package/src/shared/utils/index.ts +2 -20
  138. package/dist/build/server-routes-entry.d.ts +0 -13
  139. package/dist/build/server-routes-entry.ts +0 -30
  140. package/dist/server/router/index.d.ts +0 -7
  141. package/dist/server/router/index.js +0 -27
  142. package/dist/server/router/index.ts +0 -28
  143. package/src/build/server-routes-entry.ts +0 -30
  144. package/src/server/router/index.ts +0 -28
@@ -123,10 +123,10 @@ function encode(decoded) {
123
123
  return writer.flush();
124
124
  }
125
125
 
126
- // ../../node_modules/.bun/magic-string@1.1.0/node_modules/magic-string/dist/index.mjs
127
- var BitSet = class BitSet2 {
126
+ // ../../node_modules/.bun/magic-string@1.2.3/node_modules/magic-string/dist/index.mjs
127
+ var BitSet = class BitSet {
128
128
  constructor(arg) {
129
- this.bits = arg instanceof BitSet2 ? arg.bits.slice() : [];
129
+ this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
130
130
  }
131
131
  add(n) {
132
132
  this.bits[n >> 5] |= 1 << (n & 31);
@@ -135,7 +135,7 @@ var BitSet = class BitSet2 {
135
135
  return !!(this.bits[n >> 5] & 1 << (n & 31));
136
136
  }
137
137
  };
138
- var Chunk = class Chunk2 {
138
+ var Chunk = class Chunk {
139
139
  constructor(start, end, content) {
140
140
  this.start = start;
141
141
  this.end = end;
@@ -155,7 +155,7 @@ var Chunk = class Chunk2 {
155
155
  this.intro = this.intro + content;
156
156
  }
157
157
  clone() {
158
- const chunk = new Chunk2(this.start, this.end, this.original);
158
+ const chunk = new Chunk(this.start, this.end, this.original);
159
159
  chunk.intro = this.intro;
160
160
  chunk.outro = this.outro;
161
161
  chunk.content = this.content;
@@ -212,7 +212,7 @@ var Chunk = class Chunk2 {
212
212
  const originalBefore = this.original.slice(0, sliceIndex);
213
213
  const originalAfter = this.original.slice(sliceIndex);
214
214
  this.original = originalBefore;
215
- const newChunk = new Chunk2(index, this.end, originalAfter);
215
+ const newChunk = new Chunk(index, this.end, originalAfter);
216
216
  newChunk.outro = this.outro;
217
217
  this.outro = "";
218
218
  this.end = index;
@@ -272,6 +272,12 @@ var Chunk = class Chunk2 {
272
272
  }
273
273
  }
274
274
  };
275
+ var MagicStringError = class extends Error {
276
+ name = "MagicStringError";
277
+ constructor(message, options) {
278
+ super(`[MagicString] ${message}`, options);
279
+ }
280
+ };
275
281
  function getBtoa() {
276
282
  if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function")
277
283
  return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
@@ -279,7 +285,7 @@ function getBtoa() {
279
285
  if (buffer)
280
286
  return (str) => buffer.from(str, "utf-8").toString("base64");
281
287
  return () => {
282
- throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
288
+ throw new MagicStringError("unsupported environment: `btoa` or `Buffer` is required");
283
289
  };
284
290
  }
285
291
  var btoa = /* @__PURE__ */ getBtoa();
@@ -379,15 +385,15 @@ var Mappings = class {
379
385
  `, 0);
380
386
  let previousContentLineEnd = -1;
381
387
  while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
382
- const segment2 = [
388
+ const segment = [
383
389
  this.generatedCodeColumn,
384
390
  sourceIndex,
385
391
  loc.line,
386
392
  loc.column
387
393
  ];
388
394
  if (nameIndex >= 0)
389
- segment2.push(nameIndex);
390
- this.rawSegments.push(segment2);
395
+ segment.push(nameIndex);
396
+ this.rawSegments.push(segment);
391
397
  this.generatedCodeLine += 1;
392
398
  this.raw[this.generatedCodeLine] = this.rawSegments = [];
393
399
  this.generatedCodeColumn = 0;
@@ -478,7 +484,7 @@ var warned = {
478
484
  insertRight: false,
479
485
  storeName: false
480
486
  };
481
- var MagicString = class MagicString2 {
487
+ var MagicString = class MagicString {
482
488
  constructor(string, options = {}) {
483
489
  const chunk = new Chunk(0, string.length, string);
484
490
  Object.defineProperties(this, {
@@ -508,11 +514,11 @@ var MagicString = class MagicString2 {
508
514
  },
509
515
  byStart: {
510
516
  writable: true,
511
- value: {}
517
+ value: /* @__PURE__ */ new Map([[0, chunk]])
512
518
  },
513
519
  byEnd: {
514
520
  writable: true,
515
- value: {}
521
+ value: /* @__PURE__ */ new Map([[string.length, chunk]])
516
522
  },
517
523
  filename: {
518
524
  writable: true,
@@ -541,24 +547,26 @@ var MagicString = class MagicString2 {
541
547
  offset: {
542
548
  writable: true,
543
549
  value: options.offset || 0
550
+ },
551
+ hasMovedChunks: {
552
+ writable: true,
553
+ value: false
544
554
  }
545
555
  });
546
- this.byStart = /* @__PURE__ */ new Map([[0, chunk]]);
547
- this.byEnd = /* @__PURE__ */ new Map([[string.length, chunk]]);
548
556
  }
549
557
  addSourcemapLocation(char) {
550
558
  this.sourcemapLocations.add(char);
551
559
  }
552
560
  append(content) {
553
561
  if (typeof content !== "string")
554
- throw new TypeError("outro content must be a string");
562
+ throw new MagicStringError(`content must be a string, got ${typeof content}`);
555
563
  this.outro += content;
556
564
  return this;
557
565
  }
558
566
  appendLeft(index, content) {
559
567
  index = index + this.offset;
560
568
  if (typeof content !== "string")
561
- throw new TypeError("inserted content must be a string");
569
+ throw new MagicStringError(`content must be a string, got ${typeof content}`);
562
570
  this._split(index);
563
571
  const chunk = this.byEnd.get(index);
564
572
  if (chunk)
@@ -570,7 +578,7 @@ var MagicString = class MagicString2 {
570
578
  appendRight(index, content) {
571
579
  index = index + this.offset;
572
580
  if (typeof content !== "string")
573
- throw new TypeError("inserted content must be a string");
581
+ throw new MagicStringError(`content must be a string, got ${typeof content}`);
574
582
  this._split(index);
575
583
  const chunk = this.byStart.get(index);
576
584
  if (chunk)
@@ -580,8 +588,9 @@ var MagicString = class MagicString2 {
580
588
  return this;
581
589
  }
582
590
  clone() {
583
- const cloned = new MagicString2(this.original, {
591
+ const cloned = new MagicString(this.original, {
584
592
  filename: this.filename,
593
+ ignoreList: this.ignoreList,
585
594
  offset: this.offset
586
595
  });
587
596
  let originalChunk = this.firstChunk;
@@ -602,8 +611,10 @@ var MagicString = class MagicString2 {
602
611
  if (this.indentExclusionRanges)
603
612
  cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
604
613
  cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
614
+ cloned.storedNames = { ...this.storedNames };
605
615
  cloned.intro = this.intro;
606
616
  cloned.outro = this.outro;
617
+ cloned.hasMovedChunks = this.hasMovedChunks;
607
618
  return cloned;
608
619
  }
609
620
  generateDecodedMap(options) {
@@ -739,7 +750,7 @@ var MagicString = class MagicString2 {
739
750
  return this;
740
751
  }
741
752
  insert() {
742
- throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)");
753
+ throw new MagicStringError("insert() is deprecated, use appendLeft() or prependRight()");
743
754
  }
744
755
  insertLeft(index, content) {
745
756
  if (!warned.insertLeft) {
@@ -762,12 +773,20 @@ var MagicString = class MagicString2 {
762
773
  if (start === end)
763
774
  return this;
764
775
  if (index >= start && index <= end)
765
- throw new Error("Cannot move a selection inside itself");
776
+ throw new MagicStringError("cannot move a selection inside itself");
766
777
  this._split(start);
767
778
  this._split(end);
768
779
  this._split(index);
769
780
  const first = this.byStart.get(start);
770
781
  const last = this.byEnd.get(end);
782
+ if (this.hasMovedChunks) {
783
+ let cursor = first;
784
+ while (cursor !== last) {
785
+ cursor = cursor.next;
786
+ if (!cursor || cursor.start < start || cursor.end > end)
787
+ throw new MagicStringError(`cannot move ${start} to ${end} because an earlier move split that range`);
788
+ }
789
+ }
771
790
  const oldLeft = first.previous;
772
791
  const oldRight = last.next;
773
792
  const newRight = this.byStart.get(index);
@@ -794,6 +813,7 @@ var MagicString = class MagicString2 {
794
813
  this.firstChunk = first;
795
814
  if (!newRight)
796
815
  this.lastChunk = last;
816
+ this.hasMovedChunks = true;
797
817
  return this;
798
818
  }
799
819
  overwrite(start, end, content, options) {
@@ -807,17 +827,21 @@ var MagicString = class MagicString2 {
807
827
  start = start + this.offset;
808
828
  end = end + this.offset;
809
829
  if (typeof content !== "string")
810
- throw new TypeError("replacement content must be a string");
830
+ throw new MagicStringError(`content must be a string, got ${typeof content}`);
811
831
  if (this.original.length !== 0) {
812
- while (start < 0)
813
- start += this.original.length;
814
- while (end < 0)
815
- end += this.original.length;
832
+ if (start < 0)
833
+ start = Math.max(0, start + this.original.length);
834
+ if (end < 0)
835
+ end = Math.max(0, end + this.original.length);
816
836
  }
837
+ if (start < 0)
838
+ throw new MagicStringError(`start ${start} is out of bounds`);
817
839
  if (end > this.original.length)
818
- throw new Error("end is out of bounds");
840
+ throw new MagicStringError(`end ${end} is out of bounds`);
819
841
  if (start === end)
820
- throw new Error("Cannot overwrite a zero-length range \u2013 use appendLeft or prependRight instead");
842
+ throw new MagicStringError(`cannot overwrite a zero-length range at ${start}, use appendLeft() or prependRight()`);
843
+ if (start > end)
844
+ throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
821
845
  this._split(start);
822
846
  this._split(end);
823
847
  if (options === true) {
@@ -844,7 +868,7 @@ var MagicString = class MagicString2 {
844
868
  let chunk = first;
845
869
  while (chunk !== last) {
846
870
  if (chunk.next !== this.byStart.get(chunk.end))
847
- throw new Error("Cannot overwrite across a split point");
871
+ throw new MagicStringError("cannot overwrite across a split point");
848
872
  chunk = chunk.next;
849
873
  chunk.edit("", false);
850
874
  }
@@ -858,14 +882,14 @@ var MagicString = class MagicString2 {
858
882
  }
859
883
  prepend(content) {
860
884
  if (typeof content !== "string")
861
- throw new TypeError("outro content must be a string");
885
+ throw new MagicStringError(`content must be a string, got ${typeof content}`);
862
886
  this.intro = content + this.intro;
863
887
  return this;
864
888
  }
865
889
  prependLeft(index, content) {
866
890
  index = index + this.offset;
867
891
  if (typeof content !== "string")
868
- throw new TypeError("inserted content must be a string");
892
+ throw new MagicStringError(`content must be a string, got ${typeof content}`);
869
893
  this._split(index);
870
894
  const chunk = this.byEnd.get(index);
871
895
  if (chunk)
@@ -877,7 +901,7 @@ var MagicString = class MagicString2 {
877
901
  prependRight(index, content) {
878
902
  index = index + this.offset;
879
903
  if (typeof content !== "string")
880
- throw new TypeError("inserted content must be a string");
904
+ throw new MagicStringError(`content must be a string, got ${typeof content}`);
881
905
  this._split(index);
882
906
  const chunk = this.byStart.get(index);
883
907
  if (chunk)
@@ -890,17 +914,17 @@ var MagicString = class MagicString2 {
890
914
  start = start + this.offset;
891
915
  end = end + this.offset;
892
916
  if (this.original.length !== 0) {
893
- while (start < 0)
894
- start += this.original.length;
895
- while (end < 0)
896
- end += this.original.length;
917
+ if (start < 0)
918
+ start = Math.max(0, start + this.original.length);
919
+ if (end < 0)
920
+ end = Math.max(0, end + this.original.length);
897
921
  }
898
922
  if (start === end)
899
923
  return this;
900
924
  if (start < 0 || end > this.original.length)
901
- throw new Error("Character is out of bounds");
925
+ throw new MagicStringError(`range ${start}\u2013${end} is out of bounds`);
902
926
  if (start > end)
903
- throw new Error("end must be greater than start");
927
+ throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
904
928
  this._split(start);
905
929
  this._split(end);
906
930
  let chunk = this.byStart.get(start);
@@ -916,17 +940,17 @@ var MagicString = class MagicString2 {
916
940
  start = start + this.offset;
917
941
  end = end + this.offset;
918
942
  if (this.original.length !== 0) {
919
- while (start < 0)
920
- start += this.original.length;
921
- while (end < 0)
922
- end += this.original.length;
943
+ if (start < 0)
944
+ start = Math.max(0, start + this.original.length);
945
+ if (end < 0)
946
+ end = Math.max(0, end + this.original.length);
923
947
  }
924
948
  if (start === end)
925
949
  return this;
926
950
  if (start < 0 || end > this.original.length)
927
- throw new Error("Character is out of bounds");
951
+ throw new MagicStringError(`range ${start}\u2013${end} is out of bounds`);
928
952
  if (start > end)
929
- throw new Error("end must be greater than start");
953
+ throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
930
954
  this._split(start);
931
955
  this._split(end);
932
956
  let chunk = this.byStart.get(start);
@@ -989,10 +1013,10 @@ var MagicString = class MagicString2 {
989
1013
  start = start + this.offset;
990
1014
  end = end + this.offset;
991
1015
  if (this.original.length !== 0) {
992
- while (start < 0)
993
- start += this.original.length;
994
- while (end < 0)
995
- end += this.original.length;
1016
+ if (start < 0)
1017
+ start = Math.max(0, start + this.original.length);
1018
+ if (end < 0)
1019
+ end = Math.max(0, end + this.original.length);
996
1020
  }
997
1021
  let result = "";
998
1022
  let chunk = this.firstChunk;
@@ -1002,14 +1026,14 @@ var MagicString = class MagicString2 {
1002
1026
  chunk = chunk.next;
1003
1027
  }
1004
1028
  if (chunk && chunk.edited && chunk.start !== start)
1005
- throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
1029
+ throw new MagicStringError(`cannot use edited character ${start} as slice start anchor`);
1006
1030
  const startChunk = chunk;
1007
1031
  while (chunk) {
1008
1032
  if (chunk.intro && (startChunk !== chunk || chunk.start === start))
1009
1033
  result += chunk.intro;
1010
1034
  const containsEnd = chunk.start < end && chunk.end >= end;
1011
1035
  if (containsEnd && chunk.edited && chunk.end !== end)
1012
- throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
1036
+ throw new MagicStringError(`cannot use edited character ${end} as slice end anchor`);
1013
1037
  const sliceStart = startChunk === chunk ? start - chunk.start : 0;
1014
1038
  const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
1015
1039
  result += chunk.content.slice(sliceStart, sliceEnd);
@@ -1045,7 +1069,7 @@ var MagicString = class MagicString2 {
1045
1069
  _splitChunk(chunk, index) {
1046
1070
  if (chunk.edited && chunk.content.length) {
1047
1071
  const loc = getLocator(this.original)(index);
1048
- throw new Error(`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} \u2013 "${chunk.original}")`);
1072
+ throw new MagicStringError(`cannot split a chunk that has already been edited (${loc.line}:${loc.column} \u2013 "${chunk.original}")`);
1049
1073
  }
1050
1074
  const newChunk = chunk.split(index);
1051
1075
  this.byEnd.set(index, chunk);
@@ -1142,7 +1166,23 @@ var MagicString = class MagicString2 {
1142
1166
  return this;
1143
1167
  }
1144
1168
  hasChanged() {
1145
- return this.original !== this.toString();
1169
+ if (this.intro || this.outro)
1170
+ return true;
1171
+ let outputIndex = 0;
1172
+ let chunk = this.firstChunk;
1173
+ while (chunk) {
1174
+ if (chunk.intro || chunk.outro)
1175
+ return true;
1176
+ if (!chunk.edited && chunk.start === outputIndex)
1177
+ outputIndex = chunk.end;
1178
+ else {
1179
+ if (!this.original.startsWith(chunk.content, outputIndex))
1180
+ return true;
1181
+ outputIndex += chunk.content.length;
1182
+ }
1183
+ chunk = chunk.next;
1184
+ }
1185
+ return outputIndex !== this.original.length;
1146
1186
  }
1147
1187
  _replaceRegexp(searchValue, replacement) {
1148
1188
  function getReplacement(match, str) {
@@ -1159,31 +1199,25 @@ var MagicString = class MagicString2 {
1159
1199
  else
1160
1200
  return replacement(match[0], ...match.slice(1), match.index, str, match.groups);
1161
1201
  }
1162
- function matchAll(re, str) {
1163
- const matches = [];
1164
- while (true) {
1165
- const match = re.exec(str);
1166
- if (!match)
1167
- break;
1168
- matches.push(match);
1169
- }
1170
- return matches;
1171
- }
1172
- if (searchValue.global)
1173
- matchAll(searchValue, this.original).forEach((match) => {
1174
- if (match.index != null) {
1175
- const replacement2 = getReplacement(match, this.original);
1176
- if (replacement2 !== match[0])
1177
- this.overwrite(match.index, match.index + match[0].length, replacement2);
1178
- }
1179
- });
1180
- else {
1202
+ const replaceMatch = (match) => {
1203
+ if (match.index == null)
1204
+ return;
1205
+ const replacement = getReplacement(match, this.original);
1206
+ if (replacement === match[0])
1207
+ return;
1208
+ if (match[0].length === 0)
1209
+ this.appendRight(match.index, replacement);
1210
+ else
1211
+ this.overwrite(match.index, match.index + match[0].length, replacement);
1212
+ };
1213
+ if (searchValue.global) {
1214
+ searchValue.lastIndex = 0;
1215
+ for (const match of this.original.matchAll(searchValue))
1216
+ replaceMatch(match);
1217
+ } else {
1181
1218
  const match = this.original.match(searchValue);
1182
- if (match && match.index != null) {
1183
- const replacement2 = getReplacement(match, this.original);
1184
- if (replacement2 !== match[0])
1185
- this.overwrite(match.index, match.index + match[0].length, replacement2);
1186
- }
1219
+ if (match)
1220
+ replaceMatch(match);
1187
1221
  }
1188
1222
  return this;
1189
1223
  }
@@ -1194,7 +1228,10 @@ var MagicString = class MagicString2 {
1194
1228
  if (typeof replacement === "function")
1195
1229
  replacement = replacement(string, index, original);
1196
1230
  if (string !== replacement)
1197
- this.overwrite(index, index + string.length, replacement);
1231
+ if (string.length === 0)
1232
+ this.appendRight(index, replacement);
1233
+ else
1234
+ this.overwrite(index, index + string.length, replacement);
1198
1235
  }
1199
1236
  return this;
1200
1237
  }
@@ -1206,6 +1243,14 @@ var MagicString = class MagicString2 {
1206
1243
  _replaceAllString(string, replacement) {
1207
1244
  const { original } = this;
1208
1245
  const stringLength = string.length;
1246
+ if (stringLength === 0) {
1247
+ for (let index = 0;index <= original.length; index += 1) {
1248
+ const _replacement = typeof replacement === "function" ? replacement("", index, original) : replacement;
1249
+ if (_replacement !== "")
1250
+ this.appendRight(index, _replacement);
1251
+ }
1252
+ return this;
1253
+ }
1209
1254
  for (let index = original.indexOf(string);index !== -1; index = original.indexOf(string, index + stringLength)) {
1210
1255
  const previous = original.slice(index, index + stringLength);
1211
1256
  const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : replacement;
@@ -1218,14 +1263,743 @@ var MagicString = class MagicString2 {
1218
1263
  if (typeof searchValue === "string")
1219
1264
  return this._replaceAllString(searchValue, replacement);
1220
1265
  if (!searchValue.global)
1221
- throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
1266
+ throw new MagicStringError("replaceAll() requires a global RegExp");
1222
1267
  return this._replaceRegexp(searchValue, replacement);
1223
1268
  }
1224
1269
  };
1270
+ // ../../node_modules/.bun/yuku-ast@0.9.4/node_modules/yuku-ast/dist/aliases.js
1271
+ var ALIAS_GROUPS = {
1272
+ Expression: [
1273
+ "Identifier",
1274
+ "Literal",
1275
+ "ThisExpression",
1276
+ "Super",
1277
+ "ArrayExpression",
1278
+ "ObjectExpression",
1279
+ "FunctionExpression",
1280
+ "ArrowFunctionExpression",
1281
+ "ClassExpression",
1282
+ "TaggedTemplateExpression",
1283
+ "TemplateLiteral",
1284
+ "MemberExpression",
1285
+ "CallExpression",
1286
+ "NewExpression",
1287
+ "ChainExpression",
1288
+ "SequenceExpression",
1289
+ "ParenthesizedExpression",
1290
+ "BinaryExpression",
1291
+ "LogicalExpression",
1292
+ "ConditionalExpression",
1293
+ "UnaryExpression",
1294
+ "UpdateExpression",
1295
+ "AssignmentExpression",
1296
+ "YieldExpression",
1297
+ "AwaitExpression",
1298
+ "ImportExpression",
1299
+ "MetaProperty",
1300
+ "TSAsExpression",
1301
+ "TSSatisfiesExpression",
1302
+ "TSTypeAssertion",
1303
+ "TSNonNullExpression",
1304
+ "TSInstantiationExpression",
1305
+ "JSXElement",
1306
+ "JSXFragment"
1307
+ ],
1308
+ Statement: [
1309
+ "ExpressionStatement",
1310
+ "BlockStatement",
1311
+ "EmptyStatement",
1312
+ "DebuggerStatement",
1313
+ "ReturnStatement",
1314
+ "LabeledStatement",
1315
+ "BreakStatement",
1316
+ "ContinueStatement",
1317
+ "IfStatement",
1318
+ "SwitchStatement",
1319
+ "ThrowStatement",
1320
+ "TryStatement",
1321
+ "WhileStatement",
1322
+ "DoWhileStatement",
1323
+ "ForStatement",
1324
+ "ForInStatement",
1325
+ "ForOfStatement",
1326
+ "WithStatement",
1327
+ "FunctionDeclaration",
1328
+ "ClassDeclaration",
1329
+ "VariableDeclaration",
1330
+ "TSDeclareFunction",
1331
+ "TSTypeAliasDeclaration",
1332
+ "TSInterfaceDeclaration",
1333
+ "TSEnumDeclaration",
1334
+ "TSModuleDeclaration",
1335
+ "TSImportEqualsDeclaration"
1336
+ ],
1337
+ Declaration: [
1338
+ "FunctionDeclaration",
1339
+ "ClassDeclaration",
1340
+ "VariableDeclaration",
1341
+ "TSDeclareFunction",
1342
+ "TSTypeAliasDeclaration",
1343
+ "TSInterfaceDeclaration",
1344
+ "TSEnumDeclaration",
1345
+ "TSModuleDeclaration",
1346
+ "TSImportEqualsDeclaration"
1347
+ ],
1348
+ ModuleDeclaration: [
1349
+ "ImportDeclaration",
1350
+ "ExportNamedDeclaration",
1351
+ "ExportDefaultDeclaration",
1352
+ "ExportAllDeclaration",
1353
+ "TSExportAssignment",
1354
+ "TSNamespaceExportDeclaration"
1355
+ ],
1356
+ Function: [
1357
+ "FunctionDeclaration",
1358
+ "FunctionExpression",
1359
+ "TSDeclareFunction",
1360
+ "TSEmptyBodyFunctionExpression",
1361
+ "ArrowFunctionExpression"
1362
+ ],
1363
+ Class: ["ClassDeclaration", "ClassExpression"],
1364
+ Method: ["MethodDefinition", "TSAbstractMethodDefinition"],
1365
+ Loop: ["DoWhileStatement", "ForInStatement", "ForOfStatement", "ForStatement", "WhileStatement"],
1366
+ Pattern: ["ArrayPattern", "ObjectPattern", "AssignmentPattern", "RestElement"],
1367
+ JSX: [
1368
+ "JSXAttribute",
1369
+ "JSXClosingElement",
1370
+ "JSXClosingFragment",
1371
+ "JSXElement",
1372
+ "JSXEmptyExpression",
1373
+ "JSXExpressionContainer",
1374
+ "JSXFragment",
1375
+ "JSXIdentifier",
1376
+ "JSXMemberExpression",
1377
+ "JSXNamespacedName",
1378
+ "JSXOpeningElement",
1379
+ "JSXOpeningFragment",
1380
+ "JSXSpreadAttribute",
1381
+ "JSXSpreadChild",
1382
+ "JSXText"
1383
+ ],
1384
+ TSType: [
1385
+ "TSAnyKeyword",
1386
+ "TSUnknownKeyword",
1387
+ "TSNeverKeyword",
1388
+ "TSVoidKeyword",
1389
+ "TSNullKeyword",
1390
+ "TSUndefinedKeyword",
1391
+ "TSStringKeyword",
1392
+ "TSNumberKeyword",
1393
+ "TSBigIntKeyword",
1394
+ "TSBooleanKeyword",
1395
+ "TSSymbolKeyword",
1396
+ "TSObjectKeyword",
1397
+ "TSIntrinsicKeyword",
1398
+ "TSThisType",
1399
+ "TSTypeReference",
1400
+ "TSTypeQuery",
1401
+ "TSImportType",
1402
+ "TSLiteralType",
1403
+ "TSTemplateLiteralType",
1404
+ "TSArrayType",
1405
+ "TSIndexedAccessType",
1406
+ "TSTupleType",
1407
+ "TSNamedTupleMember",
1408
+ "TSJSDocNullableType",
1409
+ "TSJSDocNonNullableType",
1410
+ "TSJSDocUnknownType",
1411
+ "TSUnionType",
1412
+ "TSIntersectionType",
1413
+ "TSConditionalType",
1414
+ "TSInferType",
1415
+ "TSTypeOperator",
1416
+ "TSParenthesizedType",
1417
+ "TSFunctionType",
1418
+ "TSConstructorType",
1419
+ "TSTypePredicate",
1420
+ "TSTypeLiteral",
1421
+ "TSMappedType"
1422
+ ]
1423
+ };
1424
+ var ALIAS_NAMES = Object.keys(ALIAS_GROUPS);
1225
1425
 
1226
- // src/plugin/transform-client.ts
1227
- import { walk as walk2 } from "yuku-parser";
1426
+ // ../../node_modules/.bun/yuku-ast@0.9.4/node_modules/yuku-ast/dist/context.js
1427
+ class WalkContext {
1428
+ _ancestors = [];
1429
+ _node = null;
1430
+ _key = null;
1431
+ _list = null;
1432
+ _frame = null;
1433
+ _skip = false;
1434
+ _stopped = false;
1435
+ _removed = false;
1436
+ _replacement = null;
1437
+ state;
1438
+ get node() {
1439
+ return this._node;
1440
+ }
1441
+ get parent() {
1442
+ const a = this._ancestors;
1443
+ return a.length === 0 ? null : a[a.length - 1];
1444
+ }
1445
+ get key() {
1446
+ return this._key;
1447
+ }
1448
+ get index() {
1449
+ return this._list === null ? null : this._frame.i;
1450
+ }
1451
+ ancestors() {
1452
+ return [...this._ancestors];
1453
+ }
1454
+ skip() {
1455
+ this._skip = true;
1456
+ }
1457
+ stop() {
1458
+ this._stopped = true;
1459
+ }
1460
+ replace(node) {
1461
+ if (node === null || typeof node !== "object" || typeof node.type !== "string") {
1462
+ throw new TypeError("replace: expected an AST node");
1463
+ }
1464
+ if (this.parent === null) {
1465
+ throw new TypeError("replace: cannot replace the walk root");
1466
+ }
1467
+ if (node.start === 0 && node.end === 0) {
1468
+ node.start = this.node.start;
1469
+ node.end = this.node.end;
1470
+ }
1471
+ this._replacement = node;
1472
+ }
1473
+ remove() {
1474
+ if (this.parent === null) {
1475
+ throw new TypeError("remove: cannot remove the walk root");
1476
+ }
1477
+ this._removed = true;
1478
+ }
1479
+ insertBefore(node) {
1480
+ this.#insert(node, 0);
1481
+ this._frame.i++;
1482
+ }
1483
+ insertAfter(node) {
1484
+ this.#insert(node, 1);
1485
+ }
1486
+ #insert(node, offset) {
1487
+ if (this._list === null) {
1488
+ throw new TypeError("insertBefore/insertAfter require a node in an array field");
1489
+ }
1490
+ this._list.splice(this._frame.i + offset, 0, node);
1491
+ }
1492
+ }
1493
+
1494
+ // ../../node_modules/.bun/yuku-ast@0.9.4/node_modules/yuku-ast/dist/generated.js
1495
+ var KEYS = Object.create(null);
1496
+ function ck(type, keys) {
1497
+ const prev = KEYS[type];
1498
+ if (prev === undefined)
1499
+ KEYS[type] = keys;
1500
+ else
1501
+ for (const k of keys)
1502
+ if (!prev.includes(k))
1503
+ prev.push(k);
1504
+ }
1505
+ ck("SequenceExpression", ["expressions"]);
1506
+ ck("ParenthesizedExpression", ["expression"]);
1507
+ ck("ArrowFunctionExpression", ["typeParameters", "params", "returnType", "body"]);
1508
+ ck("FunctionDeclaration", ["id", "typeParameters", "params", "returnType", "body"]);
1509
+ ck("FunctionExpression", ["id", "typeParameters", "params", "returnType", "body"]);
1510
+ ck("TSDeclareFunction", ["id", "typeParameters", "params", "returnType", "body"]);
1511
+ ck("TSEmptyBodyFunctionExpression", ["id", "typeParameters", "params", "returnType", "body"]);
1512
+ ck("BlockStatement", ["body"]);
1513
+ ck("BlockStatement", ["body"]);
1514
+ ck("BinaryExpression", ["left", "right"]);
1515
+ ck("LogicalExpression", ["left", "right"]);
1516
+ ck("ConditionalExpression", ["test", "consequent", "alternate"]);
1517
+ ck("UnaryExpression", ["argument"]);
1518
+ ck("UpdateExpression", ["argument"]);
1519
+ ck("AssignmentExpression", ["left", "right"]);
1520
+ ck("ArrayExpression", ["elements"]);
1521
+ ck("ObjectExpression", ["properties"]);
1522
+ ck("SpreadElement", ["argument"]);
1523
+ ck("Property", ["key", "value"]);
1524
+ ck("MemberExpression", ["object", "property"]);
1525
+ ck("CallExpression", ["callee", "typeArguments", "arguments"]);
1526
+ ck("ChainExpression", ["expression"]);
1527
+ ck("TaggedTemplateExpression", ["tag", "typeArguments", "quasi"]);
1528
+ ck("NewExpression", ["callee", "typeArguments", "arguments"]);
1529
+ ck("AwaitExpression", ["argument"]);
1530
+ ck("YieldExpression", ["argument"]);
1531
+ ck("MetaProperty", ["meta", "property"]);
1532
+ ck("Decorator", ["expression"]);
1533
+ ck("ClassDeclaration", ["decorators", "id", "typeParameters", "superClass", "superTypeArguments", "implements", "body"]);
1534
+ ck("ClassExpression", ["decorators", "id", "typeParameters", "superClass", "superTypeArguments", "implements", "body"]);
1535
+ ck("ClassBody", ["body"]);
1536
+ ck("MethodDefinition", ["decorators", "key", "value"]);
1537
+ ck("TSAbstractMethodDefinition", ["decorators", "key", "value"]);
1538
+ ck("PropertyDefinition", ["decorators", "key", "typeAnnotation", "value"]);
1539
+ ck("AccessorProperty", ["decorators", "key", "typeAnnotation", "value"]);
1540
+ ck("TSAbstractPropertyDefinition", ["decorators", "key", "typeAnnotation", "value"]);
1541
+ ck("TSAbstractAccessorProperty", ["decorators", "key", "typeAnnotation", "value"]);
1542
+ ck("StaticBlock", ["body"]);
1543
+ ck("Super", []);
1544
+ ck("Literal", []);
1545
+ ck("Literal", []);
1546
+ ck("Literal", []);
1547
+ ck("Literal", []);
1548
+ ck("Literal", []);
1549
+ ck("ThisExpression", []);
1550
+ ck("Literal", []);
1551
+ ck("TemplateLiteral", ["quasis", "expressions"]);
1552
+ ck("TemplateElement", []);
1553
+ ck("Identifier", []);
1554
+ ck("PrivateIdentifier", []);
1555
+ ck("Identifier", ["decorators", "typeAnnotation"]);
1556
+ ck("Identifier", []);
1557
+ ck("Identifier", []);
1558
+ ck("ExpressionStatement", ["expression"]);
1559
+ ck("IfStatement", ["test", "consequent", "alternate"]);
1560
+ ck("SwitchStatement", ["discriminant", "cases"]);
1561
+ ck("SwitchCase", ["test", "consequent"]);
1562
+ ck("ForStatement", ["init", "test", "update", "body"]);
1563
+ ck("ForInStatement", ["left", "right", "body"]);
1564
+ ck("ForOfStatement", ["left", "right", "body"]);
1565
+ ck("WhileStatement", ["test", "body"]);
1566
+ ck("DoWhileStatement", ["body", "test"]);
1567
+ ck("BreakStatement", ["label"]);
1568
+ ck("ContinueStatement", ["label"]);
1569
+ ck("LabeledStatement", ["label", "body"]);
1570
+ ck("WithStatement", ["object", "body"]);
1571
+ ck("ReturnStatement", ["argument"]);
1572
+ ck("ThrowStatement", ["argument"]);
1573
+ ck("TryStatement", ["block", "handler", "finalizer"]);
1574
+ ck("CatchClause", ["param", "body"]);
1575
+ ck("DebuggerStatement", []);
1576
+ ck("EmptyStatement", []);
1577
+ ck("VariableDeclaration", ["declarations"]);
1578
+ ck("VariableDeclarator", ["id", "init"]);
1579
+ ck("ExpressionStatement", ["expression"]);
1580
+ ck("AssignmentPattern", ["decorators", "left", "typeAnnotation", "right"]);
1581
+ ck("RestElement", ["decorators", "argument", "typeAnnotation"]);
1582
+ ck("ArrayPattern", ["decorators", "elements", "typeAnnotation"]);
1583
+ ck("ObjectPattern", ["decorators", "properties", "typeAnnotation"]);
1584
+ ck("Property", ["key", "value"]);
1585
+ ck("Program", ["hashbang", "body"]);
1586
+ ck("ImportExpression", ["source", "options"]);
1587
+ ck("ImportDeclaration", ["specifiers", "source", "attributes"]);
1588
+ ck("ImportSpecifier", ["imported", "local"]);
1589
+ ck("ImportDefaultSpecifier", ["local"]);
1590
+ ck("ImportNamespaceSpecifier", ["local"]);
1591
+ ck("ImportAttribute", ["key", "value"]);
1592
+ ck("ExportNamedDeclaration", ["declaration", "specifiers", "source", "attributes"]);
1593
+ ck("ExportDefaultDeclaration", ["declaration"]);
1594
+ ck("ExportAllDeclaration", ["exported", "source", "attributes"]);
1595
+ ck("ExportSpecifier", ["local", "exported"]);
1596
+ ck("TSTypeAnnotation", ["typeAnnotation"]);
1597
+ ck("TSAnyKeyword", []);
1598
+ ck("TSUnknownKeyword", []);
1599
+ ck("TSNeverKeyword", []);
1600
+ ck("TSVoidKeyword", []);
1601
+ ck("TSNullKeyword", []);
1602
+ ck("TSUndefinedKeyword", []);
1603
+ ck("TSStringKeyword", []);
1604
+ ck("TSNumberKeyword", []);
1605
+ ck("TSBigIntKeyword", []);
1606
+ ck("TSBooleanKeyword", []);
1607
+ ck("TSSymbolKeyword", []);
1608
+ ck("TSObjectKeyword", []);
1609
+ ck("TSIntrinsicKeyword", []);
1610
+ ck("TSThisType", []);
1611
+ ck("TSTypeReference", ["typeName", "typeArguments"]);
1612
+ ck("TSQualifiedName", ["left", "right"]);
1613
+ ck("TSTypeQuery", ["exprName", "typeArguments"]);
1614
+ ck("TSImportType", ["source", "options", "qualifier", "typeArguments"]);
1615
+ ck("TSTypeParameter", ["name", "constraint", "default"]);
1616
+ ck("TSTypeParameterDeclaration", ["params"]);
1617
+ ck("TSTypeParameterInstantiation", ["params"]);
1618
+ ck("TSLiteralType", ["literal"]);
1619
+ ck("TSTemplateLiteralType", ["quasis", "types"]);
1620
+ ck("TSArrayType", ["elementType"]);
1621
+ ck("TSIndexedAccessType", ["objectType", "indexType"]);
1622
+ ck("TSTupleType", ["elementTypes"]);
1623
+ ck("TSNamedTupleMember", ["label", "elementType"]);
1624
+ ck("TSOptionalType", ["typeAnnotation"]);
1625
+ ck("TSRestType", ["typeAnnotation"]);
1626
+ ck("TSJSDocNullableType", ["typeAnnotation"]);
1627
+ ck("TSJSDocNonNullableType", ["typeAnnotation"]);
1628
+ ck("TSJSDocUnknownType", []);
1629
+ ck("TSUnionType", ["types"]);
1630
+ ck("TSIntersectionType", ["types"]);
1631
+ ck("TSConditionalType", ["checkType", "extendsType", "trueType", "falseType"]);
1632
+ ck("TSInferType", ["typeParameter"]);
1633
+ ck("TSTypeOperator", ["typeAnnotation"]);
1634
+ ck("TSParenthesizedType", ["typeAnnotation"]);
1635
+ ck("TSFunctionType", ["typeParameters", "params", "returnType"]);
1636
+ ck("TSConstructorType", ["typeParameters", "params", "returnType"]);
1637
+ ck("TSTypePredicate", ["parameterName", "typeAnnotation"]);
1638
+ ck("TSTypeLiteral", ["members"]);
1639
+ ck("TSMappedType", ["key", "constraint", "nameType", "typeAnnotation"]);
1640
+ ck("TSPropertySignature", ["key", "typeAnnotation"]);
1641
+ ck("TSMethodSignature", ["key", "typeParameters", "params", "returnType"]);
1642
+ ck("TSCallSignatureDeclaration", ["typeParameters", "params", "returnType"]);
1643
+ ck("TSConstructSignatureDeclaration", ["typeParameters", "params", "returnType"]);
1644
+ ck("TSIndexSignature", ["parameters", "typeAnnotation"]);
1645
+ ck("TSTypeAliasDeclaration", ["id", "typeParameters", "typeAnnotation"]);
1646
+ ck("TSInterfaceDeclaration", ["id", "typeParameters", "extends", "body"]);
1647
+ ck("TSInterfaceBody", ["body"]);
1648
+ ck("TSInterfaceHeritage", ["expression", "typeArguments"]);
1649
+ ck("TSClassImplements", ["expression", "typeArguments"]);
1650
+ ck("TSEnumDeclaration", ["id", "body"]);
1651
+ ck("TSEnumBody", ["members"]);
1652
+ ck("TSEnumMember", ["id", "initializer"]);
1653
+ ck("TSModuleDeclaration", ["id", "body"]);
1654
+ ck("TSModuleBlock", ["body"]);
1655
+ ck("TSModuleDeclaration", ["id", "body"]);
1656
+ ck("TSParameterProperty", ["decorators", "parameter"]);
1657
+ ck("Identifier", ["typeAnnotation"]);
1658
+ ck("TSAsExpression", ["expression", "typeAnnotation"]);
1659
+ ck("TSSatisfiesExpression", ["expression", "typeAnnotation"]);
1660
+ ck("TSTypeAssertion", ["typeAnnotation", "expression"]);
1661
+ ck("TSNonNullExpression", ["expression"]);
1662
+ ck("TSInstantiationExpression", ["expression", "typeArguments"]);
1663
+ ck("TSExportAssignment", ["expression"]);
1664
+ ck("TSNamespaceExportDeclaration", ["id"]);
1665
+ ck("TSImportEqualsDeclaration", ["id", "moduleReference"]);
1666
+ ck("TSExternalModuleReference", ["expression"]);
1667
+ ck("JSXElement", ["openingElement", "children", "closingElement"]);
1668
+ ck("JSXOpeningElement", ["name", "typeArguments", "attributes"]);
1669
+ ck("JSXClosingElement", ["name"]);
1670
+ ck("JSXFragment", ["openingFragment", "children", "closingFragment"]);
1671
+ ck("JSXOpeningFragment", []);
1672
+ ck("JSXClosingFragment", []);
1673
+ ck("JSXIdentifier", []);
1674
+ ck("JSXNamespacedName", ["namespace", "name"]);
1675
+ ck("JSXMemberExpression", ["object", "property"]);
1676
+ ck("JSXAttribute", ["name", "value"]);
1677
+ ck("JSXSpreadAttribute", ["argument"]);
1678
+ ck("JSXExpressionContainer", ["expression"]);
1679
+ ck("JSXEmptyExpression", []);
1680
+ ck("JSXText", []);
1681
+ ck("JSXSpreadChild", ["expression"]);
1682
+ ck("Hashbang", []);
1683
+ var CHILD_KEYS = KEYS;
1684
+ var TYPES = [
1685
+ "SequenceExpression",
1686
+ "ParenthesizedExpression",
1687
+ "ArrowFunctionExpression",
1688
+ "FunctionDeclaration",
1689
+ "FunctionExpression",
1690
+ "TSDeclareFunction",
1691
+ "TSEmptyBodyFunctionExpression",
1692
+ "BlockStatement",
1693
+ "BlockStatement",
1694
+ "BinaryExpression",
1695
+ "LogicalExpression",
1696
+ "ConditionalExpression",
1697
+ "UnaryExpression",
1698
+ "UpdateExpression",
1699
+ "AssignmentExpression",
1700
+ "ArrayExpression",
1701
+ "ObjectExpression",
1702
+ "SpreadElement",
1703
+ "Property",
1704
+ "MemberExpression",
1705
+ "CallExpression",
1706
+ "ChainExpression",
1707
+ "TaggedTemplateExpression",
1708
+ "NewExpression",
1709
+ "AwaitExpression",
1710
+ "YieldExpression",
1711
+ "MetaProperty",
1712
+ "Decorator",
1713
+ "ClassDeclaration",
1714
+ "ClassExpression",
1715
+ "ClassBody",
1716
+ "MethodDefinition",
1717
+ "TSAbstractMethodDefinition",
1718
+ "PropertyDefinition",
1719
+ "AccessorProperty",
1720
+ "TSAbstractPropertyDefinition",
1721
+ "TSAbstractAccessorProperty",
1722
+ "StaticBlock",
1723
+ "Super",
1724
+ "Literal",
1725
+ "Literal",
1726
+ "Literal",
1727
+ "Literal",
1728
+ "Literal",
1729
+ "ThisExpression",
1730
+ "Literal",
1731
+ "TemplateLiteral",
1732
+ "TemplateElement",
1733
+ "Identifier",
1734
+ "PrivateIdentifier",
1735
+ "Identifier",
1736
+ "Identifier",
1737
+ "Identifier",
1738
+ "ExpressionStatement",
1739
+ "IfStatement",
1740
+ "SwitchStatement",
1741
+ "SwitchCase",
1742
+ "ForStatement",
1743
+ "ForInStatement",
1744
+ "ForOfStatement",
1745
+ "WhileStatement",
1746
+ "DoWhileStatement",
1747
+ "BreakStatement",
1748
+ "ContinueStatement",
1749
+ "LabeledStatement",
1750
+ "WithStatement",
1751
+ "ReturnStatement",
1752
+ "ThrowStatement",
1753
+ "TryStatement",
1754
+ "CatchClause",
1755
+ "DebuggerStatement",
1756
+ "EmptyStatement",
1757
+ "VariableDeclaration",
1758
+ "VariableDeclarator",
1759
+ "ExpressionStatement",
1760
+ "AssignmentPattern",
1761
+ "RestElement",
1762
+ "ArrayPattern",
1763
+ "ObjectPattern",
1764
+ "Property",
1765
+ "Program",
1766
+ "ImportExpression",
1767
+ "ImportDeclaration",
1768
+ "ImportSpecifier",
1769
+ "ImportDefaultSpecifier",
1770
+ "ImportNamespaceSpecifier",
1771
+ "ImportAttribute",
1772
+ "ExportNamedDeclaration",
1773
+ "ExportDefaultDeclaration",
1774
+ "ExportAllDeclaration",
1775
+ "ExportSpecifier",
1776
+ "TSTypeAnnotation",
1777
+ "TSAnyKeyword",
1778
+ "TSUnknownKeyword",
1779
+ "TSNeverKeyword",
1780
+ "TSVoidKeyword",
1781
+ "TSNullKeyword",
1782
+ "TSUndefinedKeyword",
1783
+ "TSStringKeyword",
1784
+ "TSNumberKeyword",
1785
+ "TSBigIntKeyword",
1786
+ "TSBooleanKeyword",
1787
+ "TSSymbolKeyword",
1788
+ "TSObjectKeyword",
1789
+ "TSIntrinsicKeyword",
1790
+ "TSThisType",
1791
+ "TSTypeReference",
1792
+ "TSQualifiedName",
1793
+ "TSTypeQuery",
1794
+ "TSImportType",
1795
+ "TSTypeParameter",
1796
+ "TSTypeParameterDeclaration",
1797
+ "TSTypeParameterInstantiation",
1798
+ "TSLiteralType",
1799
+ "TSTemplateLiteralType",
1800
+ "TSArrayType",
1801
+ "TSIndexedAccessType",
1802
+ "TSTupleType",
1803
+ "TSNamedTupleMember",
1804
+ "TSOptionalType",
1805
+ "TSRestType",
1806
+ "TSJSDocNullableType",
1807
+ "TSJSDocNonNullableType",
1808
+ "TSJSDocUnknownType",
1809
+ "TSUnionType",
1810
+ "TSIntersectionType",
1811
+ "TSConditionalType",
1812
+ "TSInferType",
1813
+ "TSTypeOperator",
1814
+ "TSParenthesizedType",
1815
+ "TSFunctionType",
1816
+ "TSConstructorType",
1817
+ "TSTypePredicate",
1818
+ "TSTypeLiteral",
1819
+ "TSMappedType",
1820
+ "TSPropertySignature",
1821
+ "TSMethodSignature",
1822
+ "TSCallSignatureDeclaration",
1823
+ "TSConstructSignatureDeclaration",
1824
+ "TSIndexSignature",
1825
+ "TSTypeAliasDeclaration",
1826
+ "TSInterfaceDeclaration",
1827
+ "TSInterfaceBody",
1828
+ "TSInterfaceHeritage",
1829
+ "TSClassImplements",
1830
+ "TSEnumDeclaration",
1831
+ "TSEnumBody",
1832
+ "TSEnumMember",
1833
+ "TSModuleDeclaration",
1834
+ "TSModuleBlock",
1835
+ "TSModuleDeclaration",
1836
+ "TSParameterProperty",
1837
+ "Identifier",
1838
+ "TSAsExpression",
1839
+ "TSSatisfiesExpression",
1840
+ "TSTypeAssertion",
1841
+ "TSNonNullExpression",
1842
+ "TSInstantiationExpression",
1843
+ "TSExportAssignment",
1844
+ "TSNamespaceExportDeclaration",
1845
+ "TSImportEqualsDeclaration",
1846
+ "TSExternalModuleReference",
1847
+ "JSXElement",
1848
+ "JSXOpeningElement",
1849
+ "JSXClosingElement",
1850
+ "JSXFragment",
1851
+ "JSXOpeningFragment",
1852
+ "JSXClosingFragment",
1853
+ "JSXIdentifier",
1854
+ "JSXNamespacedName",
1855
+ "JSXMemberExpression",
1856
+ "JSXAttribute",
1857
+ "JSXSpreadAttribute",
1858
+ "JSXExpressionContainer",
1859
+ "JSXEmptyExpression",
1860
+ "JSXText",
1861
+ "JSXSpreadChild",
1862
+ "Hashbang"
1863
+ ];
1864
+ var NODE_TYPES = [...new Set(TYPES)];
1228
1865
 
1866
+ // ../../node_modules/.bun/yuku-ast@0.9.4/node_modules/yuku-ast/dist/walk.js
1867
+ function createDispatch(visitors) {
1868
+ let enter = null;
1869
+ let leave = null;
1870
+ const concrete = new Map;
1871
+ const add = (type, handler) => {
1872
+ const hooks = typeof handler === "function" ? { enter: handler } : handler;
1873
+ let entry = concrete.get(type);
1874
+ if (entry === undefined) {
1875
+ entry = { enter: [], leave: [] };
1876
+ concrete.set(type, entry);
1877
+ }
1878
+ if (hooks.enter)
1879
+ entry.enter.push(hooks.enter);
1880
+ if (hooks.leave)
1881
+ entry.leave.unshift(hooks.leave);
1882
+ };
1883
+ for (const [name, value] of Object.entries(visitors)) {
1884
+ if (value == null)
1885
+ continue;
1886
+ if (name === "enter")
1887
+ enter = value;
1888
+ else if (name === "leave")
1889
+ leave = value;
1890
+ else if (name in ALIAS_GROUPS) {
1891
+ for (const type of ALIAS_GROUPS[name])
1892
+ add(type, value);
1893
+ }
1894
+ }
1895
+ for (const [name, value] of Object.entries(visitors)) {
1896
+ if (value == null || name === "enter" || name === "leave" || name in ALIAS_GROUPS)
1897
+ continue;
1898
+ add(name, value);
1899
+ }
1900
+ return { enter, leave, typed: (type) => concrete.get(type) };
1901
+ }
1902
+ function walk(root, visitors, state) {
1903
+ _walk(root, visitors, state, new WalkContext);
1904
+ return root;
1905
+ }
1906
+ function position(ctx, node, key, list, frame) {
1907
+ ctx._node = node;
1908
+ ctx._key = key;
1909
+ ctx._list = list;
1910
+ ctx._frame = frame;
1911
+ }
1912
+ function applyReplace(ctx, parent, key, list, frame) {
1913
+ const next = ctx._replacement;
1914
+ ctx._replacement = null;
1915
+ if (list !== null)
1916
+ list[frame.i] = next;
1917
+ else
1918
+ parent[key] = next;
1919
+ return next;
1920
+ }
1921
+ function applyRemove(ctx, parent, key, list, frame) {
1922
+ ctx._removed = false;
1923
+ if (list !== null) {
1924
+ list.splice(frame.i, 1);
1925
+ frame.i--;
1926
+ } else {
1927
+ parent[key] = null;
1928
+ }
1929
+ }
1930
+ function _walk(root, visitors, state, ctx) {
1931
+ const d = createDispatch(visitors);
1932
+ ctx.state = state;
1933
+ const ancestors = ctx._ancestors;
1934
+ (function visit(node, key, list, frame) {
1935
+ let typed = d.typed(node.type);
1936
+ const parent = ctx.parent;
1937
+ position(ctx, node, key, list, frame);
1938
+ if (d.enter !== null) {
1939
+ d.enter(node, ctx);
1940
+ if (ctx._stopped)
1941
+ return false;
1942
+ }
1943
+ if (typed !== undefined) {
1944
+ for (const handler of typed.enter) {
1945
+ handler(node, ctx);
1946
+ if (ctx._stopped)
1947
+ return false;
1948
+ }
1949
+ }
1950
+ if (ctx._removed) {
1951
+ applyRemove(ctx, parent, key, list, frame);
1952
+ return true;
1953
+ }
1954
+ if (ctx._replacement !== null) {
1955
+ node = applyReplace(ctx, parent, key, list, frame);
1956
+ typed = d.typed(node.type);
1957
+ }
1958
+ const skipped = ctx._skip;
1959
+ ctx._skip = false;
1960
+ if (!skipped) {
1961
+ const keys = CHILD_KEYS[node.type];
1962
+ if (keys !== undefined && keys.length > 0) {
1963
+ ancestors.push(node);
1964
+ for (let k = 0;k < keys.length; k++) {
1965
+ const key2 = keys[k];
1966
+ const value = node[key2];
1967
+ if (value === null || value === undefined || typeof value !== "object")
1968
+ continue;
1969
+ if (Array.isArray(value)) {
1970
+ const childFrame = { i: 0 };
1971
+ for (;childFrame.i < value.length; childFrame.i++) {
1972
+ const item = value[childFrame.i];
1973
+ if (item !== null && !visit(item, key2, value, childFrame))
1974
+ return false;
1975
+ }
1976
+ } else if (!visit(value, key2, null, null)) {
1977
+ return false;
1978
+ }
1979
+ }
1980
+ ancestors.pop();
1981
+ }
1982
+ }
1983
+ position(ctx, node, key, list, frame);
1984
+ if (typed !== undefined) {
1985
+ for (const handler of typed.leave) {
1986
+ handler(node, ctx);
1987
+ if (ctx._stopped)
1988
+ return false;
1989
+ }
1990
+ }
1991
+ if (d.leave !== null) {
1992
+ d.leave(node, ctx);
1993
+ if (ctx._stopped)
1994
+ return false;
1995
+ }
1996
+ if (ctx._removed)
1997
+ applyRemove(ctx, parent, key, list, frame);
1998
+ else if (ctx._replacement !== null)
1999
+ applyReplace(ctx, parent, key, list, frame);
2000
+ return true;
2001
+ })(root, null, null, null);
2002
+ }
1229
2003
  // src/shared/parser.ts
1230
2004
  import { parse } from "yuku-parser";
1231
2005
  function parseSource(code, lang) {
@@ -1331,13 +2105,13 @@ function walkAST(node, visitor) {
1331
2105
  if (!isAstNode(node)) {
1332
2106
  return;
1333
2107
  }
1334
- const n2 = node;
1335
- visitor(n2);
1336
- for (const key of Object.keys(n2)) {
2108
+ const n = node;
2109
+ visitor(n);
2110
+ for (const key of Object.keys(n)) {
1337
2111
  if (SKIP_KEYS.has(key)) {
1338
2112
  continue;
1339
2113
  }
1340
- walkAST(n2[key], visitor);
2114
+ walkAST(n[key], visitor);
1341
2115
  }
1342
2116
  }
1343
2117
 
@@ -1485,7 +2259,6 @@ function deadCodeElimination(transformed, originalCode, lang) {
1485
2259
  }
1486
2260
 
1487
2261
  // src/plugin/transform-isomorphic.ts
1488
- import { walk } from "yuku-parser";
1489
2262
  var FURIN_MODULES = new Set(["@teyik0/furin", "furin"]);
1490
2263
  function importedName(specifier) {
1491
2264
  const { imported } = specifier;
@@ -1738,22 +2511,14 @@ function transformIsomorphicFunctions(source, filename, environment) {
1738
2511
  }
1739
2512
 
1740
2513
  // src/plugin/transform-client.ts
1741
- var SERVER_ONLY_PROPERTIES = new Set([
1742
- "loader",
1743
- "requestLoader",
1744
- "query",
1745
- "params",
1746
- "staticParams"
1747
- ]);
1748
2514
  var FURIN_CLIENT_MODULES = new Set(["@teyik0/furin/client", "furin/client"]);
1749
- function isFurinClientModule(source) {
1750
- return typeof source === "string" && FURIN_CLIENT_MODULES.has(source);
2515
+ var FURIN_SERVER_MODULES = new Set(["@teyik0/furin", "furin"]);
2516
+ var SERVER_ONLY_METHODS = new Set(["config", "head", "loader", "requestLoader", "staticParams"]);
2517
+ function isFurinRouteModule(source) {
2518
+ return typeof source === "string" && (FURIN_SERVER_MODULES.has(source) || FURIN_CLIENT_MODULES.has(source));
1751
2519
  }
1752
- function isRelativeModule(source) {
1753
- return typeof source === "string" && source.startsWith(".");
1754
- }
1755
- function importedName2(spec) {
1756
- const { imported } = spec;
2520
+ function importedName2(specifier) {
2521
+ const { imported } = specifier;
1757
2522
  if (!imported || typeof imported !== "object") {
1758
2523
  return null;
1759
2524
  }
@@ -1766,180 +2531,111 @@ function importedName2(spec) {
1766
2531
  }
1767
2532
  return null;
1768
2533
  }
1769
- function localName2(spec) {
1770
- const { local } = spec;
2534
+ function localName2(specifier) {
2535
+ const { local } = specifier;
1771
2536
  if (!local || typeof local !== "object") {
1772
2537
  return null;
1773
2538
  }
1774
2539
  const node = local;
1775
2540
  return node.type === "Identifier" && typeof node.name === "string" ? node.name : null;
1776
2541
  }
1777
- function addImportedBinding(source, spec, bindings) {
1778
- if (spec.type !== "ImportSpecifier" || spec.importKind === "type") {
1779
- return;
1780
- }
1781
- const imported = importedName2(spec);
1782
- const local = localName2(spec);
1783
- if (!local) {
1784
- return;
1785
- }
1786
- if (isFurinClientModule(source) && imported === "createRoute") {
1787
- bindings.createRouteNames.add(local);
1788
- }
1789
- if (isRelativeModule(source) && imported === "route") {
1790
- bindings.routeNames.add(local);
1791
- }
1792
- }
1793
- function collectImportedBindings(program) {
1794
- const bindings = {
1795
- createRouteNames: new Set,
1796
- routeNames: new Set
1797
- };
1798
- for (const stmt of program.body) {
1799
- if (stmt.type !== "ImportDeclaration") {
2542
+ function collectDefineRouteBindings(program) {
2543
+ const bindings = new Set;
2544
+ for (const statement of program.body) {
2545
+ if (statement.type !== "ImportDeclaration") {
1800
2546
  continue;
1801
2547
  }
1802
- const decl = stmt;
1803
- if (decl.importKind === "type") {
2548
+ const declaration = statement;
2549
+ if (declaration.importKind === "type") {
1804
2550
  continue;
1805
2551
  }
1806
- const source = decl.source.value;
1807
- for (const spec of decl.specifiers) {
1808
- addImportedBinding(source, spec, bindings);
2552
+ const source = declaration.source.value;
2553
+ if (!isFurinRouteModule(source)) {
2554
+ continue;
1809
2555
  }
1810
- }
1811
- return bindings;
1812
- }
1813
- function isCreateRouteCall(node, bindings, ancestors) {
1814
- return node.callee.type === "Identifier" && bindings.createRouteNames.has(node.callee.name) && !hasShadowingDeclaration(node.callee.name, ancestors);
1815
- }
1816
- function isCreateRouteExpression(node, bindings, ancestors) {
1817
- if (!node || typeof node !== "object") {
1818
- return false;
1819
- }
1820
- const expression = unwrapTSExpression(node);
1821
- return expression.type === "CallExpression" && isCreateRouteCall(expression, bindings, ancestors);
1822
- }
1823
- function collectLocalRouteBindings(program, bindings) {
1824
- walk2(program, {
1825
- VariableDeclarator(node, context) {
1826
- if (node.type !== "VariableDeclarator") {
1827
- return;
1828
- }
1829
- const { id, init } = node;
1830
- if (!id || typeof id !== "object") {
1831
- return;
2556
+ for (const specifier of declaration.specifiers) {
2557
+ if (specifier.type !== "ImportSpecifier" || specifier.importKind === "type") {
2558
+ continue;
1832
2559
  }
1833
- const identifier = id;
1834
- if (identifier.type !== "Identifier" || typeof identifier.name !== "string") {
1835
- return;
2560
+ const imported = importedName2(specifier);
2561
+ if (imported !== "defineRoute" && imported !== "defineRootRoute") {
2562
+ continue;
1836
2563
  }
1837
- if (isCreateRouteExpression(init, bindings, context.ancestors())) {
1838
- bindings.routeNames.add(identifier.name);
2564
+ const local = localName2(specifier);
2565
+ if (local) {
2566
+ bindings.add(local);
1839
2567
  }
1840
2568
  }
1841
- });
1842
- }
1843
- function collectRouteTransformBindings(program) {
1844
- const bindings = collectImportedBindings(program);
1845
- collectLocalRouteBindings(program, bindings);
2569
+ }
1846
2570
  return bindings;
1847
2571
  }
1848
- function isRoutePageCall(node, bindings, ancestors) {
1849
- const { callee } = node;
1850
- if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "page") {
1851
- const object = unwrapTSExpression(callee.object);
1852
- if (object.type === "Identifier" && bindings.routeNames.has(object.name) && !hasShadowingDeclaration(object.name, ancestors)) {
1853
- return true;
2572
+ function rewriteClientImports(source, program, bindings) {
2573
+ let rewritten = false;
2574
+ for (const statement of program.body) {
2575
+ if (statement.type !== "ImportDeclaration") {
2576
+ continue;
1854
2577
  }
1855
- return isCreateRouteExpression(object, bindings, ancestors);
1856
- }
1857
- return false;
1858
- }
1859
- function isTargetCall(node, bindings, ancestors) {
1860
- return isCreateRouteCall(node, bindings, ancestors) || isRoutePageCall(node, bindings, ancestors);
1861
- }
1862
- function isObjectExpressionNode(node) {
1863
- return node.type === "ObjectExpression";
1864
- }
1865
- function staticPropertyName(property) {
1866
- const { key } = property;
1867
- if (key.type === "Identifier" && !property.computed && typeof key.name === "string") {
1868
- return key.name;
1869
- }
1870
- if (key.type === "Literal" && typeof key.value === "string") {
1871
- return key.value;
1872
- }
1873
- }
1874
- function assertRoutePropertiesAreStaticallySafe(obj) {
1875
- for (const property of obj.properties) {
1876
- if (property.type !== "Property") {
1877
- throw new Error("[furin] Route configuration spreads are not allowed because server-only properties cannot be stripped safely.");
2578
+ const declaration = statement;
2579
+ const moduleName = declaration.source.value;
2580
+ if (typeof moduleName !== "string" || !FURIN_SERVER_MODULES.has(moduleName)) {
2581
+ continue;
1878
2582
  }
1879
- if (property.computed && staticPropertyName(property) === undefined) {
1880
- throw new Error("[furin] A dynamic computed property in route configuration cannot be stripped safely.");
2583
+ const importsClientValue = declaration.specifiers.some((specifier) => {
2584
+ const local = localName2(specifier);
2585
+ const imported = importedName2(specifier);
2586
+ return local !== null && bindings.has(local) || imported === "HeadContent" || imported === "Scripts";
2587
+ });
2588
+ if (!importsClientValue) {
2589
+ continue;
1881
2590
  }
2591
+ const clientModule = moduleName === "furin" ? "furin/client" : "@teyik0/furin/client";
2592
+ source.update(declaration.source.start + 1, declaration.source.end - 1, clientModule);
2593
+ rewritten = true;
1882
2594
  }
2595
+ return rewritten;
1883
2596
  }
1884
- function removeServerProperties(s, source, obj) {
1885
- assertRoutePropertiesAreStaticallySafe(obj);
1886
- const toRemove = obj.properties.filter((p) => {
1887
- if (p.type !== "Property") {
1888
- return false;
1889
- }
1890
- const name = staticPropertyName(p);
1891
- return name !== undefined && SERVER_ONLY_PROPERTIES.has(name);
1892
- });
1893
- if (toRemove.length === 0) {
1894
- return false;
2597
+ function asAstNode(node) {
2598
+ if (!node || typeof node !== "object" || !("type" in node)) {
2599
+ return null;
1895
2600
  }
1896
- for (const prop of toRemove) {
1897
- let removeEnd = prop.end;
1898
- while (removeEnd < source.length && (source[removeEnd] === "," || source[removeEnd] === " " || source[removeEnd] === `
1899
- ` || source[removeEnd] === "\r" || source[removeEnd] === "\t")) {
1900
- if (source[removeEnd] === ",") {
1901
- removeEnd += 1;
1902
- break;
1903
- }
1904
- removeEnd += 1;
1905
- }
1906
- let removeStart = prop.start;
1907
- while (removeStart > 0 && (source[removeStart - 1] === " " || source[removeStart - 1] === "\t")) {
1908
- removeStart -= 1;
2601
+ return unwrapTSExpression(node);
2602
+ }
2603
+ function chainRootIsDefineRoute(node, bindings, ancestors) {
2604
+ let current = asAstNode(node);
2605
+ while (current) {
2606
+ if (current.type === "MemberExpression") {
2607
+ current = asAstNode(current.object);
2608
+ continue;
1909
2609
  }
1910
- if (removeStart > 0 && source[removeStart - 1] === `
1911
- `) {
1912
- removeStart -= 1;
1913
- if (removeStart > 0 && source[removeStart - 1] === "\r") {
1914
- removeStart -= 1;
1915
- }
2610
+ if (current.type === "CallExpression") {
2611
+ current = asAstNode(current.callee);
2612
+ continue;
1916
2613
  }
1917
- s.remove(removeStart, removeEnd);
2614
+ return current.type === "Identifier" && typeof current.name === "string" && bindings.has(current.name) && !hasShadowingDeclaration(current.name, ancestors);
1918
2615
  }
1919
- return true;
2616
+ return false;
1920
2617
  }
1921
- function removeServerExports(s, source, program) {
1922
- let removedServerCode = false;
1923
- const bindings = collectRouteTransformBindings(program);
1924
- walk2(program, {
2618
+ function removeChainedServerCalls(source, program, bindings) {
2619
+ let transformed = rewriteClientImports(source, program, bindings);
2620
+ walk(program, {
1925
2621
  CallExpression(call, context) {
1926
- if (!isTargetCall(call, bindings, context.ancestors())) {
2622
+ const callee = asAstNode(call.callee);
2623
+ if (callee?.type !== "MemberExpression" || callee.computed === true || !callee.property || typeof callee.property !== "object") {
1927
2624
  return;
1928
2625
  }
1929
- const [firstArg] = call.arguments;
1930
- if (!firstArg) {
2626
+ const property = callee.property;
2627
+ if (property.type !== "Identifier" || typeof property.name !== "string" || !SERVER_ONLY_METHODS.has(property.name) || !chainRootIsDefineRoute(callee.object, bindings, context.ancestors())) {
1931
2628
  return;
1932
2629
  }
1933
- const arg = unwrapTSExpression(firstArg);
1934
- if (!isObjectExpressionNode(arg)) {
2630
+ const object = asAstNode(callee.object);
2631
+ if (!object) {
1935
2632
  return;
1936
2633
  }
1937
- if (removeServerProperties(s, source, arg)) {
1938
- removedServerCode = true;
1939
- }
2634
+ source.remove(object.end, call.end);
2635
+ transformed = true;
1940
2636
  }
1941
2637
  });
1942
- return removedServerCode;
2638
+ return transformed;
1943
2639
  }
1944
2640
  function transformForClient(code, filename) {
1945
2641
  const lang = detectLangFromPath(filename);
@@ -1948,20 +2644,33 @@ function transformForClient(code, filename) {
1948
2644
  }
1949
2645
  const isomorphicResult = transformIsomorphicFunctions(code, filename, "client");
1950
2646
  const clientSource = isomorphicResult.code;
1951
- const { program, diagnostics } = parseSource(clientSource, lang);
1952
- const firstError = diagnostics.find((d) => d.severity === "error");
2647
+ const { diagnostics, program } = parseSource(clientSource, lang);
2648
+ const firstError = diagnostics.find((diagnostic) => diagnostic.severity === "error");
1953
2649
  if (firstError) {
1954
2650
  throw new Error(`Failed to parse ${filename}: ${firstError.message}`);
1955
2651
  }
1956
- let s = new MagicString(clientSource);
1957
- const removedRouteCode = removeServerExports(s, clientSource, program);
2652
+ let source = new MagicString(clientSource);
2653
+ const routeBindings = collectDefineRouteBindings(program);
2654
+ const removedRouteCode = removeChainedServerCalls(source, program, routeBindings);
1958
2655
  const removedServerCode = isomorphicResult.transformed || removedRouteCode;
1959
2656
  if (removedServerCode) {
1960
- s = deadCodeElimination(s, code, lang);
2657
+ source = deadCodeElimination(source, code, lang);
2658
+ }
2659
+ if (routeBindings.size > 0) {
2660
+ source.append(`
2661
+ if (import.meta.hot) {
2662
+ import.meta.hot.accept((updatedModule) => {
2663
+ const updatedRoute = updatedModule?.route;
2664
+ if (updatedRoute?.component) {
2665
+ window.__FURIN_HMR_UPDATE__?.(${JSON.stringify(filename)}, updatedRoute.component);
2666
+ }
2667
+ });
2668
+ }
2669
+ `);
1961
2670
  }
1962
2671
  return {
1963
- code: s.toString(),
1964
- map: s.generateMap({ includeContent: true, source: filename }),
2672
+ code: source.toString(),
2673
+ map: source.generateMap({ includeContent: true, source: filename }),
1965
2674
  removedServerCode
1966
2675
  };
1967
2676
  }