@barefootjs/hono 0.31.3 → 0.31.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/hono-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,MAAM,EAIX,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAElB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,UAAU,EAEf,UAAU,
|
|
1
|
+
{"version":3,"file":"hono-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/hono-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,MAAM,EAIX,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAElB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,UAAU,EAEf,UAAU,EAQX,MAAM,iBAAiB,CAAA;AAExB;;;;;GAKG;AACH,KAAK,aAAa,GAAG;IACnB,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAGD,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;I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js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
JsxAdapter,
|
|
4
4
|
isBooleanAttr,
|
|
5
5
|
rewriteImportsForTemplate,
|
|
6
|
+
rewriteDynamicImportsInSource,
|
|
6
7
|
emitIRNode,
|
|
7
8
|
emitAttrValue,
|
|
8
9
|
buildLoopChainExpr,
|
|
@@ -53,9 +54,11 @@ class HonoAdapter extends JsxAdapter {
|
|
|
53
54
|
this.scriptAssets = options?.scriptAssets;
|
|
54
55
|
this.preloadAssets = options?.preloadAssets;
|
|
55
56
|
}
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
57
|
+
const reanchor = this.rewriteRelativeImport;
|
|
58
|
+
const withRewrittenDynamicImports = (text) => reanchor && text ? rewriteDynamicImportsInSource(text, reanchor) : text;
|
|
59
|
+
const component = withRewrittenDynamicImports(this.generateComponent(ir));
|
|
60
|
+
const types = withRewrittenDynamicImports(this.generateTypes(ir));
|
|
61
|
+
const moduleConstants = withRewrittenDynamicImports(this.generateModuleScopeDeclarations(ir));
|
|
59
62
|
const componentCode = [moduleConstants, types, component].filter(Boolean).join(`
|
|
60
63
|
`);
|
|
61
64
|
const imports = this.generateImports(ir, componentCode);
|
|
@@ -230,7 +233,8 @@ export default ${this.componentName}` : "";
|
|
|
230
233
|
const noArgDefault = wantsNoArgDefault ? ` = {} as ${propsTypeExpr}` : "";
|
|
231
234
|
const lines = [];
|
|
232
235
|
const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
|
|
233
|
-
|
|
236
|
+
const typeParameters = ir.metadata.typeParameters ?? "";
|
|
237
|
+
lines.push(`${exportPrefix}function ${name}${typeParameters}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
|
|
234
238
|
if (this.hasPreloadAssets()) {
|
|
235
239
|
lines.push(` const __bfInlinePreloads = registerComponentPreloads(${JSON.stringify(this.preloadAssets)})`);
|
|
236
240
|
}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
JsxAdapter,
|
|
4
4
|
isBooleanAttr,
|
|
5
5
|
rewriteImportsForTemplate,
|
|
6
|
+
rewriteDynamicImportsInSource,
|
|
6
7
|
emitIRNode,
|
|
7
8
|
emitAttrValue,
|
|
8
9
|
buildLoopChainExpr,
|
|
@@ -53,9 +54,11 @@ class HonoAdapter extends JsxAdapter {
|
|
|
53
54
|
this.scriptAssets = options?.scriptAssets;
|
|
54
55
|
this.preloadAssets = options?.preloadAssets;
|
|
55
56
|
}
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
57
|
+
const reanchor = this.rewriteRelativeImport;
|
|
58
|
+
const withRewrittenDynamicImports = (text) => reanchor && text ? rewriteDynamicImportsInSource(text, reanchor) : text;
|
|
59
|
+
const component = withRewrittenDynamicImports(this.generateComponent(ir));
|
|
60
|
+
const types = withRewrittenDynamicImports(this.generateTypes(ir));
|
|
61
|
+
const moduleConstants = withRewrittenDynamicImports(this.generateModuleScopeDeclarations(ir));
|
|
59
62
|
const componentCode = [moduleConstants, types, component].filter(Boolean).join(`
|
|
60
63
|
`);
|
|
61
64
|
const imports = this.generateImports(ir, componentCode);
|
|
@@ -230,7 +233,8 @@ export default ${this.componentName}` : "";
|
|
|
230
233
|
const noArgDefault = wantsNoArgDefault ? ` = {} as ${propsTypeExpr}` : "";
|
|
231
234
|
const lines = [];
|
|
232
235
|
const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
|
|
233
|
-
|
|
236
|
+
const typeParameters = ir.metadata.typeParameters ?? "";
|
|
237
|
+
lines.push(`${exportPrefix}function ${name}${typeParameters}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
|
|
234
238
|
if (this.hasPreloadAssets()) {
|
|
235
239
|
lines.push(` const __bfInlinePreloads = registerComponentPreloads(${JSON.stringify(this.preloadAssets)})`);
|
|
236
240
|
}
|
package/dist/vite.js
CHANGED
|
@@ -5,7 +5,7 @@ import { barefoot as coreBarefoot } from "@barefootjs/vite";
|
|
|
5
5
|
import { devModuleUrl, loadManifest, resolveDevOrigin, resolveScriptAssets, toPosixRelative } from "@barefootjs/vite";
|
|
6
6
|
|
|
7
7
|
// ../jsx/src/compiler.ts
|
|
8
|
-
import
|
|
8
|
+
import ts24 from "typescript";
|
|
9
9
|
|
|
10
10
|
// ../jsx/src/analyzer.ts
|
|
11
11
|
import ts9 from "typescript";
|
|
@@ -124,6 +124,20 @@ function templatePartsToJsExpr(parts, opts) {
|
|
|
124
124
|
return result;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
// ../jsx/src/identifier-pattern.ts
|
|
128
|
+
function withUnicodeFlag(flags) {
|
|
129
|
+
return flags.includes("u") ? flags : `${flags}u`;
|
|
130
|
+
}
|
|
131
|
+
function escapeIdentifierForRegex(name) {
|
|
132
|
+
return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
133
|
+
}
|
|
134
|
+
var ID_BOUNDARY_BEFORE = "(?<![\\p{ID_Continue}$])";
|
|
135
|
+
var ID_BOUNDARY_AFTER = "(?![\\p{ID_Continue}$])";
|
|
136
|
+
function identifierPattern(name, flags = "") {
|
|
137
|
+
const esc = escapeIdentifierForRegex(name);
|
|
138
|
+
return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}${ID_BOUNDARY_AFTER}`, withUnicodeFlag(flags));
|
|
139
|
+
}
|
|
140
|
+
|
|
127
141
|
// ../jsx/src/scanner/js-scanner.ts
|
|
128
142
|
import ts2 from "typescript";
|
|
129
143
|
|
|
@@ -240,6 +254,83 @@ function extractFreeIdentifiersFromText(text) {
|
|
|
240
254
|
return extractFreeIdentifiersFromNode(expr);
|
|
241
255
|
}
|
|
242
256
|
|
|
257
|
+
// ../jsx/src/scope/binding-scope.ts
|
|
258
|
+
class BindingScope {
|
|
259
|
+
frames;
|
|
260
|
+
static EMPTY = new BindingScope([]);
|
|
261
|
+
constructor(frames) {
|
|
262
|
+
this.frames = frames;
|
|
263
|
+
}
|
|
264
|
+
enterLoopRow(loop) {
|
|
265
|
+
const bindings = new Map;
|
|
266
|
+
if (loop.paramBindings && loop.paramBindings.length > 0) {
|
|
267
|
+
for (const b of loop.paramBindings)
|
|
268
|
+
bindings.set(b.name, { source: "destructure" });
|
|
269
|
+
} else {
|
|
270
|
+
bindings.set(loop.param, { source: "item" });
|
|
271
|
+
}
|
|
272
|
+
if (loop.index != null)
|
|
273
|
+
bindings.set(loop.index, { source: "index" });
|
|
274
|
+
for (const name of loop.preamble?.declaredNames ?? [])
|
|
275
|
+
bindings.set(name, { source: "preamble" });
|
|
276
|
+
const frame = { kind: "loop-row", bindings };
|
|
277
|
+
return new BindingScope([frame, ...this.frames]);
|
|
278
|
+
}
|
|
279
|
+
enterCallback(params) {
|
|
280
|
+
const bindings = new Map;
|
|
281
|
+
for (const name of params)
|
|
282
|
+
bindings.set(name, { source: "param" });
|
|
283
|
+
const frame = { kind: "callback", bindings };
|
|
284
|
+
return new BindingScope([frame, ...this.frames]);
|
|
285
|
+
}
|
|
286
|
+
isBound(name) {
|
|
287
|
+
for (const frame of this.frames) {
|
|
288
|
+
if (frame.bindings.has(name))
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
lookup(name) {
|
|
294
|
+
for (let depth = 0;depth < this.frames.length; depth++) {
|
|
295
|
+
const frame = this.frames[depth];
|
|
296
|
+
const binding = frame.bindings.get(name);
|
|
297
|
+
if (binding)
|
|
298
|
+
return { depth, frame, binding };
|
|
299
|
+
}
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
boundNames() {
|
|
303
|
+
if (this.boundNamesCache)
|
|
304
|
+
return this.boundNamesCache;
|
|
305
|
+
const names = new Set;
|
|
306
|
+
for (const frame of this.frames) {
|
|
307
|
+
for (const name of frame.bindings.keys())
|
|
308
|
+
names.add(name);
|
|
309
|
+
}
|
|
310
|
+
this.boundNamesCache = names;
|
|
311
|
+
return names;
|
|
312
|
+
}
|
|
313
|
+
boundNamesCache;
|
|
314
|
+
valueBoundNamesCache;
|
|
315
|
+
valueBoundNames() {
|
|
316
|
+
if (this.valueBoundNamesCache)
|
|
317
|
+
return this.valueBoundNamesCache;
|
|
318
|
+
const names = new Set;
|
|
319
|
+
for (const frame of this.frames) {
|
|
320
|
+
for (const [name, binding] of frame.bindings) {
|
|
321
|
+
if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
|
|
322
|
+
names.add(name);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
this.valueBoundNamesCache = names;
|
|
327
|
+
return names;
|
|
328
|
+
}
|
|
329
|
+
asShadowPredicate() {
|
|
330
|
+
return (name) => this.isBound(name);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
243
334
|
// ../jsx/src/ir-to-client-js/html-template.ts
|
|
244
335
|
var VOID_ELEMENTS = new Set([
|
|
245
336
|
"area",
|
|
@@ -611,7 +702,7 @@ var REACTIVE_PRIMITIVES = new Set([
|
|
|
611
702
|
]);
|
|
612
703
|
|
|
613
704
|
// ../jsx/src/jsx-to-ir.ts
|
|
614
|
-
import
|
|
705
|
+
import ts13 from "typescript";
|
|
615
706
|
|
|
616
707
|
// ../jsx/src/types.ts
|
|
617
708
|
var SCOPE_FORBIDDEN = {
|
|
@@ -647,6 +738,7 @@ var REACTIVE_BINDING_KINDS = new Set([
|
|
|
647
738
|
]);
|
|
648
739
|
|
|
649
740
|
// ../jsx/src/module-exports.ts
|
|
741
|
+
import ts10 from "typescript";
|
|
650
742
|
function formatParamWithType(p) {
|
|
651
743
|
const rest = p.isRest ? "..." : "";
|
|
652
744
|
const optional = p.optional ? "?" : "";
|
|
@@ -660,7 +752,7 @@ function findReachableNames(primaryRefs, declarations) {
|
|
|
660
752
|
const reachable = new Set;
|
|
661
753
|
const queue = [];
|
|
662
754
|
for (const name of allNames) {
|
|
663
|
-
if (
|
|
755
|
+
if (identifierPattern(name).test(primaryRefs)) {
|
|
664
756
|
reachable.add(name);
|
|
665
757
|
queue.push(name);
|
|
666
758
|
}
|
|
@@ -669,7 +761,7 @@ function findReachableNames(primaryRefs, declarations) {
|
|
|
669
761
|
const current = queue.shift();
|
|
670
762
|
const body = bodyMap.get(current) || "";
|
|
671
763
|
for (const name of allNames) {
|
|
672
|
-
if (!reachable.has(name) &&
|
|
764
|
+
if (!reachable.has(name) && identifierPattern(name).test(body)) {
|
|
673
765
|
reachable.add(name);
|
|
674
766
|
queue.push(name);
|
|
675
767
|
}
|
|
@@ -677,12 +769,55 @@ function findReachableNames(primaryRefs, declarations) {
|
|
|
677
769
|
}
|
|
678
770
|
return reachable;
|
|
679
771
|
}
|
|
772
|
+
function findAssignedNames(bodyText, candidates) {
|
|
773
|
+
const assigned = new Set;
|
|
774
|
+
if (candidates.size === 0)
|
|
775
|
+
return assigned;
|
|
776
|
+
const sf = ts10.createSourceFile("bf-assignment-scan.tsx", bodyText, ts10.ScriptTarget.Latest, false, ts10.ScriptKind.TSX);
|
|
777
|
+
const record = (target) => {
|
|
778
|
+
if (ts10.isIdentifier(target) && candidates.has(target.text)) {
|
|
779
|
+
assigned.add(target.text);
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
const visit = (node) => {
|
|
783
|
+
if (ts10.isBinaryExpression(node) && isAssignmentOperator(node.operatorToken.kind)) {
|
|
784
|
+
record(node.left);
|
|
785
|
+
} else if ((ts10.isPrefixUnaryExpression(node) || ts10.isPostfixUnaryExpression(node)) && (node.operator === ts10.SyntaxKind.PlusPlusToken || node.operator === ts10.SyntaxKind.MinusMinusToken)) {
|
|
786
|
+
record(node.operand);
|
|
787
|
+
}
|
|
788
|
+
ts10.forEachChild(node, visit);
|
|
789
|
+
};
|
|
790
|
+
ts10.forEachChild(sf, visit);
|
|
791
|
+
return assigned;
|
|
792
|
+
}
|
|
793
|
+
function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNames) {
|
|
794
|
+
let reachable = findReachableNames(primaryRefs, declarations);
|
|
795
|
+
if (mutableNames.size === 0)
|
|
796
|
+
return reachable;
|
|
797
|
+
let seedText = primaryRefs;
|
|
798
|
+
for (let round = 0;round <= declarations.length; round++) {
|
|
799
|
+
const survivingMutables = new Set([...reachable].filter((name) => mutableNames.has(name)));
|
|
800
|
+
if (survivingMutables.size === 0)
|
|
801
|
+
return reachable;
|
|
802
|
+
const added = declarations.filter((d) => !reachable.has(d.name)).filter((d) => findAssignedNames(d.body, survivingMutables).size > 0).map((d) => d.name);
|
|
803
|
+
if (added.length === 0)
|
|
804
|
+
return reachable;
|
|
805
|
+
seedText += `
|
|
806
|
+
` + added.join(`
|
|
807
|
+
`);
|
|
808
|
+
reachable = findReachableNames(seedText, declarations);
|
|
809
|
+
}
|
|
810
|
+
return reachable;
|
|
811
|
+
}
|
|
812
|
+
function isAssignmentOperator(kind) {
|
|
813
|
+
return kind >= ts10.SyntaxKind.FirstAssignment && kind <= ts10.SyntaxKind.LastAssignment;
|
|
814
|
+
}
|
|
680
815
|
|
|
681
816
|
// ../jsx/src/reactivity-checker.ts
|
|
682
|
-
import
|
|
817
|
+
import ts11 from "typescript";
|
|
683
818
|
|
|
684
819
|
// ../jsx/src/free-refs.ts
|
|
685
|
-
import
|
|
820
|
+
import ts12 from "typescript";
|
|
686
821
|
var _bindingMapCache = new WeakMap;
|
|
687
822
|
|
|
688
823
|
// ../jsx/src/to-locale-date-lowering.ts
|
|
@@ -1000,83 +1135,6 @@ var toLocaleDatePlugin = {
|
|
|
1000
1135
|
}
|
|
1001
1136
|
};
|
|
1002
1137
|
|
|
1003
|
-
// ../jsx/src/scope/binding-scope.ts
|
|
1004
|
-
class BindingScope {
|
|
1005
|
-
frames;
|
|
1006
|
-
static EMPTY = new BindingScope([]);
|
|
1007
|
-
constructor(frames) {
|
|
1008
|
-
this.frames = frames;
|
|
1009
|
-
}
|
|
1010
|
-
enterLoopRow(loop) {
|
|
1011
|
-
const bindings = new Map;
|
|
1012
|
-
if (loop.paramBindings && loop.paramBindings.length > 0) {
|
|
1013
|
-
for (const b of loop.paramBindings)
|
|
1014
|
-
bindings.set(b.name, { source: "destructure" });
|
|
1015
|
-
} else {
|
|
1016
|
-
bindings.set(loop.param, { source: "item" });
|
|
1017
|
-
}
|
|
1018
|
-
if (loop.index != null)
|
|
1019
|
-
bindings.set(loop.index, { source: "index" });
|
|
1020
|
-
for (const name of loop.preamble?.declaredNames ?? [])
|
|
1021
|
-
bindings.set(name, { source: "preamble" });
|
|
1022
|
-
const frame = { kind: "loop-row", bindings };
|
|
1023
|
-
return new BindingScope([frame, ...this.frames]);
|
|
1024
|
-
}
|
|
1025
|
-
enterCallback(params) {
|
|
1026
|
-
const bindings = new Map;
|
|
1027
|
-
for (const name of params)
|
|
1028
|
-
bindings.set(name, { source: "param" });
|
|
1029
|
-
const frame = { kind: "callback", bindings };
|
|
1030
|
-
return new BindingScope([frame, ...this.frames]);
|
|
1031
|
-
}
|
|
1032
|
-
isBound(name) {
|
|
1033
|
-
for (const frame of this.frames) {
|
|
1034
|
-
if (frame.bindings.has(name))
|
|
1035
|
-
return true;
|
|
1036
|
-
}
|
|
1037
|
-
return false;
|
|
1038
|
-
}
|
|
1039
|
-
lookup(name) {
|
|
1040
|
-
for (let depth = 0;depth < this.frames.length; depth++) {
|
|
1041
|
-
const frame = this.frames[depth];
|
|
1042
|
-
const binding = frame.bindings.get(name);
|
|
1043
|
-
if (binding)
|
|
1044
|
-
return { depth, frame, binding };
|
|
1045
|
-
}
|
|
1046
|
-
return null;
|
|
1047
|
-
}
|
|
1048
|
-
boundNames() {
|
|
1049
|
-
if (this.boundNamesCache)
|
|
1050
|
-
return this.boundNamesCache;
|
|
1051
|
-
const names = new Set;
|
|
1052
|
-
for (const frame of this.frames) {
|
|
1053
|
-
for (const name of frame.bindings.keys())
|
|
1054
|
-
names.add(name);
|
|
1055
|
-
}
|
|
1056
|
-
this.boundNamesCache = names;
|
|
1057
|
-
return names;
|
|
1058
|
-
}
|
|
1059
|
-
boundNamesCache;
|
|
1060
|
-
valueBoundNamesCache;
|
|
1061
|
-
valueBoundNames() {
|
|
1062
|
-
if (this.valueBoundNamesCache)
|
|
1063
|
-
return this.valueBoundNamesCache;
|
|
1064
|
-
const names = new Set;
|
|
1065
|
-
for (const frame of this.frames) {
|
|
1066
|
-
for (const [name, binding] of frame.bindings) {
|
|
1067
|
-
if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
|
|
1068
|
-
names.add(name);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
this.valueBoundNamesCache = names;
|
|
1073
|
-
return names;
|
|
1074
|
-
}
|
|
1075
|
-
asShadowPredicate() {
|
|
1076
|
-
return (name) => this.isBound(name);
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
1138
|
// ../jsx/src/jsx-to-ir.ts
|
|
1081
1139
|
var EMPTY_BOUND = new Set;
|
|
1082
1140
|
var constInitializerCache = new WeakMap;
|
|
@@ -1173,13 +1231,13 @@ var KEYWORDS_AND_GLOBALS = new Set([
|
|
|
1173
1231
|
]);
|
|
1174
1232
|
|
|
1175
1233
|
// ../jsx/src/ir-to-client-js/walk-prop-accesses.ts
|
|
1176
|
-
import
|
|
1234
|
+
import ts14 from "typescript";
|
|
1177
1235
|
|
|
1178
1236
|
// ../jsx/src/value-references.ts
|
|
1179
|
-
import
|
|
1237
|
+
import ts15 from "typescript";
|
|
1180
1238
|
|
|
1181
1239
|
// ../jsx/src/relocate.ts
|
|
1182
|
-
import
|
|
1240
|
+
import ts16 from "typescript";
|
|
1183
1241
|
|
|
1184
1242
|
// ../jsx/src/lowering-registry.ts
|
|
1185
1243
|
var plugins = [];
|
|
@@ -1358,10 +1416,10 @@ function formatDateLocalNames(metadata) {
|
|
|
1358
1416
|
}
|
|
1359
1417
|
|
|
1360
1418
|
// ../jsx/src/ir-to-client-js/prune-unused-prop-extractions.ts
|
|
1361
|
-
import
|
|
1419
|
+
import ts17 from "typescript";
|
|
1362
1420
|
|
|
1363
1421
|
// ../jsx/src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
|
|
1364
|
-
import
|
|
1422
|
+
import ts18 from "typescript";
|
|
1365
1423
|
var NO_PREAMBLE = {
|
|
1366
1424
|
lazySafe: true,
|
|
1367
1425
|
facts: { declaredNames: new Set, freeNames: new Set }
|
|
@@ -1411,7 +1469,7 @@ var INERT_BINDING_GLOBALS = new Set([
|
|
|
1411
1469
|
]);
|
|
1412
1470
|
|
|
1413
1471
|
// ../jsx/src/ir-to-client-js/emit-reactive.ts
|
|
1414
|
-
import
|
|
1472
|
+
import ts19 from "typescript";
|
|
1415
1473
|
|
|
1416
1474
|
// ../jsx/src/ir-to-client-js/control-flow/stringify/event-delegation.ts
|
|
1417
1475
|
var NON_BUBBLING_EVENTS = new Set([
|
|
@@ -1426,7 +1484,7 @@ var NON_BUBBLING_EVENTS = new Set([
|
|
|
1426
1484
|
]);
|
|
1427
1485
|
|
|
1428
1486
|
// ../jsx/src/ir-to-client-js/rewrite-props-object.ts
|
|
1429
|
-
import
|
|
1487
|
+
import ts20 from "typescript";
|
|
1430
1488
|
|
|
1431
1489
|
// ../jsx/src/ir-to-client-js/source-map.ts
|
|
1432
1490
|
var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
@@ -1517,20 +1575,20 @@ class SourceMapGenerator {
|
|
|
1517
1575
|
}
|
|
1518
1576
|
|
|
1519
1577
|
// ../jsx/src/preprocess-inline-jsx-callbacks.ts
|
|
1520
|
-
import
|
|
1578
|
+
import ts21 from "typescript";
|
|
1521
1579
|
|
|
1522
1580
|
// ../jsx/src/ssr-defaults.ts
|
|
1523
|
-
import
|
|
1581
|
+
import ts22 from "typescript";
|
|
1524
1582
|
var UNRESOLVED = Symbol("unresolved");
|
|
1525
1583
|
var NO_RETURN = Symbol("no-return");
|
|
1526
1584
|
|
|
1527
1585
|
// ../jsx/src/augment-inherited-props.ts
|
|
1528
|
-
import
|
|
1586
|
+
import ts23 from "typescript";
|
|
1529
1587
|
|
|
1530
1588
|
// ../jsx/src/rich-type-refusal.ts
|
|
1531
1589
|
var EMPTY_BINDINGS2 = new Map;
|
|
1532
1590
|
// ../jsx/src/shared-program.ts
|
|
1533
|
-
import
|
|
1591
|
+
import ts25 from "typescript";
|
|
1534
1592
|
// ../jsx/src/adapters/interface.ts
|
|
1535
1593
|
class BaseAdapter {
|
|
1536
1594
|
renderChildren(children) {
|
|
@@ -1583,7 +1641,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
1583
1641
|
...localFunctions.map((f) => ({ name: f.name, body: f.body })),
|
|
1584
1642
|
...localConstants.map((c) => ({ name: c.name, body: c.value }))
|
|
1585
1643
|
];
|
|
1586
|
-
const reachable =
|
|
1644
|
+
const reachable = closeOverWritersOfMutableBindings(primaryRefText, declarations, new Set(ir.metadata.localConstants.filter((c) => (c.declarationKind ?? "const") !== "const").map((c) => c.name)));
|
|
1587
1645
|
const reachableBodies = [...reachable].map((name) => {
|
|
1588
1646
|
const func = localFunctions.find((f) => f.name === name);
|
|
1589
1647
|
if (func)
|
|
@@ -1613,9 +1671,10 @@ class JsxAdapter extends BaseAdapter {
|
|
|
1613
1671
|
lines.push(` const ${signal.getter} = () => ${initialValue}`);
|
|
1614
1672
|
}
|
|
1615
1673
|
if (signal.setter) {
|
|
1616
|
-
const setterUsed =
|
|
1674
|
+
const setterUsed = identifierPattern(signal.setter).test(setterRefText);
|
|
1617
1675
|
if (setterUsed) {
|
|
1618
|
-
|
|
1676
|
+
const setterType = preserveTypes && signal.type.kind !== "unknown" ? `(valueOrFn: ${signal.type.raw} | ((prev: ${signal.type.raw}) => ${signal.type.raw})) => void` : null;
|
|
1677
|
+
lines.push(setterType ? ` const ${signal.setter}: ${setterType} = () => {}` : ` const ${signal.setter} = (..._args: any[]) => {}`);
|
|
1619
1678
|
}
|
|
1620
1679
|
}
|
|
1621
1680
|
}
|
|
@@ -1811,6 +1870,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
1811
1870
|
}
|
|
1812
1871
|
|
|
1813
1872
|
// ../jsx/src/adapters/template-imports.ts
|
|
1873
|
+
import ts26 from "typescript";
|
|
1814
1874
|
var CLIENT_PACKAGE_SOURCES = new Set([
|
|
1815
1875
|
"@barefootjs/client",
|
|
1816
1876
|
"@barefootjs/client/runtime"
|
|
@@ -1857,6 +1917,44 @@ function rewriteImportsForTemplate(imports, shimSource, rewriteRelative) {
|
|
|
1857
1917
|
function specKey(s) {
|
|
1858
1918
|
return `${s.isDefault ? "d" : ""}${s.isNamespace ? "n" : ""}:${s.name}:${s.alias ?? ""}`;
|
|
1859
1919
|
}
|
|
1920
|
+
function rewriteDynamicImportsInSource(sourceText, rewriteRelative) {
|
|
1921
|
+
if (!sourceText.includes("import"))
|
|
1922
|
+
return sourceText;
|
|
1923
|
+
const sf = ts26.createSourceFile("bf-template-fragment.tsx", sourceText, ts26.ScriptTarget.Latest, false, ts26.ScriptKind.TSX);
|
|
1924
|
+
const edits = [];
|
|
1925
|
+
const visit = (node) => {
|
|
1926
|
+
if (ts26.isCallExpression(node) && node.expression.kind === ts26.SyntaxKind.ImportKeyword && node.arguments.length > 0 && ts26.isStringLiteralLike(node.arguments[0])) {
|
|
1927
|
+
collect(node.arguments[0]);
|
|
1928
|
+
}
|
|
1929
|
+
if (ts26.isImportTypeNode(node) && ts26.isLiteralTypeNode(node.argument)) {
|
|
1930
|
+
const literal = node.argument.literal;
|
|
1931
|
+
if (ts26.isStringLiteralLike(literal))
|
|
1932
|
+
collect(literal);
|
|
1933
|
+
}
|
|
1934
|
+
ts26.forEachChild(node, visit);
|
|
1935
|
+
};
|
|
1936
|
+
const collect = (literal) => {
|
|
1937
|
+
const specifier = literal.text;
|
|
1938
|
+
if (!specifier.startsWith("."))
|
|
1939
|
+
return;
|
|
1940
|
+
const next = rewriteRelative(specifier);
|
|
1941
|
+
if (next === specifier)
|
|
1942
|
+
return;
|
|
1943
|
+
edits.push({
|
|
1944
|
+
start: literal.getStart(sf),
|
|
1945
|
+
end: literal.getEnd(),
|
|
1946
|
+
text: `'${next}'`
|
|
1947
|
+
});
|
|
1948
|
+
};
|
|
1949
|
+
ts26.forEachChild(sf, visit);
|
|
1950
|
+
if (edits.length === 0)
|
|
1951
|
+
return sourceText;
|
|
1952
|
+
let out = sourceText;
|
|
1953
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) {
|
|
1954
|
+
out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
|
|
1955
|
+
}
|
|
1956
|
+
return out;
|
|
1957
|
+
}
|
|
1860
1958
|
|
|
1861
1959
|
// ../jsx/src/adapters/test-adapter.ts
|
|
1862
1960
|
class TestAdapter extends JsxAdapter {
|
|
@@ -1949,7 +2047,8 @@ export default ${this.componentName}` : "";
|
|
|
1949
2047
|
const noArgDefault = hasRequiredProps ? "" : ` = {} as ${propsTypeExpr}`;
|
|
1950
2048
|
const lines = [];
|
|
1951
2049
|
const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
|
|
1952
|
-
|
|
2050
|
+
const typeParameters = ir.metadata.typeParameters ?? "";
|
|
2051
|
+
lines.push(`${exportPrefix}function ${name}${typeParameters}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
|
|
1953
2052
|
if (hasClientInteractivity) {
|
|
1954
2053
|
lines.push(` const __scopeId = (/_s\\d/.test(__bfScope || '') ? __bfScope : null) || __instanceId || \`${name}_\${Math.random().toString(36).slice(2, 8)}\``);
|
|
1955
2054
|
} else {
|
|
@@ -2255,11 +2354,11 @@ function emitAttrValue(value, emitter, name) {
|
|
|
2255
2354
|
}
|
|
2256
2355
|
}
|
|
2257
2356
|
// ../jsx/src/combine-client-js.ts
|
|
2258
|
-
import
|
|
2357
|
+
import ts27 from "typescript";
|
|
2259
2358
|
// ../jsx/src/debug.ts
|
|
2260
|
-
import
|
|
2359
|
+
import ts28 from "typescript";
|
|
2261
2360
|
// ../jsx/src/profiler.ts
|
|
2262
|
-
import
|
|
2361
|
+
import ts29 from "typescript";
|
|
2263
2362
|
|
|
2264
2363
|
// ../jsx/src/index.ts
|
|
2265
2364
|
registerBuiltinLoweringPlugins();
|
|
@@ -2309,9 +2408,11 @@ class HonoAdapter extends JsxAdapter {
|
|
|
2309
2408
|
this.scriptAssets = options?.scriptAssets;
|
|
2310
2409
|
this.preloadAssets = options?.preloadAssets;
|
|
2311
2410
|
}
|
|
2312
|
-
const
|
|
2313
|
-
const
|
|
2314
|
-
const
|
|
2411
|
+
const reanchor = this.rewriteRelativeImport;
|
|
2412
|
+
const withRewrittenDynamicImports = (text) => reanchor && text ? rewriteDynamicImportsInSource(text, reanchor) : text;
|
|
2413
|
+
const component = withRewrittenDynamicImports(this.generateComponent(ir));
|
|
2414
|
+
const types = withRewrittenDynamicImports(this.generateTypes(ir));
|
|
2415
|
+
const moduleConstants = withRewrittenDynamicImports(this.generateModuleScopeDeclarations(ir));
|
|
2315
2416
|
const componentCode = [moduleConstants, types, component].filter(Boolean).join(`
|
|
2316
2417
|
`);
|
|
2317
2418
|
const imports = this.generateImports(ir, componentCode);
|
|
@@ -2486,7 +2587,8 @@ export default ${this.componentName}` : "";
|
|
|
2486
2587
|
const noArgDefault = wantsNoArgDefault ? ` = {} as ${propsTypeExpr}` : "";
|
|
2487
2588
|
const lines = [];
|
|
2488
2589
|
const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
|
|
2489
|
-
|
|
2590
|
+
const typeParameters = ir.metadata.typeParameters ?? "";
|
|
2591
|
+
lines.push(`${exportPrefix}function ${name}${typeParameters}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
|
|
2490
2592
|
if (this.hasPreloadAssets()) {
|
|
2491
2593
|
lines.push(` const __bfInlinePreloads = registerComponentPreloads(${JSON.stringify(this.preloadAssets)})`);
|
|
2492
2594
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/hono",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.5",
|
|
4
4
|
"description": "Hono integration for BarefootJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
124
|
"@barefootjs/adapter-tests": "0.1.0",
|
|
125
|
-
"@barefootjs/vite": "0.31.
|
|
125
|
+
"@barefootjs/vite": "0.31.5",
|
|
126
126
|
"@types/jsdom": "^27.0.0",
|
|
127
127
|
"hono": "^4.6.0",
|
|
128
128
|
"jsdom": "^27.3.0",
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
JsxAdapter,
|
|
32
32
|
isBooleanAttr,
|
|
33
33
|
rewriteImportsForTemplate,
|
|
34
|
+
rewriteDynamicImportsInSource,
|
|
34
35
|
emitIRNode,
|
|
35
36
|
emitAttrValue,
|
|
36
37
|
buildLoopChainExpr,
|
|
@@ -195,9 +196,19 @@ export class HonoAdapter extends JsxAdapter implements IRNodeEmitter<HonoRenderC
|
|
|
195
196
|
// `generateModuleScopeDeclarations`; they join the scan text so a
|
|
196
197
|
// helper referenced only from a hoisted declaration still pulls its
|
|
197
198
|
// import.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
// Re-anchor relative specifiers that ride along INSIDE emitted source
|
|
200
|
+
// text — dynamic `import('./x')` and `typeof import('./x')` — which
|
|
201
|
+
// never reach `metadata.templateImports` and so are invisible to
|
|
202
|
+
// `rewriteImportsForTemplate` below (#2588). Applied to every section
|
|
203
|
+
// that can carry verbatim source: module-scope declarations, the
|
|
204
|
+
// component body's local handlers, and type declarations.
|
|
205
|
+
const reanchor = this.rewriteRelativeImport
|
|
206
|
+
const withRewrittenDynamicImports = <T extends string | null>(text: T): T =>
|
|
207
|
+
reanchor && text ? (rewriteDynamicImportsInSource(text, reanchor) as T) : text
|
|
208
|
+
|
|
209
|
+
const component = withRewrittenDynamicImports(this.generateComponent(ir))
|
|
210
|
+
const types = withRewrittenDynamicImports(this.generateTypes(ir))
|
|
211
|
+
const moduleConstants = withRewrittenDynamicImports(this.generateModuleScopeDeclarations(ir))
|
|
201
212
|
const componentCode = [moduleConstants, types, component].filter(Boolean).join('\n')
|
|
202
213
|
const imports = this.generateImports(ir, componentCode)
|
|
203
214
|
|
|
@@ -545,7 +556,12 @@ export class HonoAdapter extends JsxAdapter implements IRNodeEmitter<HonoRenderC
|
|
|
545
556
|
// Module-export keyword belongs to the adapter: it knows the target language
|
|
546
557
|
// and whether the source declared the component as exported.
|
|
547
558
|
const exportPrefix = ir.metadata.isExported === false ? '' : 'export '
|
|
548
|
-
|
|
559
|
+
// A generic component's props type (and often its body) keeps
|
|
560
|
+
// referencing the source's type parameter names verbatim — the
|
|
561
|
+
// function's own declaration must carry them too, or those references
|
|
562
|
+
// are unresolved names in the emitted `.tsx` (TS2304, xyflow's `Flow`).
|
|
563
|
+
const typeParameters = ir.metadata.typeParameters ?? ''
|
|
564
|
+
lines.push(`${exportPrefix}function ${name}${typeParameters}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`)
|
|
549
565
|
|
|
550
566
|
// Vite-pipeline script registration (see `scriptAssets`'s field
|
|
551
567
|
// docstring): register this call's resolved URLs against the request
|