@barefootjs/cli 0.5.2 → 0.5.3
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/index.js +317 -129
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -518,6 +518,19 @@ function buildChainedArrayExpr(elem) {
|
|
|
518
518
|
chainOrder: elem.chainOrder
|
|
519
519
|
});
|
|
520
520
|
}
|
|
521
|
+
function loopOffsetTerms(offset) {
|
|
522
|
+
if (!offset) return [];
|
|
523
|
+
const terms = [];
|
|
524
|
+
if (offset.staticCount) terms.push(String(offset.staticCount));
|
|
525
|
+
terms.push(...offset.dynamicTerms);
|
|
526
|
+
return terms;
|
|
527
|
+
}
|
|
528
|
+
function buildLoopChildIndexExpr(indexParam, offset) {
|
|
529
|
+
return [indexParam, ...loopOffsetTerms(offset)].join(" + ");
|
|
530
|
+
}
|
|
531
|
+
function buildLoopChildIndexSubtraction(offset) {
|
|
532
|
+
return loopOffsetTerms(offset).map((term) => ` - ${term}`).join("");
|
|
533
|
+
}
|
|
521
534
|
function toDomEventName(eventName) {
|
|
522
535
|
return jsxToDomEventMap[eventName] ?? eventName;
|
|
523
536
|
}
|
|
@@ -1274,16 +1287,28 @@ function maybeHoistedScopeAttr(inHoistedChildren, node) {
|
|
|
1274
1287
|
return inHoistedChildren && node.needsScope ? `${BF_SCOPE}="${BF_PARENT_SCOPE_PLACEHOLDER}"` : null;
|
|
1275
1288
|
}
|
|
1276
1289
|
function templateAttrExpr(attrName, valExpr, presenceOrUndefined) {
|
|
1290
|
+
if (attrName === "dangerouslySetInnerHTML") return "";
|
|
1277
1291
|
if (isBooleanAttr(attrName) || presenceOrUndefined) {
|
|
1278
1292
|
return `\${${valExpr} ? '${attrName}' : ''}`;
|
|
1279
1293
|
}
|
|
1280
1294
|
if (attrName === "style") {
|
|
1281
|
-
return `\${((v) => v != null ? 'style="' + v + '"' : '')(styleToCss(${valExpr}))}`;
|
|
1295
|
+
return `\${((v) => v != null ? 'style="' + ${escapeAttrValueExpr("v")} + '"' : '')(styleToCss(${valExpr}))}`;
|
|
1282
1296
|
}
|
|
1283
1297
|
if (attrName === "data-key" || attrName.startsWith("data-key-")) {
|
|
1284
1298
|
return `${attrName}="\${${valExpr}}"`;
|
|
1285
1299
|
}
|
|
1286
|
-
return `\${(${valExpr}) != null ? '${attrName}="' +
|
|
1300
|
+
return `\${(${valExpr}) != null ? '${attrName}="' + ${escapeAttrValueExpr(valExpr)} + '"' : ''}`;
|
|
1301
|
+
}
|
|
1302
|
+
function escapeAttrValueExpr(valExpr) {
|
|
1303
|
+
return `escapeAttr(${valExpr})`;
|
|
1304
|
+
}
|
|
1305
|
+
function escapeTextSlotExpr(innerExpr) {
|
|
1306
|
+
return `escapeText(${innerExpr})`;
|
|
1307
|
+
}
|
|
1308
|
+
function dangerouslyHtmlChildren(attrs, toExpr) {
|
|
1309
|
+
const attr = attrs.find((a) => a.name === "dangerouslySetInnerHTML");
|
|
1310
|
+
if (!attr || attr.value.kind !== "expression") return null;
|
|
1311
|
+
return `\${((${toExpr(attr.value)}) ?? {}).__html ?? ''}`;
|
|
1287
1312
|
}
|
|
1288
1313
|
function transformKeyValue(value, transformExpr) {
|
|
1289
1314
|
switch (value.kind) {
|
|
@@ -1328,6 +1353,7 @@ function renderTemplateAttrPart(attr, attrName, wrap, restSpreadNames) {
|
|
|
1328
1353
|
function isMergeableAttr(a, ctx2) {
|
|
1329
1354
|
if (ctx2.honorClientOnly && a.clientOnly) return false;
|
|
1330
1355
|
if (a.name === "key") return false;
|
|
1356
|
+
if (a.name === "dangerouslySetInnerHTML") return false;
|
|
1331
1357
|
const v = a.value;
|
|
1332
1358
|
if (v.kind === "jsx-children") return false;
|
|
1333
1359
|
if (v.kind === "boolean-shorthand") return false;
|
|
@@ -1415,7 +1441,7 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
|
|
|
1415
1441
|
}
|
|
1416
1442
|
const attrs = attrParts.join(" ");
|
|
1417
1443
|
const childrenRecurse = (n) => irToHtmlTemplate(n, restSpreadNames, loopDepth, loopParams, branchSlotsVar, insideLoop, false);
|
|
1418
|
-
const children = node.children.map(childrenRecurse).join("");
|
|
1444
|
+
const children = dangerouslyHtmlChildren(node.attrs, (v) => wrapExpr(v.expr)) ?? node.children.map(childrenRecurse).join("");
|
|
1419
1445
|
if (children || !VOID_ELEMENTS.has(node.tag)) {
|
|
1420
1446
|
return `<${node.tag}${attrs ? " " + attrs : ""}>${children}</${node.tag}>`;
|
|
1421
1447
|
}
|
|
@@ -1426,7 +1452,9 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
|
|
|
1426
1452
|
case "expression":
|
|
1427
1453
|
if (node.expr === "null" || node.expr === "undefined") return "";
|
|
1428
1454
|
if (node.slotId) {
|
|
1429
|
-
|
|
1455
|
+
const inner = wrapInterpolation(wrapExpr(node.expr));
|
|
1456
|
+
const slotted = branchSlotsVar ? inner : escapeTextSlotExpr(inner);
|
|
1457
|
+
return `<!--bf:${node.slotId}-->\${${slotted}}<!--/-->`;
|
|
1430
1458
|
}
|
|
1431
1459
|
return `\${${wrapInterpolation(wrapExpr(node.expr))}}`;
|
|
1432
1460
|
case "conditional": {
|
|
@@ -1522,7 +1550,7 @@ function irToPlaceholderTemplate(node, restSpreadNames, loopDepth = 0, loopParam
|
|
|
1522
1550
|
attrParts.push(`bf="${node.slotId}"`);
|
|
1523
1551
|
}
|
|
1524
1552
|
const attrs = attrParts.join(" ");
|
|
1525
|
-
const children = node.children.map(recurse).join("");
|
|
1553
|
+
const children = dangerouslyHtmlChildren(node.attrs, (v) => wrapExpr(v.expr)) ?? node.children.map(recurse).join("");
|
|
1526
1554
|
if (children || !VOID_ELEMENTS.has(node.tag)) {
|
|
1527
1555
|
return `<${node.tag}${attrs ? " " + attrs : ""}>${children}</${node.tag}>`;
|
|
1528
1556
|
}
|
|
@@ -1533,7 +1561,7 @@ function irToPlaceholderTemplate(node, restSpreadNames, loopDepth = 0, loopParam
|
|
|
1533
1561
|
case "expression":
|
|
1534
1562
|
if (node.expr === "null" || node.expr === "undefined") return "";
|
|
1535
1563
|
if (node.slotId) {
|
|
1536
|
-
return `<!--bf:${node.slotId}-->\${${wrapExpr(node.expr)}}<!--/-->`;
|
|
1564
|
+
return `<!--bf:${node.slotId}-->\${${escapeTextSlotExpr(wrapExpr(node.expr))}}<!--/-->`;
|
|
1537
1565
|
}
|
|
1538
1566
|
return `\${${wrapExpr(node.expr)}}`;
|
|
1539
1567
|
case "conditional": {
|
|
@@ -1752,7 +1780,7 @@ function irToComponentTemplateWithOpts(node, opts) {
|
|
|
1752
1780
|
attrParts.push(`bf="${node.slotId}"`);
|
|
1753
1781
|
}
|
|
1754
1782
|
const attrs = attrParts.join(" ");
|
|
1755
|
-
const children = node.children.map(childrenRecurse).join("");
|
|
1783
|
+
const children = dangerouslyHtmlChildren(node.attrs, (v) => transformExpr(v.expr, v.templateExpr)) ?? node.children.map(childrenRecurse).join("");
|
|
1756
1784
|
if (children || !VOID_ELEMENTS.has(node.tag)) {
|
|
1757
1785
|
return `<${node.tag}${attrs ? " " + attrs : ""}>${children}</${node.tag}>`;
|
|
1758
1786
|
}
|
|
@@ -1763,7 +1791,7 @@ function irToComponentTemplateWithOpts(node, opts) {
|
|
|
1763
1791
|
case "expression":
|
|
1764
1792
|
if (node.expr === "null" || node.expr === "undefined") return "";
|
|
1765
1793
|
if (node.slotId) {
|
|
1766
|
-
return `<!--bf:${node.slotId}-->\${${transformExpr(node.expr, node.templateExpr)}}<!--/-->`;
|
|
1794
|
+
return `<!--bf:${node.slotId}-->\${${escapeTextSlotExpr(transformExpr(node.expr, node.templateExpr))}}<!--/-->`;
|
|
1767
1795
|
}
|
|
1768
1796
|
return `\${${transformExpr(node.expr, node.templateExpr)}}`;
|
|
1769
1797
|
case "conditional": {
|
|
@@ -1966,7 +1994,7 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
1966
1994
|
attrParts.push(`bf="${node.slotId}"`);
|
|
1967
1995
|
}
|
|
1968
1996
|
const attrs = attrParts.join(" ");
|
|
1969
|
-
const children = node.children.map(childrenRecurse).join("");
|
|
1997
|
+
const children = dangerouslyHtmlChildren(node.attrs, (v) => transformExpr(v.expr, v.templateExpr)) ?? node.children.map(childrenRecurse).join("");
|
|
1970
1998
|
if (children || !VOID_ELEMENTS.has(node.tag)) {
|
|
1971
1999
|
return `<${node.tag}${attrs ? " " + attrs : ""}>${children}</${node.tag}>`;
|
|
1972
2000
|
}
|
|
@@ -1983,7 +2011,7 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
1983
2011
|
const transformed = transformExpr(node.expr, node.templateExpr);
|
|
1984
2012
|
const expr = transformed === UNSAFE_TEMPLATE_EXPR ? "''" : transformed;
|
|
1985
2013
|
if (node.slotId) {
|
|
1986
|
-
return `<!--bf:${node.slotId}-->\${${expr}}<!--/-->`;
|
|
2014
|
+
return `<!--bf:${node.slotId}-->\${${escapeTextSlotExpr(expr)}}<!--/-->`;
|
|
1987
2015
|
}
|
|
1988
2016
|
return `\${${expr}}`;
|
|
1989
2017
|
}
|
|
@@ -8310,11 +8338,11 @@ function transformMapCall(node, ctx2, isClientOnly = false, method = "map") {
|
|
|
8310
8338
|
if (stmt === returnStmt) break;
|
|
8311
8339
|
const js = ctx2.getJS(stmt);
|
|
8312
8340
|
const tjs = ctx2.getTemplateJS(stmt);
|
|
8313
|
-
const
|
|
8341
|
+
const ts21 = stmt.getText(ctx2.sourceFile);
|
|
8314
8342
|
preambleStmts.push(js.endsWith(";") ? js : js + ";");
|
|
8315
8343
|
templatePreambleStmts.push(tjs.endsWith(";") ? tjs : tjs + ";");
|
|
8316
|
-
typedPreambleStmts.push(
|
|
8317
|
-
if (js !==
|
|
8344
|
+
typedPreambleStmts.push(ts21.endsWith(";") ? ts21 : ts21 + ";");
|
|
8345
|
+
if (js !== ts21) hasTypeDiff = true;
|
|
8318
8346
|
if (js !== tjs) hasTemplateDiff = true;
|
|
8319
8347
|
}
|
|
8320
8348
|
if (preambleStmts.length > 0) {
|
|
@@ -9590,23 +9618,72 @@ var init_reactivity = __esm({
|
|
|
9590
9618
|
});
|
|
9591
9619
|
|
|
9592
9620
|
// ../jsx/src/ir-to-client-js/collect-elements.ts
|
|
9593
|
-
function
|
|
9594
|
-
|
|
9621
|
+
function domElementCount(node) {
|
|
9622
|
+
switch (node.type) {
|
|
9623
|
+
case "element":
|
|
9624
|
+
case "component":
|
|
9625
|
+
case "provider":
|
|
9626
|
+
case "async":
|
|
9627
|
+
return 1;
|
|
9628
|
+
case "text":
|
|
9629
|
+
return 0;
|
|
9630
|
+
case "expression":
|
|
9631
|
+
return EMPTY_RENDER_EXPRS.has(node.expr.trim()) ? 0 : null;
|
|
9632
|
+
case "loop":
|
|
9633
|
+
if (node.bodyIsItemConditional || node.method === "flatMap") return null;
|
|
9634
|
+
return `(${buildLoopChainExpr({
|
|
9635
|
+
base: node.array,
|
|
9636
|
+
sortComparator: node.sortComparator,
|
|
9637
|
+
filterPredicate: node.filterPredicate,
|
|
9638
|
+
chainOrder: node.chainOrder
|
|
9639
|
+
})}).length`;
|
|
9640
|
+
case "conditional": {
|
|
9641
|
+
const t = domElementCount(node.whenTrue);
|
|
9642
|
+
const f = domElementCount(node.whenFalse);
|
|
9643
|
+
if (t === null || f === null) return null;
|
|
9644
|
+
if (typeof t === "number" && typeof f === "number" && t === f) return t;
|
|
9645
|
+
return `(${node.condition} ? ${t} : ${f})`;
|
|
9646
|
+
}
|
|
9647
|
+
case "fragment":
|
|
9648
|
+
return sumElementCounts(node.children);
|
|
9649
|
+
default:
|
|
9650
|
+
return null;
|
|
9651
|
+
}
|
|
9652
|
+
}
|
|
9653
|
+
function sumElementCounts(nodes) {
|
|
9654
|
+
let staticCount = 0;
|
|
9655
|
+
const dynamic = [];
|
|
9656
|
+
for (const n of nodes) {
|
|
9657
|
+
const c = domElementCount(n);
|
|
9658
|
+
if (c === null) return null;
|
|
9659
|
+
if (typeof c === "number") staticCount += c;
|
|
9660
|
+
else dynamic.push(c);
|
|
9661
|
+
}
|
|
9662
|
+
if (dynamic.length === 0) return staticCount;
|
|
9663
|
+
const parts = staticCount > 0 ? [String(staticCount), ...dynamic] : dynamic;
|
|
9664
|
+
return parts.length === 1 ? parts[0] : `(${parts.join(" + ")})`;
|
|
9665
|
+
}
|
|
9666
|
+
function legacyElementCount(node) {
|
|
9667
|
+
return node.type === "element" || node.type === "component" || node.type === "provider" || node.type === "async" || node.type === "text" || node.type === "expression" && !node.reactive || node.type === "conditional" ? 1 : 0;
|
|
9595
9668
|
}
|
|
9596
9669
|
function computeLoopSiblingOffsets(root) {
|
|
9597
9670
|
const offsets = /* @__PURE__ */ new Map();
|
|
9598
|
-
const
|
|
9599
|
-
let nonLoopCount = 0;
|
|
9671
|
+
const recordRun = (children, preceding) => {
|
|
9600
9672
|
for (const child of children) {
|
|
9601
9673
|
if (child.type === "loop") {
|
|
9602
|
-
if (
|
|
9603
|
-
|
|
9604
|
-
|
|
9674
|
+
if (preceding.length > 0 && !offsets.has(child)) {
|
|
9675
|
+
offsets.set(child, [...preceding]);
|
|
9676
|
+
}
|
|
9677
|
+
preceding.push(child);
|
|
9678
|
+
} else if (child.type === "fragment" || child.type === "provider" || child.type === "async") {
|
|
9679
|
+
recordRun(child.children, preceding);
|
|
9680
|
+
} else {
|
|
9681
|
+
preceding.push(child);
|
|
9605
9682
|
}
|
|
9606
9683
|
}
|
|
9607
9684
|
};
|
|
9608
9685
|
const containerVisit = ({ node, descend }) => {
|
|
9609
|
-
|
|
9686
|
+
recordRun(node.children, []);
|
|
9610
9687
|
descend();
|
|
9611
9688
|
};
|
|
9612
9689
|
walkIR(root, null, {
|
|
@@ -9622,6 +9699,19 @@ function computeLoopSiblingOffsets(root) {
|
|
|
9622
9699
|
});
|
|
9623
9700
|
return offsets;
|
|
9624
9701
|
}
|
|
9702
|
+
function resolveLoopOffset(preceding) {
|
|
9703
|
+
if (!preceding || preceding.length === 0) return void 0;
|
|
9704
|
+
let staticCount = 0;
|
|
9705
|
+
const dynamicTerms = [];
|
|
9706
|
+
for (const node of preceding) {
|
|
9707
|
+
const c = domElementCount(node);
|
|
9708
|
+
if (c === null) staticCount += legacyElementCount(node);
|
|
9709
|
+
else if (typeof c === "number") staticCount += c;
|
|
9710
|
+
else dynamicTerms.push(c);
|
|
9711
|
+
}
|
|
9712
|
+
if (staticCount === 0 && dynamicTerms.length === 0) return void 0;
|
|
9713
|
+
return { staticCount, dynamicTerms };
|
|
9714
|
+
}
|
|
9625
9715
|
function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx2, options) {
|
|
9626
9716
|
const result = [];
|
|
9627
9717
|
const flat = options?.flatBranchMode === true;
|
|
@@ -9707,7 +9797,7 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx2, options)
|
|
|
9707
9797
|
refsOuterParam: refsOuter,
|
|
9708
9798
|
childComponents,
|
|
9709
9799
|
insideConditional: !flat && scope.insideCond ? true : void 0,
|
|
9710
|
-
|
|
9800
|
+
offset: flat ? void 0 : resolveLoopOffset(siblingOffsets.get(n)),
|
|
9711
9801
|
bindings
|
|
9712
9802
|
});
|
|
9713
9803
|
if (!flat) {
|
|
@@ -9917,7 +10007,7 @@ function collectElements(node, ctx2, siblingOffsets, insideConditional = false)
|
|
|
9917
10007
|
isStaticArray: l.isStaticArray,
|
|
9918
10008
|
useElementReconciliation,
|
|
9919
10009
|
innerLoops: useElementReconciliation || l.isStaticArray && innerLoops?.length ? innerLoops : void 0,
|
|
9920
|
-
|
|
10010
|
+
offset: resolveLoopOffset(siblingOffsets.get(l)),
|
|
9921
10011
|
filterPredicate: l.filterPredicate ? {
|
|
9922
10012
|
param: l.filterPredicate.param,
|
|
9923
10013
|
raw: l.filterPredicate.raw
|
|
@@ -10218,7 +10308,7 @@ function summarizeLoopChildBranch(node, ctx2, siblingOffsets, loopParam, loopPar
|
|
|
10218
10308
|
events: collectConditionalBranchEvents(node)
|
|
10219
10309
|
};
|
|
10220
10310
|
}
|
|
10221
|
-
var branchInnerLoopOptions;
|
|
10311
|
+
var EMPTY_RENDER_EXPRS, branchInnerLoopOptions;
|
|
10222
10312
|
var init_collect_elements = __esm({
|
|
10223
10313
|
"../jsx/src/ir-to-client-js/collect-elements.ts"() {
|
|
10224
10314
|
"use strict";
|
|
@@ -10228,6 +10318,8 @@ var init_collect_elements = __esm({
|
|
|
10228
10318
|
init_html_template();
|
|
10229
10319
|
init_prop_handling();
|
|
10230
10320
|
init_walker();
|
|
10321
|
+
init_loop_chain();
|
|
10322
|
+
EMPTY_RENDER_EXPRS = /* @__PURE__ */ new Set(["null", "undefined", "false", "''", '""', "``"]);
|
|
10231
10323
|
branchInnerLoopOptions = {
|
|
10232
10324
|
collectItemBindings: true,
|
|
10233
10325
|
templateDepth: 1,
|
|
@@ -10787,6 +10879,8 @@ var init_imports = __esm({
|
|
|
10787
10879
|
"splitProps",
|
|
10788
10880
|
"spreadAttrs",
|
|
10789
10881
|
"styleToCss",
|
|
10882
|
+
"escapeAttr",
|
|
10883
|
+
"escapeText",
|
|
10790
10884
|
"qsa",
|
|
10791
10885
|
"qsaItem",
|
|
10792
10886
|
"qsaChildScope",
|
|
@@ -12624,7 +12718,7 @@ function buildOuterNestedPlan(elem, comp) {
|
|
|
12624
12718
|
arrayExpr: elem.array,
|
|
12625
12719
|
param: elem.param,
|
|
12626
12720
|
indexParam,
|
|
12627
|
-
offsetExpr:
|
|
12721
|
+
offsetExpr: buildLoopChildIndexExpr(indexParam, elem.offset),
|
|
12628
12722
|
outerPreludeStatements: elem.mapPreamble ? [elem.mapPreamble] : [],
|
|
12629
12723
|
propsExpr: buildStaticPropsExpr(comp.props)
|
|
12630
12724
|
};
|
|
@@ -12642,12 +12736,12 @@ function buildInnerLoopNestedPlan(elem, innerLoop, innerComps) {
|
|
|
12642
12736
|
outerArrayExpr: elem.array,
|
|
12643
12737
|
outerParam: elem.param,
|
|
12644
12738
|
outerIndexParam,
|
|
12645
|
-
outerOffsetExpr:
|
|
12739
|
+
outerOffsetExpr: buildLoopChildIndexExpr(outerIndexParam, elem.offset),
|
|
12646
12740
|
outerPreludeStatements: elem.mapPreamble ? [elem.mapPreamble] : [],
|
|
12647
12741
|
innerContainerSlotId: innerLoop.containerSlotId ?? null,
|
|
12648
12742
|
innerArrayExpr: innerLoop.array,
|
|
12649
12743
|
innerParam: innerLoop.param,
|
|
12650
|
-
innerOffsetExpr:
|
|
12744
|
+
innerOffsetExpr: buildLoopChildIndexExpr("__innerIdx", innerLoop.offset),
|
|
12651
12745
|
innerPreludeStatements: innerLoop.mapPreamble ? [innerLoop.mapPreamble] : [],
|
|
12652
12746
|
depth: innerLoop.depth,
|
|
12653
12747
|
comps
|
|
@@ -13464,7 +13558,7 @@ function buildStaticArrayDelegationPlan(elem) {
|
|
|
13464
13558
|
arrayExpr: buildChainedArrayExpr(elem),
|
|
13465
13559
|
param: elem.param,
|
|
13466
13560
|
mapPreamble: elem.mapPreamble ?? null,
|
|
13467
|
-
|
|
13561
|
+
offset: elem.offset ?? null
|
|
13468
13562
|
}
|
|
13469
13563
|
};
|
|
13470
13564
|
}
|
|
@@ -13618,6 +13712,11 @@ var init_build_insert = __esm({
|
|
|
13618
13712
|
// ../jsx/src/ir-to-client-js/emit-reactive.ts
|
|
13619
13713
|
function emitAttrUpdate(target, attrName, expression, meta) {
|
|
13620
13714
|
const htmlName = toHTMLAttrName(attrName);
|
|
13715
|
+
if (attrName === "dangerouslySetInnerHTML" || htmlName === "dangerouslySetInnerHTML") {
|
|
13716
|
+
return [
|
|
13717
|
+
`{ const __v = ${expression}; ${target}.innerHTML = __v != null && __v.__html != null ? String(__v.__html) : '' }`
|
|
13718
|
+
];
|
|
13719
|
+
}
|
|
13621
13720
|
if (htmlName === "style") {
|
|
13622
13721
|
return [
|
|
13623
13722
|
`{ const __v = styleToCss(${expression}); if (__v != null) ${target}.setAttribute('style', __v); else ${target}.removeAttribute('style') }`
|
|
@@ -14681,11 +14780,11 @@ function emitDynamicIndexLookup(ls, ev, handlerCall, lookup) {
|
|
|
14681
14780
|
ls.push(` }`);
|
|
14682
14781
|
}
|
|
14683
14782
|
function emitStaticIndexLookup(ls, ev, handlerCall, lookup, containerVar) {
|
|
14684
|
-
const { arrayExpr, param, mapPreamble,
|
|
14783
|
+
const { arrayExpr, param, mapPreamble, offset } = lookup;
|
|
14685
14784
|
ls.push(` let __el = ${varSlotId(ev.childSlotId)}El`);
|
|
14686
14785
|
ls.push(` while (__el.parentElement && __el.parentElement !== ${containerVar}) __el = __el.parentElement`);
|
|
14687
14786
|
ls.push(` if (__el.parentElement === ${containerVar}) {`);
|
|
14688
|
-
const idxOffset =
|
|
14787
|
+
const idxOffset = buildLoopChildIndexSubtraction(offset ?? void 0);
|
|
14689
14788
|
ls.push(` const __idx = Array.from(${containerVar}.children).indexOf(__el)${idxOffset}`);
|
|
14690
14789
|
ls.push(` const ${param} = ${arrayExpr}[__idx]`);
|
|
14691
14790
|
if (mapPreamble) ls.push(` ${mapPreamble}`);
|
|
@@ -15013,7 +15112,7 @@ function buildStaticLoopPlan(elem, unsafeLocalNames) {
|
|
|
15013
15112
|
}
|
|
15014
15113
|
}
|
|
15015
15114
|
const indexParam = elem.index || "__idx";
|
|
15016
|
-
const childIndexExpr =
|
|
15115
|
+
const childIndexExpr = buildLoopChildIndexExpr(indexParam, elem.offset);
|
|
15017
15116
|
return {
|
|
15018
15117
|
kind: "static",
|
|
15019
15118
|
containerVar: `_${varSlotId(elem.slotId)}`,
|
|
@@ -17409,6 +17508,7 @@ var init_attr_value_emitter = __esm({
|
|
|
17409
17508
|
});
|
|
17410
17509
|
|
|
17411
17510
|
// ../jsx/src/combine-client-js.ts
|
|
17511
|
+
import ts18 from "typescript";
|
|
17412
17512
|
function combineParentChildClientJs(files) {
|
|
17413
17513
|
const result = /* @__PURE__ */ new Map();
|
|
17414
17514
|
const lookup = /* @__PURE__ */ new Map();
|
|
@@ -17465,30 +17565,48 @@ function combineParentChildClientJs(files) {
|
|
|
17465
17565
|
return result;
|
|
17466
17566
|
}
|
|
17467
17567
|
function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
17468
|
-
const
|
|
17469
|
-
|
|
17470
|
-
|
|
17471
|
-
|
|
17472
|
-
|
|
17473
|
-
|
|
17474
|
-
|
|
17475
|
-
|
|
17476
|
-
|
|
17477
|
-
|
|
17478
|
-
|
|
17479
|
-
|
|
17480
|
-
|
|
17481
|
-
|
|
17482
|
-
|
|
17483
|
-
|
|
17484
|
-
|
|
17485
|
-
|
|
17568
|
+
const sourceFile = ts18.createSourceFile(
|
|
17569
|
+
"combine.js",
|
|
17570
|
+
content,
|
|
17571
|
+
ts18.ScriptTarget.Latest,
|
|
17572
|
+
/*setParentNodes*/
|
|
17573
|
+
false,
|
|
17574
|
+
ts18.ScriptKind.JS
|
|
17575
|
+
);
|
|
17576
|
+
const importSpans = [];
|
|
17577
|
+
for (const stmt of sourceFile.statements) {
|
|
17578
|
+
if (!ts18.isImportDeclaration(stmt)) continue;
|
|
17579
|
+
const start = stmt.getStart(sourceFile);
|
|
17580
|
+
const end = stmt.getEnd();
|
|
17581
|
+
importSpans.push([start, end]);
|
|
17582
|
+
const stmtText = content.slice(start, end);
|
|
17583
|
+
if (stmtText.includes("@bf-child:")) continue;
|
|
17584
|
+
const clause = stmt.importClause;
|
|
17585
|
+
const bindings = clause?.namedBindings;
|
|
17586
|
+
const specifier = ts18.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
|
|
17587
|
+
if (clause && !clause.name && bindings && ts18.isNamedImports(bindings)) {
|
|
17588
|
+
if (!importsBySource.has(specifier)) {
|
|
17589
|
+
importsBySource.set(specifier, /* @__PURE__ */ new Set());
|
|
17590
|
+
}
|
|
17591
|
+
const set = importsBySource.get(specifier);
|
|
17592
|
+
for (const el of bindings.elements) {
|
|
17593
|
+
const name = el.propertyName ? `${el.propertyName.text} as ${el.name.text}` : el.name.text;
|
|
17594
|
+
set.add(name);
|
|
17486
17595
|
}
|
|
17487
17596
|
} else {
|
|
17488
|
-
|
|
17597
|
+
if (!otherImports.includes(stmtText)) {
|
|
17598
|
+
otherImports.push(stmtText);
|
|
17599
|
+
}
|
|
17489
17600
|
}
|
|
17490
17601
|
}
|
|
17491
|
-
|
|
17602
|
+
let code = "";
|
|
17603
|
+
let cursor = 0;
|
|
17604
|
+
for (const [start, end] of importSpans) {
|
|
17605
|
+
code += content.slice(cursor, start);
|
|
17606
|
+
cursor = end;
|
|
17607
|
+
}
|
|
17608
|
+
code += content.slice(cursor);
|
|
17609
|
+
code = code.trim();
|
|
17492
17610
|
if (code) {
|
|
17493
17611
|
codeSections.push(code);
|
|
17494
17612
|
}
|
|
@@ -18921,7 +19039,7 @@ var init_runtime = __esm({
|
|
|
18921
19039
|
|
|
18922
19040
|
// src/lib/resolve-imports.ts
|
|
18923
19041
|
import { dirname as dirname2, resolve as resolve2 } from "node:path";
|
|
18924
|
-
import
|
|
19042
|
+
import ts19 from "typescript";
|
|
18925
19043
|
function shapeFromDecl(decl) {
|
|
18926
19044
|
const clause = decl.importClause;
|
|
18927
19045
|
if (!clause) return null;
|
|
@@ -18931,7 +19049,7 @@ function shapeFromDecl(decl) {
|
|
|
18931
19049
|
}
|
|
18932
19050
|
const bindings = clause.namedBindings;
|
|
18933
19051
|
if (bindings) {
|
|
18934
|
-
if (
|
|
19052
|
+
if (ts19.isNamespaceImport(bindings)) {
|
|
18935
19053
|
shape.namespace = bindings.name.text;
|
|
18936
19054
|
} else {
|
|
18937
19055
|
for (const el of bindings.elements) {
|
|
@@ -18945,38 +19063,38 @@ function shapeFromDecl(decl) {
|
|
|
18945
19063
|
}
|
|
18946
19064
|
function collectExportedNames(source) {
|
|
18947
19065
|
const names = /* @__PURE__ */ new Set();
|
|
18948
|
-
const sourceFile =
|
|
19066
|
+
const sourceFile = ts19.createSourceFile(
|
|
18949
19067
|
"mod.ts",
|
|
18950
19068
|
source,
|
|
18951
|
-
|
|
19069
|
+
ts19.ScriptTarget.Latest,
|
|
18952
19070
|
/*setParents*/
|
|
18953
19071
|
false,
|
|
18954
|
-
|
|
19072
|
+
ts19.ScriptKind.TS
|
|
18955
19073
|
);
|
|
18956
19074
|
function hasExport(node) {
|
|
18957
|
-
if (!
|
|
18958
|
-
const mods =
|
|
18959
|
-
return mods?.some((m) => m.kind ===
|
|
19075
|
+
if (!ts19.canHaveModifiers(node)) return false;
|
|
19076
|
+
const mods = ts19.getModifiers(node);
|
|
19077
|
+
return mods?.some((m) => m.kind === ts19.SyntaxKind.ExportKeyword) ?? false;
|
|
18960
19078
|
}
|
|
18961
19079
|
function collectFromBindingName(name) {
|
|
18962
|
-
if (
|
|
19080
|
+
if (ts19.isIdentifier(name)) {
|
|
18963
19081
|
names.add(name.text);
|
|
18964
19082
|
return;
|
|
18965
19083
|
}
|
|
18966
19084
|
for (const el of name.elements) {
|
|
18967
|
-
if (
|
|
19085
|
+
if (ts19.isBindingElement(el)) collectFromBindingName(el.name);
|
|
18968
19086
|
}
|
|
18969
19087
|
}
|
|
18970
19088
|
for (const stmt of sourceFile.statements) {
|
|
18971
|
-
if (
|
|
19089
|
+
if (ts19.isVariableStatement(stmt) && hasExport(stmt)) {
|
|
18972
19090
|
for (const d of stmt.declarationList.declarations) {
|
|
18973
19091
|
collectFromBindingName(d.name);
|
|
18974
19092
|
}
|
|
18975
|
-
} else if (
|
|
19093
|
+
} else if (ts19.isFunctionDeclaration(stmt) && hasExport(stmt) && stmt.name) {
|
|
18976
19094
|
names.add(stmt.name.text);
|
|
18977
|
-
} else if (
|
|
19095
|
+
} else if (ts19.isClassDeclaration(stmt) && hasExport(stmt) && stmt.name) {
|
|
18978
19096
|
names.add(stmt.name.text);
|
|
18979
|
-
} else if (
|
|
19097
|
+
} else if (ts19.isExportDeclaration(stmt) && !stmt.moduleSpecifier && stmt.exportClause && ts19.isNamedExports(stmt.exportClause)) {
|
|
18980
19098
|
if (stmt.isTypeOnly) continue;
|
|
18981
19099
|
for (const el of stmt.exportClause.elements) {
|
|
18982
19100
|
if (el.isTypeOnly) continue;
|
|
@@ -18987,16 +19105,16 @@ function collectExportedNames(source) {
|
|
|
18987
19105
|
return [...names];
|
|
18988
19106
|
}
|
|
18989
19107
|
function hasUseClientDirective(source) {
|
|
18990
|
-
const sourceFile =
|
|
19108
|
+
const sourceFile = ts19.createSourceFile(
|
|
18991
19109
|
"check.tsx",
|
|
18992
19110
|
source,
|
|
18993
|
-
|
|
19111
|
+
ts19.ScriptTarget.Latest,
|
|
18994
19112
|
/*setParents*/
|
|
18995
19113
|
false,
|
|
18996
|
-
|
|
19114
|
+
ts19.ScriptKind.TSX
|
|
18997
19115
|
);
|
|
18998
19116
|
for (const stmt of sourceFile.statements) {
|
|
18999
|
-
if (!
|
|
19117
|
+
if (!ts19.isExpressionStatement(stmt) || !ts19.isStringLiteral(stmt.expression)) {
|
|
19000
19118
|
return false;
|
|
19001
19119
|
}
|
|
19002
19120
|
if (stmt.expression.text === "use client") return true;
|
|
@@ -19005,53 +19123,53 @@ function hasUseClientDirective(source) {
|
|
|
19005
19123
|
}
|
|
19006
19124
|
function collectTopLevelBindings(source) {
|
|
19007
19125
|
const names = /* @__PURE__ */ new Set();
|
|
19008
|
-
const sourceFile =
|
|
19126
|
+
const sourceFile = ts19.createSourceFile(
|
|
19009
19127
|
"bundle.ts",
|
|
19010
19128
|
source,
|
|
19011
|
-
|
|
19129
|
+
ts19.ScriptTarget.Latest,
|
|
19012
19130
|
/*setParents*/
|
|
19013
19131
|
false,
|
|
19014
|
-
|
|
19132
|
+
ts19.ScriptKind.TS
|
|
19015
19133
|
);
|
|
19016
19134
|
function collectFromBindingName(name) {
|
|
19017
|
-
if (
|
|
19135
|
+
if (ts19.isIdentifier(name)) {
|
|
19018
19136
|
names.add(name.text);
|
|
19019
19137
|
return;
|
|
19020
19138
|
}
|
|
19021
19139
|
for (const el of name.elements) {
|
|
19022
|
-
if (
|
|
19140
|
+
if (ts19.isBindingElement(el)) collectFromBindingName(el.name);
|
|
19023
19141
|
}
|
|
19024
19142
|
}
|
|
19025
19143
|
for (const stmt of sourceFile.statements) {
|
|
19026
|
-
if (
|
|
19144
|
+
if (ts19.isVariableStatement(stmt)) {
|
|
19027
19145
|
for (const d of stmt.declarationList.declarations) {
|
|
19028
19146
|
collectFromBindingName(d.name);
|
|
19029
19147
|
}
|
|
19030
|
-
} else if (
|
|
19148
|
+
} else if (ts19.isFunctionDeclaration(stmt) && stmt.name) {
|
|
19031
19149
|
names.add(stmt.name.text);
|
|
19032
|
-
} else if (
|
|
19150
|
+
} else if (ts19.isClassDeclaration(stmt) && stmt.name) {
|
|
19033
19151
|
names.add(stmt.name.text);
|
|
19034
19152
|
}
|
|
19035
19153
|
}
|
|
19036
19154
|
return names;
|
|
19037
19155
|
}
|
|
19038
19156
|
function stripImportsAndExports(body) {
|
|
19039
|
-
const sourceFile =
|
|
19157
|
+
const sourceFile = ts19.createSourceFile(
|
|
19040
19158
|
"body.ts",
|
|
19041
19159
|
body,
|
|
19042
|
-
|
|
19160
|
+
ts19.ScriptTarget.Latest,
|
|
19043
19161
|
/*setParents*/
|
|
19044
19162
|
false,
|
|
19045
|
-
|
|
19163
|
+
ts19.ScriptKind.TS
|
|
19046
19164
|
);
|
|
19047
19165
|
const spans = [];
|
|
19048
19166
|
const hoistedImports = [];
|
|
19049
19167
|
for (const stmt of sourceFile.statements) {
|
|
19050
|
-
if (
|
|
19168
|
+
if (ts19.isImportDeclaration(stmt)) {
|
|
19051
19169
|
const start = stmt.getStart(sourceFile);
|
|
19052
19170
|
const end = stmt.getEnd();
|
|
19053
19171
|
const specifier = stmt.moduleSpecifier;
|
|
19054
|
-
if (
|
|
19172
|
+
if (ts19.isStringLiteral(specifier)) {
|
|
19055
19173
|
const path23 = specifier.text;
|
|
19056
19174
|
const isRelative = path23.startsWith("./") || path23.startsWith("../");
|
|
19057
19175
|
if (!isRelative) {
|
|
@@ -19061,24 +19179,24 @@ function stripImportsAndExports(body) {
|
|
|
19061
19179
|
spans.push([start, end]);
|
|
19062
19180
|
continue;
|
|
19063
19181
|
}
|
|
19064
|
-
if (
|
|
19182
|
+
if (ts19.isExportDeclaration(stmt)) {
|
|
19065
19183
|
spans.push([stmt.getStart(sourceFile), stmt.getEnd()]);
|
|
19066
19184
|
continue;
|
|
19067
19185
|
}
|
|
19068
|
-
if (
|
|
19069
|
-
const exportKw = stmt.getChildren(sourceFile).find((c) => c.kind ===
|
|
19070
|
-
const defaultKw = stmt.getChildren(sourceFile).find((c) => c.kind ===
|
|
19071
|
-
const equalsKw = stmt.getChildren(sourceFile).find((c) => c.kind ===
|
|
19186
|
+
if (ts19.isExportAssignment(stmt)) {
|
|
19187
|
+
const exportKw = stmt.getChildren(sourceFile).find((c) => c.kind === ts19.SyntaxKind.ExportKeyword);
|
|
19188
|
+
const defaultKw = stmt.getChildren(sourceFile).find((c) => c.kind === ts19.SyntaxKind.DefaultKeyword);
|
|
19189
|
+
const equalsKw = stmt.getChildren(sourceFile).find((c) => c.kind === ts19.SyntaxKind.EqualsToken);
|
|
19072
19190
|
const start = exportKw?.getStart(sourceFile) ?? stmt.getStart(sourceFile);
|
|
19073
19191
|
const end = (defaultKw ?? equalsKw)?.getEnd() ?? exportKw?.getEnd() ?? stmt.getStart(sourceFile);
|
|
19074
19192
|
if (end > start) spans.push([start, end]);
|
|
19075
19193
|
continue;
|
|
19076
19194
|
}
|
|
19077
|
-
if (
|
|
19078
|
-
const mods =
|
|
19195
|
+
if (ts19.canHaveModifiers(stmt)) {
|
|
19196
|
+
const mods = ts19.getModifiers(stmt);
|
|
19079
19197
|
if (!mods) continue;
|
|
19080
19198
|
for (const mod of mods) {
|
|
19081
|
-
if (mod.kind ===
|
|
19199
|
+
if (mod.kind === ts19.SyntaxKind.ExportKeyword) {
|
|
19082
19200
|
const start = mod.getStart(sourceFile);
|
|
19083
19201
|
let end = mod.getEnd();
|
|
19084
19202
|
while (end < body.length && /\s/.test(body[end])) end++;
|
|
@@ -19187,48 +19305,48 @@ function buildDanglingReferenceMessage(binding, s) {
|
|
|
19187
19305
|
function isValueReference(id) {
|
|
19188
19306
|
const parent = id.parent;
|
|
19189
19307
|
if (!parent) return false;
|
|
19190
|
-
if (
|
|
19191
|
-
if (
|
|
19192
|
-
if ((
|
|
19308
|
+
if (ts19.isPropertyAccessExpression(parent) && parent.name === id) return false;
|
|
19309
|
+
if (ts19.isPropertyAssignment(parent) && parent.name === id) return false;
|
|
19310
|
+
if ((ts19.isMethodDeclaration(parent) || ts19.isGetAccessorDeclaration(parent) || ts19.isSetAccessorDeclaration(parent)) && parent.name === id) {
|
|
19193
19311
|
return false;
|
|
19194
19312
|
}
|
|
19195
|
-
if (
|
|
19196
|
-
if (
|
|
19197
|
-
if (
|
|
19198
|
-
if (
|
|
19199
|
-
if (
|
|
19200
|
-
if (
|
|
19201
|
-
if (
|
|
19202
|
-
if (
|
|
19203
|
-
if (
|
|
19204
|
-
if (
|
|
19205
|
-
if (
|
|
19206
|
-
if (
|
|
19207
|
-
if (
|
|
19208
|
-
if (
|
|
19313
|
+
if (ts19.isVariableDeclaration(parent) && parent.name === id) return false;
|
|
19314
|
+
if (ts19.isFunctionDeclaration(parent) && parent.name === id) return false;
|
|
19315
|
+
if (ts19.isFunctionExpression(parent) && parent.name === id) return false;
|
|
19316
|
+
if (ts19.isClassDeclaration(parent) && parent.name === id) return false;
|
|
19317
|
+
if (ts19.isClassExpression(parent) && parent.name === id) return false;
|
|
19318
|
+
if (ts19.isParameter(parent) && parent.name === id) return false;
|
|
19319
|
+
if (ts19.isBindingElement(parent) && (parent.name === id || parent.propertyName === id)) return false;
|
|
19320
|
+
if (ts19.isLabeledStatement(parent) && parent.label === id) return false;
|
|
19321
|
+
if (ts19.isBreakOrContinueStatement(parent) && parent.label === id) return false;
|
|
19322
|
+
if (ts19.isImportSpecifier(parent) && (parent.name === id || parent.propertyName === id)) return false;
|
|
19323
|
+
if (ts19.isExportSpecifier(parent) && (parent.name === id || parent.propertyName === id)) return false;
|
|
19324
|
+
if (ts19.isImportClause(parent) && parent.name === id) return false;
|
|
19325
|
+
if (ts19.isNamespaceImport(parent) && parent.name === id) return false;
|
|
19326
|
+
if (ts19.isQualifiedName(parent) && parent.right === id) return false;
|
|
19209
19327
|
return true;
|
|
19210
19328
|
}
|
|
19211
19329
|
function detectStrippedReferences(bundleSource, stripped) {
|
|
19212
19330
|
if (stripped.length === 0) return [];
|
|
19213
19331
|
let sf;
|
|
19214
19332
|
try {
|
|
19215
|
-
sf =
|
|
19333
|
+
sf = ts19.createSourceFile(
|
|
19216
19334
|
"bundle.js",
|
|
19217
19335
|
bundleSource,
|
|
19218
|
-
|
|
19336
|
+
ts19.ScriptTarget.Latest,
|
|
19219
19337
|
/*setParents*/
|
|
19220
19338
|
true,
|
|
19221
|
-
|
|
19339
|
+
ts19.ScriptKind.JS
|
|
19222
19340
|
);
|
|
19223
19341
|
} catch {
|
|
19224
19342
|
return [];
|
|
19225
19343
|
}
|
|
19226
19344
|
const firstReference = /* @__PURE__ */ new Map();
|
|
19227
19345
|
function visit3(node) {
|
|
19228
|
-
if (
|
|
19346
|
+
if (ts19.isIdentifier(node) && isValueReference(node)) {
|
|
19229
19347
|
if (!firstReference.has(node.text)) firstReference.set(node.text, node);
|
|
19230
19348
|
}
|
|
19231
|
-
|
|
19349
|
+
ts19.forEachChild(node, visit3);
|
|
19232
19350
|
}
|
|
19233
19351
|
visit3(sf);
|
|
19234
19352
|
const errors = [];
|
|
@@ -19258,18 +19376,18 @@ function detectStrippedReferences(bundleSource, stripped) {
|
|
|
19258
19376
|
return errors;
|
|
19259
19377
|
}
|
|
19260
19378
|
async function walkAndCollect(content, searchDirs, modules, visiting, loggingPath, stripped, stubDeps, nextId) {
|
|
19261
|
-
const sourceFile =
|
|
19379
|
+
const sourceFile = ts19.createSourceFile(
|
|
19262
19380
|
"walk.js",
|
|
19263
19381
|
content,
|
|
19264
|
-
|
|
19382
|
+
ts19.ScriptTarget.Latest,
|
|
19265
19383
|
/*setParents*/
|
|
19266
19384
|
false,
|
|
19267
|
-
|
|
19385
|
+
ts19.ScriptKind.JS
|
|
19268
19386
|
);
|
|
19269
19387
|
const sites = [];
|
|
19270
19388
|
for (const stmt of sourceFile.statements) {
|
|
19271
|
-
if (!
|
|
19272
|
-
if (!
|
|
19389
|
+
if (!ts19.isImportDeclaration(stmt)) continue;
|
|
19390
|
+
if (!ts19.isStringLiteral(stmt.moduleSpecifier)) continue;
|
|
19273
19391
|
const spec = stmt.moduleSpecifier.text;
|
|
19274
19392
|
if (!spec.startsWith("./") && !spec.startsWith("../")) continue;
|
|
19275
19393
|
const start = stmt.getStart(sourceFile);
|
|
@@ -19721,7 +19839,7 @@ var init_assets_ignore = __esm({
|
|
|
19721
19839
|
});
|
|
19722
19840
|
|
|
19723
19841
|
// src/lib/build.ts
|
|
19724
|
-
import
|
|
19842
|
+
import ts20 from "typescript";
|
|
19725
19843
|
import { mkdir, readdir, stat, unlink } from "node:fs/promises";
|
|
19726
19844
|
import { resolve as resolve6, basename, relative as relative2, dirname as dirname3, isAbsolute as isAbsolute2 } from "node:path";
|
|
19727
19845
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
@@ -20178,12 +20296,7 @@ async function build(config, options = {}) {
|
|
|
20178
20296
|
try {
|
|
20179
20297
|
let content = await readText(filePath);
|
|
20180
20298
|
const before = content;
|
|
20181
|
-
|
|
20182
|
-
content = content.replace(
|
|
20183
|
-
/from ['"]@barefootjs\/client(?:\/[^'"]*)?['"]/g,
|
|
20184
|
-
`from '${rel}'`
|
|
20185
|
-
);
|
|
20186
|
-
}
|
|
20299
|
+
content = rewriteBarefootClientSpecifiers(content, rel);
|
|
20187
20300
|
content = mergeDuplicateNamedImports(content);
|
|
20188
20301
|
if (content !== before && await writeIfChanged(filePath, content)) {
|
|
20189
20302
|
anyOutputChanged = true;
|
|
@@ -20272,7 +20385,7 @@ async function build(config, options = {}) {
|
|
|
20272
20385
|
};
|
|
20273
20386
|
}
|
|
20274
20387
|
function extractBareImports(code) {
|
|
20275
|
-
const { importedFiles } =
|
|
20388
|
+
const { importedFiles } = ts20.preProcessFile(code, true, true);
|
|
20276
20389
|
const specifiers = /* @__PURE__ */ new Set();
|
|
20277
20390
|
for (const { fileName } of importedFiles) {
|
|
20278
20391
|
if (!fileName.startsWith(".") && !fileName.startsWith("/") && !fileName.includes("://")) {
|
|
@@ -20337,13 +20450,82 @@ function effectiveOutName(tplPath, entryBaseNoExt) {
|
|
|
20337
20450
|
const entryDir = entryBaseNoExt.includes("/") ? entryBaseNoExt.slice(0, entryBaseNoExt.lastIndexOf("/")) : "";
|
|
20338
20451
|
return entryDir ? `${entryDir}/${bn}` : bn;
|
|
20339
20452
|
}
|
|
20453
|
+
function topLevelImportLines(content) {
|
|
20454
|
+
const lines = /* @__PURE__ */ new Set();
|
|
20455
|
+
const sourceFile = ts20.createSourceFile(
|
|
20456
|
+
"merge.js",
|
|
20457
|
+
content,
|
|
20458
|
+
ts20.ScriptTarget.Latest,
|
|
20459
|
+
/*setParentNodes*/
|
|
20460
|
+
true,
|
|
20461
|
+
ts20.ScriptKind.JS
|
|
20462
|
+
);
|
|
20463
|
+
for (const stmt of sourceFile.statements) {
|
|
20464
|
+
if (ts20.isImportDeclaration(stmt)) {
|
|
20465
|
+
const { line } = sourceFile.getLineAndCharacterOfPosition(stmt.getStart(sourceFile));
|
|
20466
|
+
lines.add(line);
|
|
20467
|
+
}
|
|
20468
|
+
}
|
|
20469
|
+
return lines;
|
|
20470
|
+
}
|
|
20471
|
+
function rewriteBarefootClientSpecifiers(content, rel) {
|
|
20472
|
+
if (!content.includes("@barefootjs/client")) return content;
|
|
20473
|
+
const sourceFile = ts20.createSourceFile(
|
|
20474
|
+
"client.js",
|
|
20475
|
+
content,
|
|
20476
|
+
ts20.ScriptTarget.Latest,
|
|
20477
|
+
/*setParentNodes*/
|
|
20478
|
+
true,
|
|
20479
|
+
ts20.ScriptKind.JS
|
|
20480
|
+
);
|
|
20481
|
+
const isBarefootClient = (s) => s === "@barefootjs/client" || s.startsWith("@barefootjs/client/");
|
|
20482
|
+
const spans = [];
|
|
20483
|
+
const visit3 = (node) => {
|
|
20484
|
+
if (ts20.isImportDeclaration(node) || ts20.isExportDeclaration(node)) {
|
|
20485
|
+
const ms = node.moduleSpecifier;
|
|
20486
|
+
if (ms && ts20.isStringLiteral(ms) && isBarefootClient(ms.text)) {
|
|
20487
|
+
spans.push([ms.getStart(sourceFile), ms.getEnd()]);
|
|
20488
|
+
}
|
|
20489
|
+
} else if (ts20.isCallExpression(node) && node.expression.kind === ts20.SyntaxKind.ImportKeyword) {
|
|
20490
|
+
const arg = node.arguments[0];
|
|
20491
|
+
if (arg && ts20.isStringLiteral(arg) && isBarefootClient(arg.text)) {
|
|
20492
|
+
spans.push([arg.getStart(sourceFile), arg.getEnd()]);
|
|
20493
|
+
}
|
|
20494
|
+
}
|
|
20495
|
+
ts20.forEachChild(node, visit3);
|
|
20496
|
+
};
|
|
20497
|
+
visit3(sourceFile);
|
|
20498
|
+
if (spans.length === 0) return content;
|
|
20499
|
+
spans.sort((a, b) => b[0] - a[0]);
|
|
20500
|
+
let out = content;
|
|
20501
|
+
for (const [start, end] of spans) {
|
|
20502
|
+
out = out.slice(0, start) + `'${rel}'` + out.slice(end);
|
|
20503
|
+
}
|
|
20504
|
+
return out;
|
|
20505
|
+
}
|
|
20340
20506
|
function mergeDuplicateNamedImports(content) {
|
|
20341
20507
|
const lines = content.split("\n");
|
|
20342
20508
|
const namedImportRe = /^import\s+\{\s*([^}]+)\s*\}\s+from\s+(['"])([^'"]+)\2\s*;?\s*$/;
|
|
20343
20509
|
const bySource = /* @__PURE__ */ new Map();
|
|
20344
20510
|
const dropIndices = /* @__PURE__ */ new Set();
|
|
20345
20511
|
let changed = false;
|
|
20512
|
+
{
|
|
20513
|
+
const seen = /* @__PURE__ */ new Set();
|
|
20514
|
+
let possibleDuplicate = false;
|
|
20515
|
+
for (const line of lines) {
|
|
20516
|
+
const m = line.match(namedImportRe);
|
|
20517
|
+
if (!m) continue;
|
|
20518
|
+
if (seen.has(m[3])) {
|
|
20519
|
+
possibleDuplicate = true;
|
|
20520
|
+
break;
|
|
20521
|
+
}
|
|
20522
|
+
seen.add(m[3]);
|
|
20523
|
+
}
|
|
20524
|
+
if (!possibleDuplicate) return content;
|
|
20525
|
+
}
|
|
20526
|
+
const realImportLines = topLevelImportLines(content);
|
|
20346
20527
|
lines.forEach((line, idx) => {
|
|
20528
|
+
if (!realImportLines.has(idx)) return;
|
|
20347
20529
|
const m = line.match(namedImportRe);
|
|
20348
20530
|
if (!m) return;
|
|
20349
20531
|
const names = m[1].split(",").map((s) => s.trim()).filter(Boolean);
|
|
@@ -23847,7 +24029,13 @@ export default createConfig({
|
|
|
23847
24029
|
}
|
|
23848
24030
|
},
|
|
23849
24031
|
"include": ["**/*.ts", "**/*.tsx"],
|
|
23850
|
-
|
|
24032
|
+
// Do NOT exclude dist/components here. The server imports the compiled
|
|
24033
|
+
// SSR templates from there (see the @/components/* paths above), and
|
|
24034
|
+
// tsx applies the JSX transform per-file honouring this include/
|
|
24035
|
+
// exclude \u2014 an excluded .tsx loses jsxImportSource and falls back to
|
|
24036
|
+
// the classic React runtime, so SSR throws "ReferenceError: React is
|
|
24037
|
+
// not defined" at the first render. They must stay in scope.
|
|
24038
|
+
"exclude": ["node_modules"]
|
|
23851
24039
|
}
|
|
23852
24040
|
`;
|
|
23853
24041
|
HONO_NODE_ADAPTER = {
|
|
@@ -27567,9 +27755,9 @@ function findProjectConfig(startDir) {
|
|
|
27567
27755
|
let dir = path.resolve(startDir);
|
|
27568
27756
|
const { root: fsRoot } = path.parse(dir);
|
|
27569
27757
|
while (true) {
|
|
27570
|
-
const
|
|
27571
|
-
if (existsSync2(
|
|
27572
|
-
return { dir, tsConfigPath:
|
|
27758
|
+
const ts21 = path.join(dir, "barefoot.config.ts");
|
|
27759
|
+
if (existsSync2(ts21)) {
|
|
27760
|
+
return { dir, tsConfigPath: ts21 };
|
|
27573
27761
|
}
|
|
27574
27762
|
if (dir === fsRoot) return null;
|
|
27575
27763
|
dir = path.dirname(dir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "CLI for agent-driven UI component discovery and scaffolding",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typescript": "^5.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@barefootjs/jsx": "0.5.
|
|
34
|
+
"@barefootjs/jsx": "0.5.3",
|
|
35
35
|
"@types/node": "^22.0.0"
|
|
36
36
|
}
|
|
37
37
|
}
|