@teyik0/furin 0.3.0-alpha.1 → 0.4.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/bun.d.ts +2 -18
- package/dist/adapter/package.d.ts +2 -2
- package/dist/adapter/runtime-build.d.ts +33 -0
- package/dist/adapter/vercel.d.ts +3 -0
- package/dist/build/client.d.ts +2 -2
- package/dist/build/compile-entry.d.ts +4 -3
- package/dist/build/compile-entry.ts +24 -69
- package/dist/build/entry-template.d.ts +8 -2
- package/dist/build/entry-template.ts +48 -11
- package/dist/build/index.d.ts +2 -2
- package/dist/build/index.js +11720 -7840
- package/dist/build/route-types.d.ts +2 -22
- package/dist/build/shared.d.ts +1 -1
- package/dist/build/ssg-cache.d.ts +14 -1
- package/dist/build/types.d.ts +26 -3
- package/dist/build/virtual-entry.d.ts +8 -0
- package/dist/cache.d.ts +5 -0
- package/dist/cache.js +97 -0
- package/dist/cli/index.js +11815 -7793
- package/dist/cli/preview.d.ts +7 -0
- package/dist/client/boundaries.d.ts +3 -0
- package/dist/client/browser-events-runtime.d.ts +2 -0
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/define-route.d.ts +36 -0
- package/dist/client/dev-error-overlay.d.ts +1 -0
- package/dist/client/dev-error-overlay.ts +201 -0
- package/dist/client/document.d.ts +27 -0
- package/dist/client/hmr.d.ts +12 -0
- package/dist/client/internal/runtime-types.d.ts +3 -1
- package/dist/client/link.js +1392 -940
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +9 -0
- package/dist/client/router/provider.d.ts +1 -1
- package/dist/client/router/search/index.d.ts +3 -7
- package/dist/client/router/sync-catch-up.d.ts +1 -1
- package/dist/client/router/types.d.ts +40 -34
- package/dist/client.d.ts +4 -159
- package/dist/client.js +197 -21
- package/dist/config.d.ts +25 -8
- package/dist/config.js +15 -7
- package/dist/define-route.d.ts +1358 -0
- package/dist/devtools/protocol.d.ts +2 -2
- package/dist/furin.d.ts +18 -34
- package/dist/furin.js +16038 -9395
- package/dist/plugin/index.js +1401 -223
- package/dist/plugin/route-config-autofix.d.ts +31 -0
- package/dist/plugin/routes.d.ts +28 -0
- package/dist/routes.d.ts +6 -0
- package/dist/routes.js +1 -0
- package/dist/rsc/build/index.d.ts +6 -2
- package/dist/rsc.js +3 -3
- package/dist/server/browser-events/plugin.d.ts +11 -0
- package/dist/server/browser-events/types.d.ts +9 -0
- package/dist/server/cache/invalidation.d.ts +1 -2
- package/dist/server/cache/isr.d.ts +1 -0
- package/dist/server/cache/purger.d.ts +7 -0
- package/dist/server/cache/runtime-cache.d.ts +21 -0
- package/dist/server/dev/browser-events.d.ts +4 -0
- package/dist/server/dev/diagnostics.d.ts +39 -0
- package/dist/server/dev/error.d.ts +17 -0
- package/dist/server/dev/graph.d.ts +86 -0
- package/dist/server/dev/plugin.d.ts +9 -0
- package/dist/server/dev/request-security.d.ts +1 -0
- package/dist/server/dev/rewrite-module-specifiers.d.ts +7 -0
- package/dist/server/dev/runtime.production.d.ts +5 -0
- package/dist/server/dev/symbolicate.d.ts +11 -0
- package/dist/server/dev/transform-failure.d.ts +4 -0
- package/dist/server/dev-page-plugin.d.ts +7 -5
- package/dist/server/dev-page-plugin.production.d.ts +1 -0
- package/dist/server/devtools/hub.d.ts +3 -2
- package/dist/server/devtools/instrumentation.d.ts +2 -2
- package/dist/server/devtools/instrumentation.production.d.ts +2 -2
- package/dist/server/devtools/plugin.d.ts +2 -2
- package/dist/server/external-prerender.d.ts +2 -0
- package/dist/server/instance.d.ts +2 -2
- package/dist/server/internal.d.ts +17 -2
- package/dist/server/internal.js +436 -1
- package/dist/server/logger.d.ts +4 -0
- package/dist/server/render/assemble.d.ts +0 -9
- package/dist/server/render/document.d.ts +4 -0
- package/dist/server/render/element.d.ts +3 -1
- package/dist/server/render/index.d.ts +2 -2
- package/dist/server/render/index.ts +1 -2
- package/dist/server/render/isr.d.ts +1 -1
- package/dist/server/render/loaders.d.ts +1 -1
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-document.d.ts +21 -0
- package/dist/server/render/ppr-request.d.ts +26 -0
- package/dist/server/render/ppr-route.d.ts +4 -2
- package/dist/server/render/shell.ts +0 -12
- package/dist/server/render/ssg.d.ts +3 -1
- package/dist/server/render/ssr.d.ts +23 -11
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +24 -0
- package/dist/server/router/hmr.d.ts +16 -8
- package/dist/server/router/hmr.production.d.ts +2 -0
- package/dist/server/router/patterns.d.ts +7 -0
- package/dist/server/router/plugin.d.ts +6 -3
- package/dist/server/router/schema-merge.d.ts +2 -2
- package/dist/server/router/schemas.d.ts +5 -5
- package/dist/server/router/source-version.d.ts +2 -0
- package/dist/server/router/types.d.ts +1 -0
- package/dist/server/sync/adapter.d.ts +13 -0
- package/dist/server/sync/config.d.ts +5 -5
- package/dist/server/sync/index.d.ts +6 -6
- package/dist/server/sync/index.js +1115 -985
- package/dist/server/sync/notifier.d.ts +1 -0
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +101 -6
- package/dist/server/sync/postgres/migrate.js +3 -2
- package/dist/server/sync/stream.d.ts +4 -13
- package/dist/shared/await.d.ts +4 -5
- package/dist/shared/browser-events.d.ts +22 -0
- package/dist/shared/compact-json.d.ts +8 -0
- package/dist/shared/deferred-ndjson.d.ts +6 -5
- package/dist/shared/dev-diagnostics.d.ts +36 -0
- package/dist/shared/elysia-contract.d.ts +41 -0
- package/dist/shared/prefix.d.ts +2 -0
- package/dist/shared/route-map.d.ts +5 -0
- package/dist/shared/utils/index.d.ts +1 -3
- package/package.json +55 -43
- package/src/adapter/README.md +45 -0
- package/src/adapter/bun.ts +62 -265
- package/src/adapter/package.ts +34 -22
- package/src/adapter/runtime-build.ts +375 -0
- package/src/adapter/static.ts +83 -5
- package/src/adapter/vercel.ts +857 -0
- package/src/build/client.ts +58 -16
- package/src/build/compile-entry.ts +24 -69
- package/src/build/entry-template.ts +48 -11
- package/src/build/hydrate.ts +147 -37
- package/src/build/index.ts +21 -7
- package/src/build/production-instrumentation.ts +56 -4
- package/src/build/route-types.ts +19 -114
- package/src/build/shared.ts +3 -2
- package/src/build/ssg-cache.ts +99 -16
- package/src/build/types.ts +32 -3
- package/src/build/virtual-entry.ts +27 -0
- package/src/cache.ts +14 -0
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +62 -10
- package/src/cli/preview.ts +90 -0
- package/src/client/boundaries.tsx +19 -2
- package/src/client/browser-events-runtime.ts +204 -0
- package/src/client/browser-events.ts +22 -0
- package/src/client/define-route.ts +38 -0
- package/src/client/dev-error-overlay.ts +201 -0
- package/src/client/document.tsx +162 -0
- package/src/client/hmr.ts +63 -0
- package/src/client/internal/runtime-types.ts +3 -1
- package/src/client/link.tsx +21 -6
- package/src/client/router/boundary-tree.tsx +4 -4
- package/src/client/router/index.ts +1 -0
- package/src/client/router/link-utils.ts +26 -0
- package/src/client/router/provider.tsx +190 -65
- package/src/client/router/search/index.ts +4 -12
- package/src/client/router/sync-catch-up.ts +3 -4
- package/src/client/router/types.ts +56 -30
- package/src/client.ts +14 -316
- package/src/config.ts +35 -10
- package/src/define-route.ts +972 -0
- package/src/devtools/devtools-element.js +67 -87
- package/src/devtools/protocol.ts +2 -2
- package/src/furin.ts +431 -101
- package/src/plugin/route-config-autofix.ts +1140 -0
- package/src/plugin/routes.ts +1061 -0
- package/src/plugin/transform-client.ts +776 -228
- package/src/plugin/transform-isomorphic.ts +1 -1
- package/src/react-dom-edge.d.ts +6 -0
- package/src/routes.ts +6 -0
- package/src/rsc/build/index.ts +16 -4
- package/src/server/auto-invalidate/registry.ts +2 -2
- package/src/server/auto-invalidate/runtime.ts +5 -2
- package/src/server/browser-events/plugin.ts +168 -0
- package/src/server/browser-events/types.ts +11 -0
- package/src/server/cache/dev-loader.ts +30 -29
- package/src/server/cache/invalidation.ts +13 -22
- package/src/server/cache/isr.ts +9 -0
- package/src/server/cache/purger.ts +41 -0
- package/src/server/cache/runtime-cache.ts +137 -0
- package/src/server/dev/browser-events.ts +54 -0
- package/src/server/dev/diagnostics.ts +297 -0
- package/src/server/dev/error.ts +148 -0
- package/src/server/dev/graph.ts +438 -0
- package/src/server/dev/plugin.ts +130 -0
- package/src/server/dev/request-security.ts +38 -0
- package/src/server/dev/rewrite-module-specifiers.ts +81 -0
- package/src/server/dev/runtime.production.ts +24 -0
- package/src/server/dev/symbolicate.ts +135 -0
- package/src/server/dev/transform-failure.ts +8 -0
- package/src/server/dev-page-plugin.production.ts +3 -0
- package/src/server/dev-page-plugin.ts +110 -52
- package/src/server/devtools/hub.ts +6 -5
- package/src/server/devtools/instrumentation.production.ts +3 -3
- package/src/server/devtools/instrumentation.ts +14 -8
- package/src/server/devtools/plugin.ts +12 -153
- package/src/server/external-prerender.ts +10 -0
- package/src/server/instance.ts +5 -5
- package/src/server/internal.ts +42 -2
- package/src/server/logger.ts +21 -0
- package/src/server/render/assemble.ts +4 -45
- package/src/server/render/document.tsx +34 -0
- package/src/server/render/element.tsx +31 -15
- package/src/server/render/index.ts +1 -2
- package/src/server/render/isr.ts +70 -24
- package/src/server/render/loaders.ts +43 -8
- package/src/server/render/not-found.ts +77 -29
- package/src/server/render/ppr-document.ts +239 -0
- package/src/server/render/ppr-request.ts +104 -0
- package/src/server/render/ppr-route.ts +153 -32
- package/src/server/render/shell.ts +0 -12
- package/src/server/render/ssg.ts +39 -21
- package/src/server/render/ssr.ts +429 -143
- package/src/server/render/template.ts +128 -2
- package/src/server/router/defined-route.ts +78 -0
- package/src/server/router/discovery.ts +129 -29
- package/src/server/router/hmr.production.ts +7 -0
- package/src/server/router/hmr.ts +177 -67
- package/src/server/router/patterns.ts +45 -13
- package/src/server/router/plugin.ts +184 -78
- package/src/server/router/schema-merge.ts +4 -14
- package/src/server/router/schemas.ts +11 -8
- package/src/server/router/source-version.ts +9 -0
- package/src/server/router/types.ts +2 -0
- package/src/server/sync/adapter.ts +13 -0
- package/src/server/sync/config.ts +12 -12
- package/src/server/sync/index.ts +8 -8
- package/src/server/sync/notifier.ts +1 -0
- package/src/server/sync/plugin.ts +4 -1
- package/src/server/sync/postgres/index.ts +111 -5
- package/src/server/sync/postgres/migrate.ts +3 -2
- package/src/server/sync/response.ts +14 -10
- package/src/server/sync/runtime.ts +12 -0
- package/src/server/sync/stream.ts +78 -113
- package/src/shared/await.tsx +4 -5
- package/src/shared/browser-events.ts +28 -0
- package/src/shared/compact-json.ts +77 -0
- package/src/shared/deferred-ndjson.ts +20 -6
- package/src/shared/dev-diagnostics.ts +44 -0
- package/src/shared/elysia-contract.ts +63 -0
- package/src/shared/prefix.ts +8 -0
- package/src/shared/route-map.ts +46 -0
- package/src/shared/utils/index.ts +2 -20
- package/dist/build/server-routes-entry.d.ts +0 -13
- package/dist/build/server-routes-entry.ts +0 -30
- package/dist/server/router/index.d.ts +0 -7
- package/dist/server/router/index.js +0 -27
- package/dist/server/router/index.ts +0 -28
- package/src/build/server-routes-entry.ts +0 -30
- package/src/server/router/index.ts +0 -28
package/dist/plugin/index.js
CHANGED
|
@@ -123,10 +123,10 @@ function encode(decoded) {
|
|
|
123
123
|
return writer.flush();
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
// ../../node_modules/.bun/magic-string@1.
|
|
127
|
-
var BitSet = class
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
390
|
-
this.rawSegments.push(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
830
|
+
throw new MagicStringError(`content must be a string, got ${typeof content}`);
|
|
811
831
|
if (this.original.length !== 0) {
|
|
812
|
-
|
|
813
|
-
start
|
|
814
|
-
|
|
815
|
-
end
|
|
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
|
|
840
|
+
throw new MagicStringError(`end ${end} is out of bounds`);
|
|
819
841
|
if (start === end)
|
|
820
|
-
throw new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
894
|
-
start
|
|
895
|
-
|
|
896
|
-
end
|
|
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
|
|
925
|
+
throw new MagicStringError(`range ${start}\u2013${end} is out of bounds`);
|
|
902
926
|
if (start > end)
|
|
903
|
-
throw new
|
|
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
|
-
|
|
920
|
-
start
|
|
921
|
-
|
|
922
|
-
end
|
|
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
|
|
951
|
+
throw new MagicStringError(`range ${start}\u2013${end} is out of bounds`);
|
|
928
952
|
if (start > end)
|
|
929
|
-
throw new
|
|
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
|
-
|
|
993
|
-
start
|
|
994
|
-
|
|
995
|
-
end
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
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
|
|
1183
|
-
|
|
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
|
-
|
|
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
|
|
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.5/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
|
-
//
|
|
1227
|
-
|
|
1426
|
+
// ../../node_modules/.bun/yuku-ast@0.9.5/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
|
+
}
|
|
1228
1493
|
|
|
1494
|
+
// ../../node_modules/.bun/yuku-ast@0.9.5/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)];
|
|
1865
|
+
|
|
1866
|
+
// ../../node_modules/.bun/yuku-ast@0.9.5/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
|
|
1335
|
-
visitor(
|
|
1336
|
-
for (const key of Object.keys(
|
|
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(
|
|
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,25 @@ 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
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
2515
|
+
var FURIN_SERVER_MODULES = new Set(["@teyik0/furin", "furin"]);
|
|
2516
|
+
var REACT_COMPONENT_WRAPPERS = new Set(["forwardRef", "memo"]);
|
|
2517
|
+
var SERVER_ONLY_METHODS = new Set(["config", "head", "loader", "requestLoader", "staticParams"]);
|
|
2518
|
+
var REACT_HOOK_NAME_RE = /^use[A-Z0-9]/;
|
|
2519
|
+
var HMR_DATA_SIGNATURE = "furin.hmr.data-signature";
|
|
2520
|
+
var TYPESCRIPT_RUNTIME_WRAPPERS = new Map([
|
|
2521
|
+
["TSAsExpression", ["expression"]],
|
|
2522
|
+
["TSInstantiationExpression", ["expression"]],
|
|
2523
|
+
["TSNonNullExpression", ["expression"]],
|
|
2524
|
+
["TSParameterProperty", ["decorators", "parameter"]],
|
|
2525
|
+
["TSSatisfiesExpression", ["expression"]],
|
|
2526
|
+
["TSTypeAssertion", ["expression"]]
|
|
2527
|
+
]);
|
|
2528
|
+
function isFurinRouteModule(source) {
|
|
2529
|
+
return typeof source === "string" && (FURIN_SERVER_MODULES.has(source) || FURIN_CLIENT_MODULES.has(source));
|
|
1754
2530
|
}
|
|
1755
|
-
function importedName2(
|
|
1756
|
-
const { imported } =
|
|
2531
|
+
function importedName2(specifier) {
|
|
2532
|
+
const { imported } = specifier;
|
|
1757
2533
|
if (!imported || typeof imported !== "object") {
|
|
1758
2534
|
return null;
|
|
1759
2535
|
}
|
|
@@ -1766,180 +2542,534 @@ function importedName2(spec) {
|
|
|
1766
2542
|
}
|
|
1767
2543
|
return null;
|
|
1768
2544
|
}
|
|
1769
|
-
function localName2(
|
|
1770
|
-
const { local } =
|
|
2545
|
+
function localName2(specifier) {
|
|
2546
|
+
const { local } = specifier;
|
|
1771
2547
|
if (!local || typeof local !== "object") {
|
|
1772
2548
|
return null;
|
|
1773
2549
|
}
|
|
1774
2550
|
const node = local;
|
|
1775
2551
|
return node.type === "Identifier" && typeof node.name === "string" ? node.name : null;
|
|
1776
2552
|
}
|
|
1777
|
-
function
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
2553
|
+
function collectDefineRouteBindings(program) {
|
|
2554
|
+
const bindings = new Set;
|
|
2555
|
+
for (const statement of program.body) {
|
|
2556
|
+
if (statement.type !== "ImportDeclaration") {
|
|
2557
|
+
continue;
|
|
2558
|
+
}
|
|
2559
|
+
const declaration = statement;
|
|
2560
|
+
if (declaration.importKind === "type") {
|
|
2561
|
+
continue;
|
|
2562
|
+
}
|
|
2563
|
+
const source = declaration.source.value;
|
|
2564
|
+
if (!isFurinRouteModule(source)) {
|
|
2565
|
+
continue;
|
|
2566
|
+
}
|
|
2567
|
+
for (const specifier of declaration.specifiers) {
|
|
2568
|
+
if (specifier.type !== "ImportSpecifier" || specifier.importKind === "type") {
|
|
2569
|
+
continue;
|
|
2570
|
+
}
|
|
2571
|
+
const imported = importedName2(specifier);
|
|
2572
|
+
if (imported !== "defineRoute" && imported !== "defineRootRoute") {
|
|
2573
|
+
continue;
|
|
2574
|
+
}
|
|
2575
|
+
const local = localName2(specifier);
|
|
2576
|
+
if (local) {
|
|
2577
|
+
bindings.add(local);
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
1791
2580
|
}
|
|
2581
|
+
return bindings;
|
|
1792
2582
|
}
|
|
1793
|
-
function
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
};
|
|
1798
|
-
for (const stmt of program.body) {
|
|
1799
|
-
if (stmt.type !== "ImportDeclaration") {
|
|
2583
|
+
function rewriteClientImports(source, program, bindings) {
|
|
2584
|
+
let rewritten = false;
|
|
2585
|
+
for (const statement of program.body) {
|
|
2586
|
+
if (statement.type !== "ImportDeclaration") {
|
|
1800
2587
|
continue;
|
|
1801
2588
|
}
|
|
1802
|
-
const
|
|
1803
|
-
|
|
2589
|
+
const declaration = statement;
|
|
2590
|
+
const moduleName = declaration.source.value;
|
|
2591
|
+
if (typeof moduleName !== "string" || !FURIN_SERVER_MODULES.has(moduleName)) {
|
|
1804
2592
|
continue;
|
|
1805
2593
|
}
|
|
1806
|
-
const
|
|
1807
|
-
|
|
1808
|
-
|
|
2594
|
+
const importsClientValue = declaration.specifiers.some((specifier) => {
|
|
2595
|
+
const local = localName2(specifier);
|
|
2596
|
+
const imported = importedName2(specifier);
|
|
2597
|
+
return local !== null && bindings.has(local) || imported === "HeadContent" || imported === "Scripts";
|
|
2598
|
+
});
|
|
2599
|
+
if (!importsClientValue) {
|
|
2600
|
+
continue;
|
|
1809
2601
|
}
|
|
2602
|
+
const clientModule = moduleName === "furin" ? "furin/client" : "@teyik0/furin/client";
|
|
2603
|
+
source.update(declaration.source.start + 1, declaration.source.end - 1, clientModule);
|
|
2604
|
+
rewritten = true;
|
|
1810
2605
|
}
|
|
1811
|
-
return
|
|
2606
|
+
return rewritten;
|
|
1812
2607
|
}
|
|
1813
|
-
function
|
|
1814
|
-
|
|
2608
|
+
function asAstNode(node) {
|
|
2609
|
+
if (!node || typeof node !== "object" || !("type" in node)) {
|
|
2610
|
+
return null;
|
|
2611
|
+
}
|
|
2612
|
+
return unwrapTSExpression(node);
|
|
1815
2613
|
}
|
|
1816
|
-
function
|
|
1817
|
-
|
|
1818
|
-
|
|
2614
|
+
function chainRootIsDefineRoute(node, bindings, ancestors) {
|
|
2615
|
+
let current = asAstNode(node);
|
|
2616
|
+
while (current) {
|
|
2617
|
+
if (current.type === "MemberExpression") {
|
|
2618
|
+
current = asAstNode(current.object);
|
|
2619
|
+
continue;
|
|
2620
|
+
}
|
|
2621
|
+
if (current.type === "CallExpression") {
|
|
2622
|
+
current = asAstNode(current.callee);
|
|
2623
|
+
continue;
|
|
2624
|
+
}
|
|
2625
|
+
return current.type === "Identifier" && typeof current.name === "string" && bindings.has(current.name) && !hasShadowingDeclaration(current.name, ancestors);
|
|
1819
2626
|
}
|
|
1820
|
-
|
|
1821
|
-
return expression.type === "CallExpression" && isCreateRouteCall(expression, bindings, ancestors);
|
|
2627
|
+
return false;
|
|
1822
2628
|
}
|
|
1823
|
-
function
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
2629
|
+
function removeChainedServerCalls(source, program, bindings) {
|
|
2630
|
+
let transformed = rewriteClientImports(source, program, bindings);
|
|
2631
|
+
walk(program, {
|
|
2632
|
+
CallExpression(call, context) {
|
|
2633
|
+
const callee = asAstNode(call.callee);
|
|
2634
|
+
if (callee?.type !== "MemberExpression" || callee.computed === true || !callee.property || typeof callee.property !== "object") {
|
|
1827
2635
|
return;
|
|
1828
2636
|
}
|
|
1829
|
-
const
|
|
1830
|
-
if (
|
|
2637
|
+
const property = callee.property;
|
|
2638
|
+
if (property.type !== "Identifier" || typeof property.name !== "string" || !SERVER_ONLY_METHODS.has(property.name) || !chainRootIsDefineRoute(callee.object, bindings, context.ancestors())) {
|
|
1831
2639
|
return;
|
|
1832
2640
|
}
|
|
1833
|
-
const
|
|
1834
|
-
if (
|
|
2641
|
+
const object = asAstNode(callee.object);
|
|
2642
|
+
if (!object) {
|
|
1835
2643
|
return;
|
|
1836
2644
|
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
}
|
|
2645
|
+
source.remove(object.end, call.end);
|
|
2646
|
+
transformed = true;
|
|
1840
2647
|
}
|
|
1841
2648
|
});
|
|
2649
|
+
return transformed;
|
|
1842
2650
|
}
|
|
1843
|
-
function
|
|
1844
|
-
const
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
2651
|
+
function collectBindingNames(pattern, names) {
|
|
2652
|
+
const node = asAstNode(pattern);
|
|
2653
|
+
if (!node) {
|
|
2654
|
+
return;
|
|
2655
|
+
}
|
|
2656
|
+
if (node.type === "Identifier" && typeof node.name === "string") {
|
|
2657
|
+
names.push(node.name);
|
|
2658
|
+
return;
|
|
2659
|
+
}
|
|
2660
|
+
if (node.type === "AssignmentPattern") {
|
|
2661
|
+
collectBindingNames(node.left, names);
|
|
2662
|
+
return;
|
|
2663
|
+
}
|
|
2664
|
+
if (node.type === "RestElement") {
|
|
2665
|
+
collectBindingNames(node.argument, names);
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2668
|
+
if (node.type === "ArrayPattern" && Array.isArray(node.elements)) {
|
|
2669
|
+
for (const element of node.elements) {
|
|
2670
|
+
collectBindingNames(element, names);
|
|
2671
|
+
}
|
|
2672
|
+
return;
|
|
2673
|
+
}
|
|
2674
|
+
if (node.type === "ObjectPattern" && Array.isArray(node.properties)) {
|
|
2675
|
+
for (const property of node.properties) {
|
|
2676
|
+
const propertyNode = asAstNode(property);
|
|
2677
|
+
collectBindingNames(propertyNode?.type === "Property" ? propertyNode.value : propertyNode?.argument, names);
|
|
1854
2678
|
}
|
|
1855
|
-
return isCreateRouteExpression(object, bindings, ancestors);
|
|
1856
2679
|
}
|
|
1857
|
-
return false;
|
|
1858
2680
|
}
|
|
1859
|
-
function
|
|
1860
|
-
|
|
2681
|
+
function collectDeclarationBindings(declaration, declarations) {
|
|
2682
|
+
if (declaration?.type === "FunctionDeclaration" || declaration?.type === "ClassDeclaration") {
|
|
2683
|
+
const identifier = asAstNode(declaration.id);
|
|
2684
|
+
if (identifier?.type === "Identifier" && typeof identifier.name === "string") {
|
|
2685
|
+
declarations.set(identifier.name, declaration);
|
|
2686
|
+
}
|
|
2687
|
+
return;
|
|
2688
|
+
}
|
|
2689
|
+
if (declaration?.type !== "VariableDeclaration" || !Array.isArray(declaration.declarations)) {
|
|
2690
|
+
return;
|
|
2691
|
+
}
|
|
2692
|
+
for (const item of declaration.declarations) {
|
|
2693
|
+
const names = [];
|
|
2694
|
+
collectBindingNames(item.id, names);
|
|
2695
|
+
for (const name of names) {
|
|
2696
|
+
declarations.set(name, item);
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
1861
2699
|
}
|
|
1862
|
-
function
|
|
1863
|
-
|
|
2700
|
+
function collectModuleBindings(program) {
|
|
2701
|
+
const declarations = new Map;
|
|
2702
|
+
const imports = new Set;
|
|
2703
|
+
for (const statement of program.body) {
|
|
2704
|
+
if (statement.type === "ImportDeclaration" && Array.isArray(statement.specifiers)) {
|
|
2705
|
+
for (const specifier of statement.specifiers) {
|
|
2706
|
+
const local = localName2(specifier);
|
|
2707
|
+
if (local) {
|
|
2708
|
+
imports.add(local);
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
continue;
|
|
2712
|
+
}
|
|
2713
|
+
const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? asAstNode(statement.declaration) : statement;
|
|
2714
|
+
collectDeclarationBindings(declaration, declarations);
|
|
2715
|
+
}
|
|
2716
|
+
return { declarations, imports };
|
|
1864
2717
|
}
|
|
1865
|
-
function
|
|
1866
|
-
const
|
|
1867
|
-
if (
|
|
1868
|
-
return
|
|
2718
|
+
function isBindingIdentifier(identifier, pattern) {
|
|
2719
|
+
const node = asAstNode(pattern);
|
|
2720
|
+
if (!node) {
|
|
2721
|
+
return false;
|
|
1869
2722
|
}
|
|
1870
|
-
if (
|
|
1871
|
-
return
|
|
2723
|
+
if (node.type === "Identifier") {
|
|
2724
|
+
return node.start === identifier.start && node.end === identifier.end;
|
|
2725
|
+
}
|
|
2726
|
+
if (node.type === "AssignmentPattern") {
|
|
2727
|
+
return isBindingIdentifier(identifier, node.left);
|
|
2728
|
+
}
|
|
2729
|
+
if (node.type === "RestElement") {
|
|
2730
|
+
return isBindingIdentifier(identifier, node.argument);
|
|
1872
2731
|
}
|
|
2732
|
+
if (node.type === "ArrayPattern" && Array.isArray(node.elements)) {
|
|
2733
|
+
return node.elements.some((element) => isBindingIdentifier(identifier, element));
|
|
2734
|
+
}
|
|
2735
|
+
if (node.type === "ObjectPattern" && Array.isArray(node.properties)) {
|
|
2736
|
+
return node.properties.some((property) => {
|
|
2737
|
+
const propertyNode = asAstNode(property);
|
|
2738
|
+
return isBindingIdentifier(identifier, propertyNode?.type === "Property" ? propertyNode.value : propertyNode?.argument);
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
return false;
|
|
1873
2742
|
}
|
|
1874
|
-
function
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
throw new Error("[furin] Route configuration spreads are not allowed because server-only properties cannot be stripped safely.");
|
|
1878
|
-
}
|
|
1879
|
-
if (property.computed && staticPropertyName(property) === undefined) {
|
|
1880
|
-
throw new Error("[furin] A dynamic computed property in route configuration cannot be stripped safely.");
|
|
1881
|
-
}
|
|
2743
|
+
function nodeContains(container, node) {
|
|
2744
|
+
if (Array.isArray(container)) {
|
|
2745
|
+
return container.some((entry) => nodeContains(entry, node));
|
|
1882
2746
|
}
|
|
2747
|
+
const containerNode = asAstNode(container);
|
|
2748
|
+
return Boolean(containerNode && containerNode.start <= node.start && node.end <= containerNode.end);
|
|
1883
2749
|
}
|
|
1884
|
-
function
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
if (p.type !== "Property") {
|
|
2750
|
+
function isTypePosition(node, ancestors) {
|
|
2751
|
+
return ancestors.some((ancestor) => {
|
|
2752
|
+
if (!ancestor.type.startsWith("TS")) {
|
|
1888
2753
|
return false;
|
|
1889
2754
|
}
|
|
1890
|
-
const
|
|
1891
|
-
|
|
2755
|
+
const runtimeChildren = TYPESCRIPT_RUNTIME_WRAPPERS.get(ancestor.type);
|
|
2756
|
+
if (runtimeChildren) {
|
|
2757
|
+
return !runtimeChildren.some((key) => nodeContains(ancestor[key], node));
|
|
2758
|
+
}
|
|
2759
|
+
return true;
|
|
1892
2760
|
});
|
|
1893
|
-
|
|
2761
|
+
}
|
|
2762
|
+
function isNonReferenceKey(node, parent) {
|
|
2763
|
+
return Boolean(parent && (parent.type === "MemberExpression" && parent.computed !== true && parent.property === node || parent.type === "Property" && parent.computed !== true && parent.shorthand !== true && parent.key === node || (parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.computed !== true && parent.key === node || (parent.type === "LabeledStatement" || parent.type === "BreakStatement" || parent.type === "ContinueStatement") && parent.label === node));
|
|
2764
|
+
}
|
|
2765
|
+
function isReferenceIdentifier(node, ancestors) {
|
|
2766
|
+
if (isTypePosition(node, ancestors) || isNonReferenceKey(node, ancestors.at(-1))) {
|
|
1894
2767
|
return false;
|
|
1895
2768
|
}
|
|
1896
|
-
for (const
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
` || source[removeEnd] === "\r" || source[removeEnd] === "\t")) {
|
|
1900
|
-
if (source[removeEnd] === ",") {
|
|
1901
|
-
removeEnd += 1;
|
|
1902
|
-
break;
|
|
1903
|
-
}
|
|
1904
|
-
removeEnd += 1;
|
|
2769
|
+
for (const ancestor of ancestors) {
|
|
2770
|
+
if (ancestor.type === "VariableDeclarator" && isBindingIdentifier(node, ancestor.id) || (ancestor.type === "FunctionDeclaration" || ancestor.type === "FunctionExpression" || ancestor.type === "ArrowFunctionExpression") && (isBindingIdentifier(node, ancestor.id) || Array.isArray(ancestor.params) && ancestor.params.some((parameter) => isBindingIdentifier(node, parameter))) || ancestor.type === "ClassDeclaration" && isBindingIdentifier(node, ancestor.id) || ancestor.type === "CatchClause" && isBindingIdentifier(node, ancestor.param)) {
|
|
2771
|
+
return false;
|
|
1905
2772
|
}
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
2773
|
+
}
|
|
2774
|
+
return true;
|
|
2775
|
+
}
|
|
2776
|
+
function walkWithAncestors(value, ancestors, visitor) {
|
|
2777
|
+
if (Array.isArray(value)) {
|
|
2778
|
+
for (const entry of value) {
|
|
2779
|
+
walkWithAncestors(entry, ancestors, visitor);
|
|
1909
2780
|
}
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
2781
|
+
return;
|
|
2782
|
+
}
|
|
2783
|
+
const node = asAstNode(value);
|
|
2784
|
+
if (!node) {
|
|
2785
|
+
return;
|
|
2786
|
+
}
|
|
2787
|
+
visitor(node, ancestors);
|
|
2788
|
+
const nextAncestors = [...ancestors, node];
|
|
2789
|
+
for (const [key, child] of Object.entries(node)) {
|
|
2790
|
+
if (key !== "type" && key !== "start" && key !== "end" && key !== "comments") {
|
|
2791
|
+
walkWithAncestors(child, nextAncestors, visitor);
|
|
1916
2792
|
}
|
|
1917
|
-
s.remove(removeStart, removeEnd);
|
|
1918
2793
|
}
|
|
1919
|
-
return true;
|
|
1920
2794
|
}
|
|
1921
|
-
function
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
2795
|
+
function collectDependencyIdentifier(child, ancestors, trackImports, state) {
|
|
2796
|
+
if (child.type !== "Identifier" || typeof child.name !== "string" || !isReferenceIdentifier(child, ancestors) || hasShadowingDeclaration(child.name, ancestors)) {
|
|
2797
|
+
return;
|
|
2798
|
+
}
|
|
2799
|
+
const declaration = state.moduleBindings.declarations.get(child.name);
|
|
2800
|
+
if (!declaration) {
|
|
2801
|
+
if (trackImports && state.moduleBindings.imports.has(child.name)) {
|
|
2802
|
+
state.hasUnresolvedImport = true;
|
|
2803
|
+
}
|
|
2804
|
+
return;
|
|
2805
|
+
}
|
|
2806
|
+
const alreadyTracked = state.dependencies.has(declaration.start);
|
|
2807
|
+
if (!alreadyTracked) {
|
|
2808
|
+
state.dependencies.set(declaration.start, declaration);
|
|
2809
|
+
}
|
|
2810
|
+
if (trackImports) {
|
|
2811
|
+
if (state.importTrackedDependencies.has(declaration.start)) {
|
|
2812
|
+
return;
|
|
2813
|
+
}
|
|
2814
|
+
state.importTrackedDependencies.add(declaration.start);
|
|
2815
|
+
} else if (alreadyTracked) {
|
|
2816
|
+
return;
|
|
2817
|
+
}
|
|
2818
|
+
collectDependencies(declaration, trackImports, state);
|
|
2819
|
+
}
|
|
2820
|
+
function collectDependencies(node, trackImports, state) {
|
|
2821
|
+
walkWithAncestors(node, [], (child, ancestors) => {
|
|
2822
|
+
collectDependencyIdentifier(child, ancestors, trackImports, state);
|
|
2823
|
+
});
|
|
2824
|
+
}
|
|
2825
|
+
function createHmrDataSignature(code, program, bindings) {
|
|
2826
|
+
const serverStages = [];
|
|
2827
|
+
const dependencyState = {
|
|
2828
|
+
dependencies: new Map,
|
|
2829
|
+
hasUnresolvedImport: false,
|
|
2830
|
+
importTrackedDependencies: new Set,
|
|
2831
|
+
moduleBindings: collectModuleBindings(program)
|
|
2832
|
+
};
|
|
2833
|
+
walk(program, {
|
|
1925
2834
|
CallExpression(call, context) {
|
|
1926
|
-
|
|
2835
|
+
const callee = asAstNode(call.callee);
|
|
2836
|
+
if (callee?.type !== "MemberExpression" || callee.computed === true || !callee.property || typeof callee.property !== "object") {
|
|
2837
|
+
return;
|
|
2838
|
+
}
|
|
2839
|
+
const property = callee.property;
|
|
2840
|
+
if (property.type !== "Identifier" || typeof property.name !== "string" || !SERVER_ONLY_METHODS.has(property.name) || !chainRootIsDefineRoute(callee.object, bindings, context.ancestors())) {
|
|
2841
|
+
return;
|
|
2842
|
+
}
|
|
2843
|
+
const object = asAstNode(callee.object);
|
|
2844
|
+
if (!object) {
|
|
1927
2845
|
return;
|
|
1928
2846
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
2847
|
+
serverStages.push({
|
|
2848
|
+
source: code.slice(object.end, call.end),
|
|
2849
|
+
start: call.start
|
|
2850
|
+
});
|
|
2851
|
+
if (Array.isArray(call.arguments)) {
|
|
2852
|
+
for (const argument of call.arguments) {
|
|
2853
|
+
const argumentNode = asAstNode(argument);
|
|
2854
|
+
if (argumentNode) {
|
|
2855
|
+
collectDependencies(argumentNode, property.name !== "config", dependencyState);
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
});
|
|
2861
|
+
const dataSource = [
|
|
2862
|
+
...serverStages,
|
|
2863
|
+
...[...dependencyState.dependencies.values()].map((dependency) => ({
|
|
2864
|
+
source: code.slice(dependency.start, dependency.end),
|
|
2865
|
+
start: dependency.start
|
|
2866
|
+
}))
|
|
2867
|
+
].sort((left, right) => left.start - right.start).map((entry) => entry.source).join(`
|
|
2868
|
+
`);
|
|
2869
|
+
const hash = new Bun.CryptoHasher("sha256").update(dataSource).digest("hex");
|
|
2870
|
+
return dependencyState.hasUnresolvedImport ? `external:${hash}` : hash;
|
|
2871
|
+
}
|
|
2872
|
+
function calledHookName(call) {
|
|
2873
|
+
const callee = asAstNode(call.callee);
|
|
2874
|
+
if (callee?.type === "Identifier" && typeof callee.name === "string") {
|
|
2875
|
+
return REACT_HOOK_NAME_RE.test(callee.name) ? callee.name : null;
|
|
2876
|
+
}
|
|
2877
|
+
if (callee?.type === "MemberExpression" && callee.computed !== true && callee.property && typeof callee.property === "object") {
|
|
2878
|
+
const property = callee.property;
|
|
2879
|
+
if (property.type === "Identifier" && typeof property.name === "string" && REACT_HOOK_NAME_RE.test(property.name)) {
|
|
2880
|
+
return property.name;
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
return null;
|
|
2884
|
+
}
|
|
2885
|
+
function routeComponentExpression(program, bindings) {
|
|
2886
|
+
let component = null;
|
|
2887
|
+
walk(program, {
|
|
2888
|
+
CallExpression(call, context) {
|
|
2889
|
+
const callee = asAstNode(call.callee);
|
|
2890
|
+
if (callee?.type !== "MemberExpression" || callee.computed === true || !callee.property || typeof callee.property !== "object") {
|
|
1931
2891
|
return;
|
|
1932
2892
|
}
|
|
1933
|
-
const
|
|
1934
|
-
|
|
2893
|
+
const property = callee.property;
|
|
2894
|
+
const ancestors = context.ancestors();
|
|
2895
|
+
const routeDeclarator = ancestors.find((ancestor) => {
|
|
2896
|
+
if (ancestor.type !== "VariableDeclarator") {
|
|
2897
|
+
return false;
|
|
2898
|
+
}
|
|
2899
|
+
const identifier = asAstNode(ancestor.id);
|
|
2900
|
+
return identifier?.type === "Identifier" && identifier.name === "route";
|
|
2901
|
+
});
|
|
2902
|
+
if (!(routeDeclarator && ancestors.some((ancestor) => ancestor.type === "ExportNamedDeclaration")) || property.type !== "Identifier" || property.name !== "page" && property.name !== "layout" || !chainRootIsDefineRoute(callee.object, bindings, ancestors)) {
|
|
1935
2903
|
return;
|
|
1936
2904
|
}
|
|
1937
|
-
|
|
1938
|
-
|
|
2905
|
+
const args = call.arguments;
|
|
2906
|
+
component = Array.isArray(args) ? asAstNode(args[0]) : null;
|
|
2907
|
+
context.stop();
|
|
2908
|
+
}
|
|
2909
|
+
});
|
|
2910
|
+
return component;
|
|
2911
|
+
}
|
|
2912
|
+
function namedFunction(declaration, name) {
|
|
2913
|
+
if (declaration.type === "FunctionDeclaration") {
|
|
2914
|
+
const identifier = asAstNode(declaration.id);
|
|
2915
|
+
return identifier?.type === "Identifier" && identifier.name === name ? declaration : null;
|
|
2916
|
+
}
|
|
2917
|
+
if (declaration.type === "VariableDeclaration" && Array.isArray(declaration.declarations)) {
|
|
2918
|
+
for (const item of declaration.declarations) {
|
|
2919
|
+
const identifier = asAstNode(item.id);
|
|
2920
|
+
const initializer = asAstNode(item.init);
|
|
2921
|
+
if (identifier?.type === "Identifier" && identifier.name === name && (initializer?.type === "ArrowFunctionExpression" || initializer?.type === "FunctionExpression")) {
|
|
2922
|
+
return initializer;
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
return null;
|
|
2927
|
+
}
|
|
2928
|
+
function localFunction(program, name) {
|
|
2929
|
+
for (const statement of program.body) {
|
|
2930
|
+
const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? asAstNode(statement.declaration) : statement;
|
|
2931
|
+
const component = declaration ? namedFunction(declaration, name) : null;
|
|
2932
|
+
if (component) {
|
|
2933
|
+
return component;
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
return null;
|
|
2937
|
+
}
|
|
2938
|
+
function isImportedBinding(program, name) {
|
|
2939
|
+
return program.body.some((statement) => statement.type === "ImportDeclaration" && statement.importKind !== "type" && statement.specifiers.some((specifier) => specifier.importKind !== "type" && localName2(specifier) === name));
|
|
2940
|
+
}
|
|
2941
|
+
function collectReactWrapperBindings(program) {
|
|
2942
|
+
const bindings = {
|
|
2943
|
+
members: new Set,
|
|
2944
|
+
namespaces: new Set
|
|
2945
|
+
};
|
|
2946
|
+
for (const statement of program.body) {
|
|
2947
|
+
if (statement.type !== "ImportDeclaration" || statement.source.value !== "react") {
|
|
2948
|
+
continue;
|
|
2949
|
+
}
|
|
2950
|
+
for (const specifier of statement.specifiers) {
|
|
2951
|
+
const local = localName2(specifier);
|
|
2952
|
+
if (!local || specifier.importKind === "type") {
|
|
2953
|
+
continue;
|
|
2954
|
+
}
|
|
2955
|
+
const imported = importedName2(specifier);
|
|
2956
|
+
if (specifier.type === "ImportSpecifier" && imported && REACT_COMPONENT_WRAPPERS.has(imported)) {
|
|
2957
|
+
bindings.members.add(local);
|
|
2958
|
+
} else if (specifier.type === "ImportDefaultSpecifier" || specifier.type === "ImportNamespaceSpecifier" || specifier.type === "ImportSpecifier" && imported === "default") {
|
|
2959
|
+
bindings.namespaces.add(local);
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
return bindings;
|
|
2964
|
+
}
|
|
2965
|
+
function wrappedComponentFunction(program, expression, bindings) {
|
|
2966
|
+
if (expression.type === "ArrowFunctionExpression" || expression.type === "FunctionExpression") {
|
|
2967
|
+
return expression;
|
|
2968
|
+
}
|
|
2969
|
+
if (expression.type === "Identifier" && typeof expression.name === "string") {
|
|
2970
|
+
return localFunction(program, expression.name);
|
|
2971
|
+
}
|
|
2972
|
+
if (expression.type !== "CallExpression") {
|
|
2973
|
+
return null;
|
|
2974
|
+
}
|
|
2975
|
+
const callee = asAstNode(expression.callee);
|
|
2976
|
+
const isNamedWrapper = callee?.type === "Identifier" && typeof callee.name === "string" && bindings.members.has(callee.name);
|
|
2977
|
+
const object = callee?.type === "MemberExpression" ? asAstNode(callee.object) : null;
|
|
2978
|
+
const property = callee?.type === "MemberExpression" ? asAstNode(callee.property) : null;
|
|
2979
|
+
const isNamespaceWrapper = callee?.type === "MemberExpression" && callee.computed !== true && object?.type === "Identifier" && typeof object.name === "string" && bindings.namespaces.has(object.name) && property?.type === "Identifier" && typeof property.name === "string" && REACT_COMPONENT_WRAPPERS.has(property.name);
|
|
2980
|
+
if (!(isNamedWrapper || isNamespaceWrapper)) {
|
|
2981
|
+
return null;
|
|
2982
|
+
}
|
|
2983
|
+
const args = expression.arguments;
|
|
2984
|
+
const wrapped = Array.isArray(args) ? asAstNode(args[0]) : null;
|
|
2985
|
+
return wrapped ? wrappedComponentFunction(program, wrapped, bindings) : null;
|
|
2986
|
+
}
|
|
2987
|
+
function importedMemberBinding(program, expression) {
|
|
2988
|
+
let object = expression.type === "MemberExpression" ? asAstNode(expression.object) : null;
|
|
2989
|
+
while (object?.type === "MemberExpression") {
|
|
2990
|
+
object = asAstNode(object.object);
|
|
2991
|
+
}
|
|
2992
|
+
return object?.type === "Identifier" && typeof object.name === "string" && isImportedBinding(program, object.name) ? object.name : null;
|
|
2993
|
+
}
|
|
2994
|
+
function sourceText(code, node) {
|
|
2995
|
+
return node ? code.slice(node.start, node.end) : "";
|
|
2996
|
+
}
|
|
2997
|
+
function unusedIdentifier(program, preferred) {
|
|
2998
|
+
const identifiers = new Set;
|
|
2999
|
+
walk(program, {
|
|
3000
|
+
Identifier(node) {
|
|
3001
|
+
identifiers.add(node.name);
|
|
3002
|
+
}
|
|
3003
|
+
});
|
|
3004
|
+
if (!identifiers.has(preferred)) {
|
|
3005
|
+
return preferred;
|
|
3006
|
+
}
|
|
3007
|
+
let suffix = 1;
|
|
3008
|
+
while (identifiers.has(`${preferred}_${suffix}`)) {
|
|
3009
|
+
suffix += 1;
|
|
3010
|
+
}
|
|
3011
|
+
return `${preferred}_${suffix}`;
|
|
3012
|
+
}
|
|
3013
|
+
function hookCallsiteSignature(code, call, hookName, parent) {
|
|
3014
|
+
let key = parent?.type === "VariableDeclarator" ? sourceText(code, asAstNode(parent.id)) : "";
|
|
3015
|
+
const args = call.arguments;
|
|
3016
|
+
const stateArgument = Array.isArray(args) ? asAstNode(args[0]) : null;
|
|
3017
|
+
const reducerArgument = Array.isArray(args) ? asAstNode(args[1]) : null;
|
|
3018
|
+
if (hookName === "useState" && stateArgument) {
|
|
3019
|
+
key += `(${sourceText(code, stateArgument)})`;
|
|
3020
|
+
} else if (hookName === "useReducer" && reducerArgument) {
|
|
3021
|
+
key += `(${sourceText(code, reducerArgument)})`;
|
|
3022
|
+
}
|
|
3023
|
+
return `${hookName}{${key}}`;
|
|
3024
|
+
}
|
|
3025
|
+
function collectFunctionHookSignature(code, component) {
|
|
3026
|
+
const hooks = [];
|
|
3027
|
+
walk(component, {
|
|
3028
|
+
CallExpression(call, context) {
|
|
3029
|
+
const callNode = call;
|
|
3030
|
+
const name = calledHookName(callNode);
|
|
3031
|
+
if (name) {
|
|
3032
|
+
hooks.push(hookCallsiteSignature(code, callNode, name, asAstNode(context.parent)));
|
|
3033
|
+
}
|
|
3034
|
+
},
|
|
3035
|
+
Function(node, context) {
|
|
3036
|
+
if (node !== component) {
|
|
3037
|
+
context.skip();
|
|
1939
3038
|
}
|
|
1940
3039
|
}
|
|
1941
3040
|
});
|
|
1942
|
-
return
|
|
3041
|
+
return hooks;
|
|
3042
|
+
}
|
|
3043
|
+
function collectClientHookSignature(code, filename) {
|
|
3044
|
+
const lang = detectLangFromPath(filename);
|
|
3045
|
+
const { program } = parseSource(code, lang);
|
|
3046
|
+
const componentExpression = routeComponentExpression(program, collectDefineRouteBindings(program));
|
|
3047
|
+
if (!componentExpression) {
|
|
3048
|
+
return null;
|
|
3049
|
+
}
|
|
3050
|
+
const wrappedComponent = wrappedComponentFunction(program, componentExpression, collectReactWrapperBindings(program));
|
|
3051
|
+
if (wrappedComponent) {
|
|
3052
|
+
return collectFunctionHookSignature(code, wrappedComponent);
|
|
3053
|
+
}
|
|
3054
|
+
if (componentExpression.type !== "Identifier" || typeof componentExpression.name !== "string") {
|
|
3055
|
+
if (importedMemberBinding(program, componentExpression)) {
|
|
3056
|
+
return {
|
|
3057
|
+
end: componentExpression.end,
|
|
3058
|
+
expression: sourceText(code, componentExpression),
|
|
3059
|
+
start: componentExpression.start
|
|
3060
|
+
};
|
|
3061
|
+
}
|
|
3062
|
+
return collectFunctionHookSignature(code, componentExpression);
|
|
3063
|
+
}
|
|
3064
|
+
const component = localFunction(program, componentExpression.name);
|
|
3065
|
+
if (component) {
|
|
3066
|
+
return collectFunctionHookSignature(code, component);
|
|
3067
|
+
}
|
|
3068
|
+
return isImportedBinding(program, componentExpression.name) ? {
|
|
3069
|
+
end: componentExpression.end,
|
|
3070
|
+
expression: componentExpression.name,
|
|
3071
|
+
start: componentExpression.start
|
|
3072
|
+
} : "external";
|
|
1943
3073
|
}
|
|
1944
3074
|
function transformForClient(code, filename) {
|
|
1945
3075
|
const lang = detectLangFromPath(filename);
|
|
@@ -1948,20 +3078,68 @@ function transformForClient(code, filename) {
|
|
|
1948
3078
|
}
|
|
1949
3079
|
const isomorphicResult = transformIsomorphicFunctions(code, filename, "client");
|
|
1950
3080
|
const clientSource = isomorphicResult.code;
|
|
1951
|
-
const {
|
|
1952
|
-
const firstError = diagnostics.find((
|
|
3081
|
+
const { diagnostics, program } = parseSource(clientSource, lang);
|
|
3082
|
+
const firstError = diagnostics.find((diagnostic) => diagnostic.severity === "error");
|
|
1953
3083
|
if (firstError) {
|
|
1954
3084
|
throw new Error(`Failed to parse ${filename}: ${firstError.message}`);
|
|
1955
3085
|
}
|
|
1956
|
-
let
|
|
1957
|
-
const
|
|
3086
|
+
let source = new MagicString(clientSource);
|
|
3087
|
+
const routeBindings = collectDefineRouteBindings(program);
|
|
3088
|
+
const removedRouteCode = removeChainedServerCalls(source, program, routeBindings);
|
|
1958
3089
|
const removedServerCode = isomorphicResult.transformed || removedRouteCode;
|
|
1959
3090
|
if (removedServerCode) {
|
|
1960
|
-
|
|
3091
|
+
source = deadCodeElimination(source, code, lang);
|
|
3092
|
+
}
|
|
3093
|
+
const transformedCode = source.toString();
|
|
3094
|
+
let hookSignature = routeBindings.size > 0 ? collectClientHookSignature(transformedCode, filename) : null;
|
|
3095
|
+
if (hookSignature && typeof hookSignature === "object" && !Array.isArray(hookSignature)) {
|
|
3096
|
+
const createElementBinding = unusedIdentifier(program, "__furinCreateElement");
|
|
3097
|
+
source = new MagicString(transformedCode);
|
|
3098
|
+
source.prepend(`import { createElement as ${createElementBinding} } from "react";
|
|
3099
|
+
`);
|
|
3100
|
+
source.update(hookSignature.start, hookSignature.end, `(import.meta.hot ? (props) => ${createElementBinding}(${hookSignature.expression}, props) : ${hookSignature.expression})`);
|
|
3101
|
+
hookSignature = [];
|
|
3102
|
+
}
|
|
3103
|
+
if (routeBindings.size > 0 && hookSignature !== null) {
|
|
3104
|
+
const originalParse = parseSource(code, lang);
|
|
3105
|
+
const originalError = originalParse.diagnostics.find((diagnostic) => diagnostic.severity === "error");
|
|
3106
|
+
if (originalError) {
|
|
3107
|
+
throw new Error(`Failed to parse ${filename}: ${originalError.message}`);
|
|
3108
|
+
}
|
|
3109
|
+
const hmrDataSignature = createHmrDataSignature(code, originalParse.program, collectDefineRouteBindings(originalParse.program));
|
|
3110
|
+
const signatureValue = Array.isArray(hookSignature) ? JSON.stringify(hookSignature) : 'route.component[Symbol.for("furin.hmr.hook-signature")] ?? [String(route.component)]';
|
|
3111
|
+
source.append(`
|
|
3112
|
+
if (import.meta.hot && route?.component) {
|
|
3113
|
+
const previousDataSignature = ${JSON.stringify(hmrDataSignature)};
|
|
3114
|
+
Object.defineProperty(route, Symbol.for(${JSON.stringify(HMR_DATA_SIGNATURE)}), {
|
|
3115
|
+
configurable: true,
|
|
3116
|
+
value: previousDataSignature,
|
|
3117
|
+
});
|
|
3118
|
+
Object.defineProperty(route.component, Symbol.for("furin.hmr.hook-signature"), {
|
|
3119
|
+
configurable: true,
|
|
3120
|
+
value: ${signatureValue},
|
|
3121
|
+
});
|
|
3122
|
+
import.meta.hot.accept((updatedModule) => {
|
|
3123
|
+
const updatedRoute = updatedModule?.route;
|
|
3124
|
+
if (updatedRoute?.component) {
|
|
3125
|
+
const updatedDataSignature = Reflect.get(
|
|
3126
|
+
updatedRoute,
|
|
3127
|
+
Symbol.for(${JSON.stringify(HMR_DATA_SIGNATURE)})
|
|
3128
|
+
);
|
|
3129
|
+
const dataChanged =
|
|
3130
|
+
previousDataSignature.startsWith("external:") ||
|
|
3131
|
+
typeof updatedDataSignature !== "string" ||
|
|
3132
|
+
updatedDataSignature.startsWith("external:") ||
|
|
3133
|
+
updatedDataSignature !== previousDataSignature;
|
|
3134
|
+
window.__FURIN_HMR_UPDATE__?.(${JSON.stringify(filename)}, updatedRoute.component, dataChanged);
|
|
3135
|
+
}
|
|
3136
|
+
});
|
|
3137
|
+
}
|
|
3138
|
+
`);
|
|
1961
3139
|
}
|
|
1962
3140
|
return {
|
|
1963
|
-
code:
|
|
1964
|
-
map:
|
|
3141
|
+
code: source.toString(),
|
|
3142
|
+
map: source.generateMap({ includeContent: true, source: filename }),
|
|
1965
3143
|
removedServerCode
|
|
1966
3144
|
};
|
|
1967
3145
|
}
|