@barefootjs/jsx 0.39.9 → 0.40.0
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/adapters/attr-plan.d.ts +1 -20
- package/dist/adapters/attr-plan.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +77 -1
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-plan.d.ts +41 -1
- package/dist/adapters/loop-plan.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/css-layer-prefixer.d.ts.map +1 -1
- package/dist/debug.d.ts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1965 -1862
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/module-exports.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +2 -0
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/template-parts.d.ts +1 -1
- package/dist/template-parts.d.ts.map +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/attr-plan.test.ts +1 -14
- package/src/__tests__/client-template-escape-soundness.test.ts +17 -4
- package/src/__tests__/client-template-static-delimiters.test.ts +57 -0
- package/src/__tests__/dsl-template-adapter.test.ts +70 -0
- package/src/__tests__/extract-function-params.test.ts +37 -0
- package/src/__tests__/issue-2960-multi-root-cond-same-tag.test.ts +18 -0
- package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +11 -0
- package/src/__tests__/loop-plan.test.ts +66 -1
- package/src/__tests__/template-parts-literal-boundary.test.ts +22 -0
- package/src/adapters/attr-plan.ts +2 -54
- package/src/adapters/dsl-template-adapter.ts +144 -2
- package/src/adapters/loop-plan.ts +67 -2
- package/src/augment-inherited-props.ts +5 -9
- package/src/css-layer-prefixer.ts +4 -5
- package/src/debug.ts +1 -0
- package/src/index.ts +11 -3
- package/src/ir-to-client-js/compute-inlinability.ts +1 -1
- package/src/ir-to-client-js/html-template.ts +52 -45
- package/src/ir-to-client-js/utils.ts +1 -1
- package/src/jsx-to-ir.ts +34 -20
- package/src/loop-destructure.ts +4 -1
- package/src/module-exports.ts +13 -21
- package/src/rich-type-refusal.ts +3 -1
- package/src/scope/binding-scope.ts +5 -0
- package/src/template-parts.ts +4 -2
- package/src/template-position-walk.ts +3 -1
- package/src/types.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -2967,6 +2967,9 @@ class BindingScope {
|
|
|
2967
2967
|
const hit = this.lookup(name);
|
|
2968
2968
|
return hit ? hit.binding.stringValue === true : outer(name);
|
|
2969
2969
|
}
|
|
2970
|
+
innermostNames() {
|
|
2971
|
+
return this.frames[0] ? [...this.frames[0].bindings.keys()] : [];
|
|
2972
|
+
}
|
|
2970
2973
|
shadowedNames() {
|
|
2971
2974
|
if (!this.frames[0])
|
|
2972
2975
|
return [];
|
|
@@ -3036,7 +3039,9 @@ function templatePartsToJsExpr(parts, opts) {
|
|
|
3036
3039
|
let result = "`";
|
|
3037
3040
|
for (const part of parts) {
|
|
3038
3041
|
if (part.type === "string") {
|
|
3039
|
-
result +=
|
|
3042
|
+
result += part.value.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${").replace(/\r/g, "\\r");
|
|
3043
|
+
} else if (part.type === "expression") {
|
|
3044
|
+
result += `\${${opts?.useTemplate ? part.templateExpr ?? part.expr : part.expr}}`;
|
|
3040
3045
|
} else if (part.type === "ternary") {
|
|
3041
3046
|
const cond = opts?.useTemplate && part.templateCondition ? part.templateCondition : part.condition;
|
|
3042
3047
|
result += `\${${cond} ? '${part.whenTrue}' : '${part.whenFalse}'}`;
|
|
@@ -5658,6 +5663,9 @@ function isEventHandlerName(name) {
|
|
|
5658
5663
|
}
|
|
5659
5664
|
|
|
5660
5665
|
// src/ir-to-client-js/html-template.ts
|
|
5666
|
+
function escapeStaticTemplateHtml(text) {
|
|
5667
|
+
return escapeHtml(text).replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
5668
|
+
}
|
|
5661
5669
|
function splitTemplateInterpolations(inner) {
|
|
5662
5670
|
const parts = [];
|
|
5663
5671
|
let i = 0;
|
|
@@ -5840,7 +5848,7 @@ function renderTemplateAttrPart(attr, attrName, wrap, restSpreadNames) {
|
|
|
5840
5848
|
case "boolean-attr":
|
|
5841
5849
|
return attrName;
|
|
5842
5850
|
case "literal":
|
|
5843
|
-
return `${attrName}="${
|
|
5851
|
+
return `${attrName}="${escapeStaticTemplateHtml(v.value)}"`;
|
|
5844
5852
|
case "expression": {
|
|
5845
5853
|
const valExpr = wrap(v.expr);
|
|
5846
5854
|
return templateAttrExpr(attrName, valExpr, v.presenceOrUndefined);
|
|
@@ -6041,7 +6049,7 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
|
|
|
6041
6049
|
return `<${node.tag}${attrs ? " " + attrs : ""} />`;
|
|
6042
6050
|
}
|
|
6043
6051
|
case "text":
|
|
6044
|
-
return
|
|
6052
|
+
return escapeStaticTemplateHtml(node.value);
|
|
6045
6053
|
case "expression": {
|
|
6046
6054
|
if (node.expr === "null" || node.expr === "undefined")
|
|
6047
6055
|
return "";
|
|
@@ -6091,7 +6099,7 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
|
|
|
6091
6099
|
propsEntries.push(childrenEntry);
|
|
6092
6100
|
const propsExpr = propsEntries.length > 0 ? `{${propsEntries.join(", ")}}` : "{}";
|
|
6093
6101
|
const keyProp = node.props.find((p) => p.name === "key");
|
|
6094
|
-
const keyArg = keyProp ? `, ${
|
|
6102
|
+
const keyArg = keyProp ? `, ${transformKeyValue(keyProp.value, (expr, templateExpr) => wrapExpr(templateExpr ?? expr))}` : "";
|
|
6095
6103
|
return interp(renderChildCall(nameForRegistryRef(node.name), propsExpr, renderChildScopeArgs(node, keyArg)));
|
|
6096
6104
|
}
|
|
6097
6105
|
case "loop": {
|
|
@@ -6149,7 +6157,7 @@ function buildLoopSkeletonTemplate(node, safe) {
|
|
|
6149
6157
|
const v = a.value;
|
|
6150
6158
|
switch (v.kind) {
|
|
6151
6159
|
case "literal":
|
|
6152
|
-
attrParts.push(`${toHtmlAttrName(a.name)}="${
|
|
6160
|
+
attrParts.push(`${toHtmlAttrName(a.name)}="${escapeStaticTemplateHtml(v.value)}"`);
|
|
6153
6161
|
break;
|
|
6154
6162
|
case "boolean-attr":
|
|
6155
6163
|
attrParts.push(toHtmlAttrName(a.name));
|
|
@@ -6186,7 +6194,7 @@ function buildLoopSkeletonTemplate(node, safe) {
|
|
|
6186
6194
|
return `<${node.tag}${attrs ? " " + attrs : ""} />`;
|
|
6187
6195
|
}
|
|
6188
6196
|
case "text":
|
|
6189
|
-
return
|
|
6197
|
+
return escapeStaticTemplateHtml(node.value);
|
|
6190
6198
|
case "expression":
|
|
6191
6199
|
if (node.expr === "null" || node.expr === "undefined")
|
|
6192
6200
|
return "";
|
|
@@ -6371,7 +6379,7 @@ function irToPlaceholderTemplate(node, restSpreadNames, loopDepth = 0, loopParam
|
|
|
6371
6379
|
return `<${node.tag}${attrs ? " " + attrs : ""} />`;
|
|
6372
6380
|
}
|
|
6373
6381
|
case "text":
|
|
6374
|
-
return
|
|
6382
|
+
return escapeStaticTemplateHtml(node.value);
|
|
6375
6383
|
case "expression": {
|
|
6376
6384
|
if (node.expr === "null" || node.expr === "undefined")
|
|
6377
6385
|
return "";
|
|
@@ -6504,29 +6512,50 @@ function addCondAttrToTemplate(html, condId) {
|
|
|
6504
6512
|
}
|
|
6505
6513
|
return `<!--bf-cond-start:${condId}-->${html}<!--bf-cond-end:${condId}-->`;
|
|
6506
6514
|
}
|
|
6515
|
+
function* templateHtmlTags(html) {
|
|
6516
|
+
let cursor = 0;
|
|
6517
|
+
let noCommentEnd = false;
|
|
6518
|
+
while (cursor < html.length) {
|
|
6519
|
+
const start = html.indexOf("<", cursor);
|
|
6520
|
+
if (start < 0)
|
|
6521
|
+
break;
|
|
6522
|
+
cursor = start + 1;
|
|
6523
|
+
if (html.startsWith("<!--", start) && !noCommentEnd) {
|
|
6524
|
+
const commentEnd = html.indexOf("-->", start + 4);
|
|
6525
|
+
if (commentEnd >= 0) {
|
|
6526
|
+
cursor = commentEnd + 3;
|
|
6527
|
+
continue;
|
|
6528
|
+
}
|
|
6529
|
+
noCommentEnd = true;
|
|
6530
|
+
}
|
|
6531
|
+
const nameStart = html[start + 1] === "/" ? start + 2 : start + 1;
|
|
6532
|
+
if (nameStart >= html.length || /[\s/>]/.test(html[nameStart]))
|
|
6533
|
+
continue;
|
|
6534
|
+
const end = html.indexOf(">", nameStart + 1);
|
|
6535
|
+
if (end < 0)
|
|
6536
|
+
break;
|
|
6537
|
+
cursor = end + 1;
|
|
6538
|
+
const raw = html.slice(start, cursor);
|
|
6539
|
+
if (raw.startsWith("<!--"))
|
|
6540
|
+
continue;
|
|
6541
|
+
yield { raw, end: cursor };
|
|
6542
|
+
}
|
|
6543
|
+
}
|
|
6507
6544
|
function isSingleRootElement(html) {
|
|
6508
6545
|
const trimmed = html.trim();
|
|
6509
6546
|
const match = trimmed.match(/^<(\w+)[\s>]/);
|
|
6510
6547
|
if (!match)
|
|
6511
6548
|
return false;
|
|
6512
|
-
if (/^<\w+[^>]*\/>$/.test(trimmed))
|
|
6513
|
-
return true;
|
|
6514
|
-
const tagPattern = /<!--[\s\S]*?-->|<\/?[^\s/>]+[^>]*>/g;
|
|
6515
6549
|
let depth = 0;
|
|
6516
|
-
|
|
6517
|
-
while (tagMatch = tagPattern.exec(trimmed)) {
|
|
6518
|
-
const raw = tagMatch[0];
|
|
6519
|
-
if (raw.startsWith("<!--"))
|
|
6520
|
-
continue;
|
|
6550
|
+
for (const { raw, end } of templateHtmlTags(trimmed)) {
|
|
6521
6551
|
if (raw.endsWith("/>")) {
|
|
6522
6552
|
if (depth === 0)
|
|
6523
|
-
return
|
|
6553
|
+
return end === trimmed.length;
|
|
6524
6554
|
continue;
|
|
6525
6555
|
}
|
|
6526
6556
|
depth += raw.startsWith("</") ? -1 : 1;
|
|
6527
|
-
if (depth === 0)
|
|
6528
|
-
return
|
|
6529
|
-
}
|
|
6557
|
+
if (depth === 0)
|
|
6558
|
+
return end === trimmed.length;
|
|
6530
6559
|
}
|
|
6531
6560
|
return false;
|
|
6532
6561
|
}
|
|
@@ -6590,7 +6619,7 @@ function irToComponentTemplateWithOpts(node, opts) {
|
|
|
6590
6619
|
return templateAttrExpr(keyName, transformExpr(tmplStr));
|
|
6591
6620
|
}
|
|
6592
6621
|
case "literal":
|
|
6593
|
-
return `${keyName}="${
|
|
6622
|
+
return `${keyName}="${escapeStaticTemplateHtml(v.value)}"`;
|
|
6594
6623
|
default:
|
|
6595
6624
|
return "";
|
|
6596
6625
|
}
|
|
@@ -6600,7 +6629,7 @@ function irToComponentTemplateWithOpts(node, opts) {
|
|
|
6600
6629
|
case "boolean-attr":
|
|
6601
6630
|
return attrName;
|
|
6602
6631
|
case "literal":
|
|
6603
|
-
return `${attrName}="${
|
|
6632
|
+
return `${attrName}="${escapeStaticTemplateHtml(v.value)}"`;
|
|
6604
6633
|
case "expression":
|
|
6605
6634
|
return templateAttrExpr(attrName, transformExpr(v.expr, v.templateExpr), v.presenceOrUndefined);
|
|
6606
6635
|
case "template": {
|
|
@@ -6626,7 +6655,7 @@ function irToComponentTemplateWithOpts(node, opts) {
|
|
|
6626
6655
|
return `<${node.tag}${attrs ? " " + attrs : ""} />`;
|
|
6627
6656
|
}
|
|
6628
6657
|
case "text":
|
|
6629
|
-
return
|
|
6658
|
+
return escapeStaticTemplateHtml(node.value);
|
|
6630
6659
|
case "expression": {
|
|
6631
6660
|
if (node.expr === "null" || node.expr === "undefined")
|
|
6632
6661
|
return "";
|
|
@@ -6915,7 +6944,7 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
6915
6944
|
case "boolean-attr":
|
|
6916
6945
|
return keyName;
|
|
6917
6946
|
case "literal":
|
|
6918
|
-
return `${keyName}="${
|
|
6947
|
+
return `${keyName}="${escapeStaticTemplateHtml(v.value)}"`;
|
|
6919
6948
|
case "expression":
|
|
6920
6949
|
return templateAttrExpr(keyName, transformExpr(v.expr, v.templateExpr), v.presenceOrUndefined);
|
|
6921
6950
|
case "template": {
|
|
@@ -6932,7 +6961,7 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
6932
6961
|
case "boolean-attr":
|
|
6933
6962
|
return attrName;
|
|
6934
6963
|
case "literal":
|
|
6935
|
-
return `${attrName}="${
|
|
6964
|
+
return `${attrName}="${escapeStaticTemplateHtml(v.value)}"`;
|
|
6936
6965
|
case "expression":
|
|
6937
6966
|
return templateAttrExpr(attrName, transformExpr(v.expr, v.templateExpr), v.presenceOrUndefined);
|
|
6938
6967
|
case "template": {
|
|
@@ -6958,7 +6987,7 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
6958
6987
|
return `<${node.tag}${attrs ? " " + attrs : ""} />`;
|
|
6959
6988
|
}
|
|
6960
6989
|
case "text":
|
|
6961
|
-
return
|
|
6990
|
+
return escapeStaticTemplateHtml(node.value);
|
|
6962
6991
|
case "expression":
|
|
6963
6992
|
if (node.expr === "null" || node.expr === "undefined")
|
|
6964
6993
|
return "";
|
|
@@ -8173,8 +8202,8 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
8173
8202
|
const v = prop.value;
|
|
8174
8203
|
if (v?.parts) {
|
|
8175
8204
|
for (const part of v.parts) {
|
|
8176
|
-
if (part.type === "
|
|
8177
|
-
scan(part.
|
|
8205
|
+
if (part.type === "expression")
|
|
8206
|
+
scan(part.expr);
|
|
8178
8207
|
else if (part.type === "ternary") {
|
|
8179
8208
|
scan(part.condition);
|
|
8180
8209
|
scan(part.whenTrue);
|
|
@@ -8192,8 +8221,8 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
8192
8221
|
const v = attr.value;
|
|
8193
8222
|
if (v?.parts) {
|
|
8194
8223
|
for (const part of v.parts) {
|
|
8195
|
-
if (part.type === "
|
|
8196
|
-
scan(part.
|
|
8224
|
+
if (part.type === "expression")
|
|
8225
|
+
scan(part.expr);
|
|
8197
8226
|
else if (part.type === "ternary") {
|
|
8198
8227
|
scan(part.condition);
|
|
8199
8228
|
scan(part.whenTrue);
|
|
@@ -13637,17 +13666,21 @@ function isAssignmentOperator3(kind) {
|
|
|
13637
13666
|
return kind >= ts23.SyntaxKind.FirstAssignment && kind <= ts23.SyntaxKind.LastAssignment;
|
|
13638
13667
|
}
|
|
13639
13668
|
function extractFunctionParams(value) {
|
|
13640
|
-
const
|
|
13641
|
-
|
|
13642
|
-
|
|
13643
|
-
|
|
13644
|
-
|
|
13645
|
-
|
|
13646
|
-
|
|
13647
|
-
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
|
|
13669
|
+
for (const kind of [ts23.ScriptKind.TSX, ts23.ScriptKind.TS]) {
|
|
13670
|
+
const source = ts23.createSourceFile("function.tsx", `(${value}
|
|
13671
|
+
)`, ts23.ScriptTarget.Latest, true, kind);
|
|
13672
|
+
const diagnostics = "parseDiagnostics" in source ? source.parseDiagnostics : undefined;
|
|
13673
|
+
if (Array.isArray(diagnostics) && diagnostics.length > 0)
|
|
13674
|
+
continue;
|
|
13675
|
+
const statement = source.statements[0];
|
|
13676
|
+
if (!statement || !ts23.isExpressionStatement(statement))
|
|
13677
|
+
return "";
|
|
13678
|
+
let expression = statement.expression;
|
|
13679
|
+
while (ts23.isParenthesizedExpression(expression))
|
|
13680
|
+
expression = expression.expression;
|
|
13681
|
+
if (!ts23.isArrowFunction(expression) && !ts23.isFunctionExpression(expression))
|
|
13682
|
+
return "";
|
|
13683
|
+
return expression.parameters.map((parameter) => `${parameter.dotDotDotToken ? "..." : ""}${parameter.name.getText(source)}`).join(", ");
|
|
13651
13684
|
}
|
|
13652
13685
|
return "";
|
|
13653
13686
|
}
|
|
@@ -14267,7 +14300,9 @@ function walkTemplateParts(parts, loc, attrName, visit3) {
|
|
|
14267
14300
|
visit3({ expr: parseExpression(trimmed), loc, role: "template-part", attrName });
|
|
14268
14301
|
};
|
|
14269
14302
|
for (const part of parts) {
|
|
14270
|
-
if (part.type === "
|
|
14303
|
+
if (part.type === "expression") {
|
|
14304
|
+
visit3({ expr: part.parsed, loc, role: "template-part", attrName });
|
|
14305
|
+
} else if (part.type === "ternary") {
|
|
14271
14306
|
visitText(part.condition);
|
|
14272
14307
|
visitText(part.whenTrue);
|
|
14273
14308
|
visitText(part.whenFalse);
|
|
@@ -14990,11 +15025,19 @@ function childrenReadOf(parsed, analyzer, scope) {
|
|
|
14990
15025
|
const readsProps = parsed.kind === "member" && parsed.object.kind === "identifier" && !scope.isBound(parsed.object.name);
|
|
14991
15026
|
return readsProps && isPropsChildrenMember(parsed, analyzer) ? "bare" : null;
|
|
14992
15027
|
}
|
|
14993
|
-
function attachParsedAttrValues(node, parse2, parseValue) {
|
|
15028
|
+
function attachParsedAttrValues(node, parse2, parseValue, resolve2) {
|
|
14994
15029
|
const attach = (value, spreads) => {
|
|
14995
|
-
|
|
14996
|
-
|
|
14997
|
-
|
|
15030
|
+
if (value.kind === "template" || value.kind === "expression") {
|
|
15031
|
+
for (const part of value.parts ?? []) {
|
|
15032
|
+
if (part.type === "expression")
|
|
15033
|
+
part.parsed = resolve2(part.parsed);
|
|
15034
|
+
}
|
|
15035
|
+
}
|
|
15036
|
+
if (value.kind === "expression" || spreads && value.kind === "spread") {
|
|
15037
|
+
const trimmed = value.expr.trim();
|
|
15038
|
+
if (trimmed)
|
|
15039
|
+
value.parsed = value.kind === "spread" ? parse2(trimmed) : parseValue(trimmed);
|
|
15040
|
+
}
|
|
14998
15041
|
};
|
|
14999
15042
|
if (node.type === "element") {
|
|
15000
15043
|
for (const attr of node.attrs)
|
|
@@ -15022,7 +15065,7 @@ function attachParsedExpressions(node, analyzer, scope = BindingScope.EMPTY) {
|
|
|
15022
15065
|
if (trimmed)
|
|
15023
15066
|
node.parsedCondition = parse2(trimmed);
|
|
15024
15067
|
}
|
|
15025
|
-
attachParsedAttrValues(node, parse2, parseValue);
|
|
15068
|
+
attachParsedAttrValues(node, parse2, parseValue, (parsed) => resolveCallbackMethodFunctionReferences(parsed, analyzer, bound));
|
|
15026
15069
|
switch (node.type) {
|
|
15027
15070
|
case "element":
|
|
15028
15071
|
case "component":
|
|
@@ -15737,8 +15780,12 @@ function cleanJsxWhitespace(raw) {
|
|
|
15737
15780
|
let line = lines[i].replace(/\t/g, " ");
|
|
15738
15781
|
if (!isFirstLine)
|
|
15739
15782
|
line = line.replace(/^ +/, "");
|
|
15740
|
-
if (!isLastLine)
|
|
15741
|
-
|
|
15783
|
+
if (!isLastLine) {
|
|
15784
|
+
let end = line.length;
|
|
15785
|
+
while (end > 0 && line[end - 1] === " ")
|
|
15786
|
+
end--;
|
|
15787
|
+
line = line.slice(0, end);
|
|
15788
|
+
}
|
|
15742
15789
|
if (line !== "")
|
|
15743
15790
|
kept.push(line);
|
|
15744
15791
|
}
|
|
@@ -17808,7 +17855,9 @@ function attrValueText(value) {
|
|
|
17808
17855
|
return "";
|
|
17809
17856
|
const out = [];
|
|
17810
17857
|
for (const p of value.parts) {
|
|
17811
|
-
if (p.type === "
|
|
17858
|
+
if (p.type === "expression")
|
|
17859
|
+
out.push(p.expr);
|
|
17860
|
+
else if (p.type === "ternary")
|
|
17812
17861
|
out.push(p.condition, p.whenTrue, p.whenFalse);
|
|
17813
17862
|
else if (p.type === "lookup")
|
|
17814
17863
|
out.push(p.key);
|
|
@@ -18543,7 +18592,7 @@ function parseTemplateLiteral(expr, ctx) {
|
|
|
18543
18592
|
} else {
|
|
18544
18593
|
const val = ctx.getJS(span.expression);
|
|
18545
18594
|
const tVal = rewriteBarePropRefs2(val, span.expression, ctx);
|
|
18546
|
-
parts.push({ type: "
|
|
18595
|
+
parts.push({ type: "expression", expr: val, templateExpr: tVal, parsed: parseValueExpr(val) });
|
|
18547
18596
|
}
|
|
18548
18597
|
} else {
|
|
18549
18598
|
const resolved = tryResolveTemplateSpanFromConst(span.expression, ctx);
|
|
@@ -18552,7 +18601,7 @@ function parseTemplateLiteral(expr, ctx) {
|
|
|
18552
18601
|
} else {
|
|
18553
18602
|
const val = ctx.getJS(span.expression);
|
|
18554
18603
|
const tVal = rewriteBarePropRefs2(val, span.expression, ctx);
|
|
18555
|
-
parts.push({ type: "
|
|
18604
|
+
parts.push({ type: "expression", expr: val, templateExpr: tVal, parsed: parseValueExpr(val) });
|
|
18556
18605
|
}
|
|
18557
18606
|
}
|
|
18558
18607
|
if (span.literal.text) {
|
|
@@ -18693,9 +18742,10 @@ function tryResolveIdentifierAsTemplateLiteral(ident, ctx) {
|
|
|
18693
18742
|
const text = astText(span.expression);
|
|
18694
18743
|
const templateText = rewriteBarePropRefs2(text, span.expression, ctx);
|
|
18695
18744
|
parts.push({
|
|
18696
|
-
type: "
|
|
18697
|
-
|
|
18698
|
-
|
|
18745
|
+
type: "expression",
|
|
18746
|
+
expr: text,
|
|
18747
|
+
templateExpr: templateText,
|
|
18748
|
+
parsed: parseValueExpr(text)
|
|
18699
18749
|
});
|
|
18700
18750
|
}
|
|
18701
18751
|
if (span.literal.text)
|
|
@@ -19330,11 +19380,13 @@ function attrValueReactivityProbe(value) {
|
|
|
19330
19380
|
case "template":
|
|
19331
19381
|
return value.parts.map((p) => {
|
|
19332
19382
|
if (p.type === "string")
|
|
19333
|
-
return
|
|
19383
|
+
return "";
|
|
19384
|
+
if (p.type === "expression")
|
|
19385
|
+
return p.expr;
|
|
19334
19386
|
if (p.type === "ternary")
|
|
19335
19387
|
return p.condition;
|
|
19336
19388
|
return p.key;
|
|
19337
|
-
}).join("");
|
|
19389
|
+
}).join(" ");
|
|
19338
19390
|
case "literal":
|
|
19339
19391
|
case "boolean-attr":
|
|
19340
19392
|
case "boolean-shorthand":
|
|
@@ -28154,8 +28206,8 @@ function collectAndPrefixAttrs(ir, layerName, referencedConstants, constantNames
|
|
|
28154
28206
|
case "template": {
|
|
28155
28207
|
prefixIRTemplateParts(attr.value.parts, layerName);
|
|
28156
28208
|
for (const part of attr.value.parts) {
|
|
28157
|
-
if (part.type === "
|
|
28158
|
-
collectConstantRefs(part.
|
|
28209
|
+
if (part.type === "expression") {
|
|
28210
|
+
collectConstantRefs(part.expr, referencedConstants, constantNames);
|
|
28159
28211
|
}
|
|
28160
28212
|
}
|
|
28161
28213
|
break;
|
|
@@ -28179,7 +28231,7 @@ function prefixIRTemplateParts(parts, layerName) {
|
|
|
28179
28231
|
if (part.type === "ternary") {
|
|
28180
28232
|
part.whenTrue = prefixClassString(part.whenTrue, layerName);
|
|
28181
28233
|
part.whenFalse = prefixClassString(part.whenFalse, layerName);
|
|
28182
|
-
} else if (part.type === "string"
|
|
28234
|
+
} else if (part.type === "string") {
|
|
28183
28235
|
part.value = prefixClassString(part.value, layerName);
|
|
28184
28236
|
}
|
|
28185
28237
|
}
|
|
@@ -28747,7 +28799,9 @@ function checkExpr(expr, loc, meta, bindings, matchers, errors, seen) {
|
|
|
28747
28799
|
}
|
|
28748
28800
|
function walkTemplateParts2(parts, loc, meta, bindings, matchers, errors, seen) {
|
|
28749
28801
|
for (const part of parts) {
|
|
28750
|
-
if (part.type === "
|
|
28802
|
+
if (part.type === "expression") {
|
|
28803
|
+
checkExpr(part.parsed, loc, meta, bindings, matchers, errors, seen);
|
|
28804
|
+
} else if (part.type === "ternary") {
|
|
28751
28805
|
const trimmed = part.condition.trim();
|
|
28752
28806
|
if (trimmed)
|
|
28753
28807
|
checkExpr(parseExpression(trimmed), loc, meta, bindings, matchers, errors, seen);
|
|
@@ -30219,1974 +30273,2021 @@ function callsOnlyGetters(init, getters) {
|
|
|
30219
30273
|
return ok;
|
|
30220
30274
|
}
|
|
30221
30275
|
|
|
30222
|
-
// src/
|
|
30223
|
-
function
|
|
30224
|
-
|
|
30225
|
-
|
|
30226
|
-
function collectNullableOptionalProps(ir) {
|
|
30227
|
-
return new Set([
|
|
30228
|
-
...ir.metadata.propsParams.filter((p) => p.defaultValue === undefined && !p.isRest && (p.type?.kind !== "primitive" || p.optional)).map((p) => p.name),
|
|
30229
|
-
...ir.metadata.restPropsExpandedKeys
|
|
30230
|
-
]);
|
|
30231
|
-
}
|
|
30232
|
-
function isBooleanTypedPropRef(expr, ctx) {
|
|
30233
|
-
let bare = expr.trim();
|
|
30234
|
-
if (ctx.propsObjectName && bare.startsWith(`${ctx.propsObjectName}.`)) {
|
|
30235
|
-
bare = bare.slice(ctx.propsObjectName.length + 1);
|
|
30236
|
-
}
|
|
30237
|
-
if (!/^[A-Za-z_$][\w$]*$/.test(bare))
|
|
30276
|
+
// src/loop-destructure.ts
|
|
30277
|
+
function isLowerableLoopDestructure(loop) {
|
|
30278
|
+
const bindings = loop.paramBindings;
|
|
30279
|
+
if (!bindings || bindings.length === 0)
|
|
30238
30280
|
return false;
|
|
30239
|
-
if (
|
|
30281
|
+
if (loop.filterPredicate)
|
|
30240
30282
|
return false;
|
|
30241
|
-
|
|
30283
|
+
for (const name of [...bindings.map((b) => b.name), loop.index]) {
|
|
30284
|
+
if (name && name.startsWith("__bf_"))
|
|
30285
|
+
return false;
|
|
30286
|
+
}
|
|
30287
|
+
for (const b of bindings) {
|
|
30288
|
+
if (b.rest) {
|
|
30289
|
+
if (!b.segments)
|
|
30290
|
+
return false;
|
|
30291
|
+
} else if (!b.segments || b.segments.length === 0) {
|
|
30292
|
+
return false;
|
|
30293
|
+
}
|
|
30294
|
+
}
|
|
30295
|
+
const objectRestNames = bindings.filter((b) => b.rest?.kind === "object").map((b) => b.name);
|
|
30296
|
+
if (objectRestNames.length === 0)
|
|
30297
|
+
return true;
|
|
30298
|
+
return !restNamesMisused(loop, objectRestNames);
|
|
30242
30299
|
}
|
|
30243
|
-
|
|
30244
|
-
|
|
30245
|
-
|
|
30246
|
-
const
|
|
30247
|
-
|
|
30248
|
-
|
|
30249
|
-
|
|
30250
|
-
|
|
30251
|
-
|
|
30252
|
-
|
|
30253
|
-
|
|
30254
|
-
|
|
30255
|
-
|
|
30256
|
-
const check = (scope) => {
|
|
30257
|
-
const byTarget = new Map;
|
|
30258
|
-
for (const name of new Set([...rootNames, ...scope.boundNames()])) {
|
|
30259
|
-
const target = ident(name);
|
|
30260
|
-
const group = byTarget.get(target);
|
|
30261
|
-
if (group)
|
|
30262
|
-
group.push(name);
|
|
30263
|
-
else
|
|
30264
|
-
byTarget.set(target, [name]);
|
|
30300
|
+
var isLowerableObjectRestDestructure = isLowerableLoopDestructure;
|
|
30301
|
+
function restNamesMisused(loop, names) {
|
|
30302
|
+
const nameSet = new Set(names);
|
|
30303
|
+
const valueUse = names.map((n) => new RegExp(`(?<![\\w.$])${escapeRe(n)}(?!\\s*\\??\\.)(?![\\w$])`));
|
|
30304
|
+
let misused = false;
|
|
30305
|
+
const check = (s) => {
|
|
30306
|
+
if (!s || misused)
|
|
30307
|
+
return;
|
|
30308
|
+
for (const re of valueUse) {
|
|
30309
|
+
if (re.test(s)) {
|
|
30310
|
+
misused = true;
|
|
30311
|
+
return;
|
|
30312
|
+
}
|
|
30265
30313
|
}
|
|
30266
|
-
|
|
30267
|
-
|
|
30268
|
-
|
|
30269
|
-
|
|
30270
|
-
|
|
30271
|
-
|
|
30272
|
-
|
|
30273
|
-
|
|
30274
|
-
|
|
30275
|
-
|
|
30276
|
-
severity: "error",
|
|
30277
|
-
message: `${list} both become the ${adapterName} template variable \`${target}\`, so they would read the same value. ${adapterName} reserves some names and renames them, and the new name collides with another name in this component.`,
|
|
30278
|
-
loc: { file: `${componentName}.tsx`, start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
30279
|
-
suggestion: {
|
|
30280
|
-
message: `Rename one of ${list} so the two names stay distinct after the ${adapterName} renaming.`,
|
|
30281
|
-
escape: [{ kind: "rewrite" }]
|
|
30282
|
-
}
|
|
30283
|
-
});
|
|
30314
|
+
};
|
|
30315
|
+
const attr = (v, isIntrinsicElementAttrs) => {
|
|
30316
|
+
if (v.kind === "spread" && isIntrinsicElementAttrs && nameSet.has(v.expr.trim())) {
|
|
30317
|
+
return;
|
|
30318
|
+
}
|
|
30319
|
+
if (v.kind === "expression" || v.kind === "spread") {
|
|
30320
|
+
check(v.expr);
|
|
30321
|
+
check(v.templateExpr);
|
|
30322
|
+
} else if (v.kind === "template") {
|
|
30323
|
+
v.parts.forEach(part);
|
|
30284
30324
|
}
|
|
30285
30325
|
};
|
|
30286
|
-
const
|
|
30287
|
-
if (
|
|
30326
|
+
const part = (p) => {
|
|
30327
|
+
if (p.type === "expression") {
|
|
30328
|
+
check(p.expr);
|
|
30329
|
+
check(p.templateExpr);
|
|
30330
|
+
} else if (p.type === "ternary") {
|
|
30331
|
+
check(p.condition);
|
|
30332
|
+
check(p.templateCondition);
|
|
30333
|
+
check(p.whenTrue);
|
|
30334
|
+
check(p.whenFalse);
|
|
30335
|
+
} else if (p.type === "lookup") {
|
|
30336
|
+
check(p.key);
|
|
30337
|
+
check(p.templateKey);
|
|
30338
|
+
}
|
|
30339
|
+
};
|
|
30340
|
+
const visitLoop = (l) => {
|
|
30341
|
+
if (misused)
|
|
30342
|
+
return;
|
|
30343
|
+
check(l.array);
|
|
30344
|
+
check(l.templateArray);
|
|
30345
|
+
check(l.key);
|
|
30346
|
+
if (l.preamble) {
|
|
30347
|
+
check(preambleAnalysisText(l.preamble));
|
|
30348
|
+
check(preambleAnalysisTemplateText(l.preamble));
|
|
30349
|
+
}
|
|
30350
|
+
if (l.flatMapCallback) {
|
|
30351
|
+
check(preambleAnalysisText(l.flatMapCallback));
|
|
30352
|
+
for (const seg of l.flatMapCallback.segments) {
|
|
30353
|
+
if (seg.kind === "jsx")
|
|
30354
|
+
visit3(seg.ir);
|
|
30355
|
+
}
|
|
30356
|
+
}
|
|
30357
|
+
l.children.forEach(visit3);
|
|
30358
|
+
};
|
|
30359
|
+
const visit3 = (node) => {
|
|
30360
|
+
if (misused)
|
|
30288
30361
|
return;
|
|
30289
30362
|
switch (node.type) {
|
|
30363
|
+
case "expression":
|
|
30364
|
+
check(node.expr);
|
|
30365
|
+
check(node.templateExpr);
|
|
30366
|
+
break;
|
|
30367
|
+
case "conditional":
|
|
30368
|
+
check(node.condition);
|
|
30369
|
+
check(node.templateCondition);
|
|
30370
|
+
visit3(node.whenTrue);
|
|
30371
|
+
visit3(node.whenFalse);
|
|
30372
|
+
break;
|
|
30373
|
+
case "if-statement":
|
|
30374
|
+
check(node.condition);
|
|
30375
|
+
check(node.templateCondition);
|
|
30376
|
+
for (const sv of node.scopeVariables) {
|
|
30377
|
+
check(sv.initializer);
|
|
30378
|
+
check(sv.templateInitializer);
|
|
30379
|
+
}
|
|
30380
|
+
visit3(node.consequent);
|
|
30381
|
+
if (node.alternate)
|
|
30382
|
+
visit3(node.alternate);
|
|
30383
|
+
break;
|
|
30290
30384
|
case "element":
|
|
30385
|
+
node.attrs.forEach((a) => attr(a.value, true));
|
|
30386
|
+
node.events.forEach((e) => check(e.handler));
|
|
30387
|
+
node.children.forEach(visit3);
|
|
30388
|
+
break;
|
|
30291
30389
|
case "component":
|
|
30292
|
-
|
|
30293
|
-
|
|
30294
|
-
for (const child of node.children)
|
|
30295
|
-
visit3(child, scope);
|
|
30390
|
+
node.props.forEach((p) => attr(p.value, false));
|
|
30391
|
+
node.children.forEach(visit3);
|
|
30296
30392
|
break;
|
|
30297
|
-
case "
|
|
30298
|
-
|
|
30299
|
-
|
|
30300
|
-
visit3(child, scope);
|
|
30393
|
+
case "provider":
|
|
30394
|
+
attr(node.valueProp.value, false);
|
|
30395
|
+
node.children.forEach(visit3);
|
|
30301
30396
|
break;
|
|
30302
|
-
case "
|
|
30303
|
-
|
|
30304
|
-
check(scope.enterCallback([node.filterPredicate.param]));
|
|
30305
|
-
const row = scope.enterLoopRow(node);
|
|
30306
|
-
check(row);
|
|
30307
|
-
for (const child of node.children)
|
|
30308
|
-
visit3(child, row);
|
|
30309
|
-
if (node.childComponent) {
|
|
30310
|
-
for (const child of node.childComponent.children)
|
|
30311
|
-
visit3(child, row);
|
|
30312
|
-
}
|
|
30313
|
-
for (const nested of node.nestedComponents ?? []) {
|
|
30314
|
-
for (const child of nested.children)
|
|
30315
|
-
visit3(child, row);
|
|
30316
|
-
}
|
|
30317
|
-
for (const seg of node.flatMapCallback?.segments ?? []) {
|
|
30318
|
-
if (seg.kind === "jsx")
|
|
30319
|
-
visit3(seg.ir, row);
|
|
30320
|
-
}
|
|
30321
|
-
for (const seg of node.preamble?.segments ?? []) {
|
|
30322
|
-
if (seg.kind === "jsx")
|
|
30323
|
-
visit3(seg.ir, row);
|
|
30324
|
-
}
|
|
30397
|
+
case "fragment":
|
|
30398
|
+
node.children.forEach(visit3);
|
|
30325
30399
|
break;
|
|
30326
|
-
|
|
30327
|
-
|
|
30328
|
-
|
|
30329
|
-
visit3(node.whenFalse, scope);
|
|
30400
|
+
case "async":
|
|
30401
|
+
visit3(node.fallback);
|
|
30402
|
+
node.children.forEach(visit3);
|
|
30330
30403
|
break;
|
|
30331
|
-
case "
|
|
30332
|
-
|
|
30333
|
-
if (node.alternate)
|
|
30334
|
-
visit3(node.alternate, scope);
|
|
30404
|
+
case "loop":
|
|
30405
|
+
visitLoop(node);
|
|
30335
30406
|
break;
|
|
30336
30407
|
case "text":
|
|
30337
|
-
case "expression":
|
|
30338
30408
|
case "slot":
|
|
30339
30409
|
break;
|
|
30340
30410
|
}
|
|
30341
30411
|
};
|
|
30342
|
-
|
|
30343
|
-
|
|
30344
|
-
return errors;
|
|
30412
|
+
visitLoop(loop);
|
|
30413
|
+
return misused;
|
|
30345
30414
|
}
|
|
30346
|
-
|
|
30347
|
-
|
|
30348
|
-
class DslTemplateAdapter extends BaseAdapter {
|
|
30349
|
-
componentName = "";
|
|
30350
|
-
errors = [];
|
|
30351
|
-
propsObjectName = null;
|
|
30352
|
-
restPropsName = null;
|
|
30353
|
-
propsParams = [];
|
|
30354
|
-
booleanTypedProps = new Set;
|
|
30355
|
-
stringValueNames = new Set;
|
|
30356
|
-
moduleStringConsts = new Map;
|
|
30357
|
-
_searchParamsLocals = new Set;
|
|
30358
|
-
_loweringMatchers = [];
|
|
30359
|
-
computedConsts = null;
|
|
30360
|
-
localConstants = [];
|
|
30361
|
-
rootPropAliases = new Map;
|
|
30362
|
-
scope = BindingScope.EMPTY;
|
|
30363
|
-
nullableOptionalProps = new Set;
|
|
30364
|
-
nullableSignalGetters = new Set;
|
|
30365
|
-
nullishAttrCtx = { nullableSignals: new Set, memos: new Map };
|
|
30366
|
-
importAliases = new Map;
|
|
30367
|
-
childrenCaptureCounter = 0;
|
|
30368
|
-
templateIdentifierSpelling = null;
|
|
30369
|
-
resetAdapterState(_ir) {}
|
|
30370
|
-
renderInScope(scope, render) {
|
|
30371
|
-
const outer = this.scope;
|
|
30372
|
-
this.scope = scope;
|
|
30373
|
-
try {
|
|
30374
|
-
return render();
|
|
30375
|
-
} finally {
|
|
30376
|
-
this.scope = outer;
|
|
30377
|
-
}
|
|
30378
|
-
}
|
|
30379
|
-
generate(ir, options) {
|
|
30380
|
-
this.resetCompileState(ir);
|
|
30381
|
-
this.collectCompileErrors(ir, options);
|
|
30382
|
-
const templateBody = ir.root.type === "if-statement" ? this.renderIfStatement(ir.root) : this.renderNode(ir.root);
|
|
30383
|
-
const scriptReg = options?.skipScriptRegistration ? "" : this.generateScriptRegistrations(ir, options?.scriptBaseName, options?.scriptAssets, options?.preloadAssets);
|
|
30384
|
-
const ctxSeed = this.contextConsumerSeed(ir);
|
|
30385
|
-
const memoSeed = this.derivedMemoSeed(ir);
|
|
30386
|
-
const template = `${scriptReg}${ctxSeed}${memoSeed}${templateBody}
|
|
30387
|
-
`;
|
|
30388
|
-
if (this.errors.length > 0) {
|
|
30389
|
-
ir.errors.push(...this.errors);
|
|
30390
|
-
}
|
|
30391
|
-
return {
|
|
30392
|
-
template,
|
|
30393
|
-
sections: { imports: "", types: "", component: template, defaultExport: "" },
|
|
30394
|
-
extension: this.extension
|
|
30395
|
-
};
|
|
30396
|
-
}
|
|
30397
|
-
resetCompileState(ir) {
|
|
30398
|
-
this.componentName = ir.metadata.componentName;
|
|
30399
|
-
this.propsObjectName = ir.metadata.propsObjectName ?? null;
|
|
30400
|
-
this.restPropsName = ir.metadata.restPropsName ?? null;
|
|
30401
|
-
augmentInheritedPropAccesses(ir);
|
|
30402
|
-
this.propsParams = ir.metadata.propsParams.map((p) => ({ name: p.name, optional: p.optional }));
|
|
30403
|
-
this.booleanTypedProps = collectBooleanTypedProps(ir);
|
|
30404
|
-
this.localConstants = ir.metadata.localConstants ?? [];
|
|
30405
|
-
this.rootPropAliases = rootPropAliasNames(ir, this.propsParams.map((p) => p.name));
|
|
30406
|
-
this.scope = BindingScope.EMPTY;
|
|
30407
|
-
this.nullableOptionalProps = collectNullableOptionalProps(ir);
|
|
30408
|
-
this.nullableSignalGetters = collectNullableSignalGetters(ir);
|
|
30409
|
-
this.nullishAttrCtx = collectNullishAttrContext(ir);
|
|
30410
|
-
this.stringValueNames = this.stringValueNamesFor(ir);
|
|
30411
|
-
this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants);
|
|
30412
|
-
this._searchParamsLocals = searchParamsLocalNames(ir.metadata);
|
|
30413
|
-
this._loweringMatchers = prepareLoweringMatchers(ir.metadata);
|
|
30414
|
-
this.computedConsts = computedConstContext(ir.metadata, (name) => this.scope.isBound(name));
|
|
30415
|
-
this.importAliases = buildImportAliasMap(ir.metadata.imports ?? []);
|
|
30416
|
-
this.childrenCaptureCounter = 0;
|
|
30417
|
-
this.errors = [];
|
|
30418
|
-
this.resetAdapterState(ir);
|
|
30419
|
-
}
|
|
30420
|
-
collectCompileErrors(ir, options) {
|
|
30421
|
-
const spelling = this.templateIdentifierSpelling;
|
|
30422
|
-
if (spelling) {
|
|
30423
|
-
const propNames = this.propsParams.map((p) => p.name);
|
|
30424
|
-
this.errors.push(...templateNameCollisionErrors(ir, propNames, spelling.ident, spelling.label, this.componentName));
|
|
30425
|
-
}
|
|
30426
|
-
if (!options?.siblingTemplatesRegistered) {
|
|
30427
|
-
this.errors.push(...collectImportedLoopChildComponentErrors(ir, this.componentName, this.loopChildDiagnosticName));
|
|
30428
|
-
}
|
|
30429
|
-
}
|
|
30415
|
+
function escapeRe(s) {
|
|
30416
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
30430
30417
|
}
|
|
30431
|
-
|
|
30432
|
-
|
|
30433
|
-
|
|
30434
|
-
|
|
30435
|
-
|
|
30436
|
-
|
|
30437
|
-
|
|
30438
|
-
|
|
30439
|
-
|
|
30440
|
-
|
|
30441
|
-
|
|
30442
|
-
|
|
30443
|
-
}
|
|
30444
|
-
if (namespaceSpec) {
|
|
30445
|
-
parts.push(`* as ${namespaceSpec.name}`);
|
|
30446
|
-
}
|
|
30447
|
-
if (namedSpecs.length > 0) {
|
|
30448
|
-
const named = namedSpecs.map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ");
|
|
30449
|
-
parts.push(`{ ${named} }`);
|
|
30450
|
-
}
|
|
30451
|
-
return parts.join(", ");
|
|
30452
|
-
}
|
|
30453
|
-
generateSignalInitializers(ir, jsxBody) {
|
|
30454
|
-
const lines = [];
|
|
30455
|
-
const { preserveTypes } = this.jsxConfig;
|
|
30456
|
-
const primaryRefs = [jsxBody];
|
|
30457
|
-
for (const signal of ir.metadata.signals) {
|
|
30458
|
-
if (signal.isModule)
|
|
30459
|
-
continue;
|
|
30460
|
-
primaryRefs.push(signal.initialValue);
|
|
30461
|
-
}
|
|
30462
|
-
for (const memo of ir.metadata.memos) {
|
|
30463
|
-
if (memo.isModule)
|
|
30464
|
-
continue;
|
|
30465
|
-
primaryRefs.push(memo.computation);
|
|
30466
|
-
}
|
|
30467
|
-
const primaryRefText = primaryRefs.join(`
|
|
30468
|
-
`);
|
|
30469
|
-
const localFunctions = ir.metadata.localFunctions.filter((f) => !f.isExported);
|
|
30470
|
-
const localConstants = ir.metadata.localConstants.filter((c) => !c.isExported && c.value);
|
|
30471
|
-
const declarations = [
|
|
30472
|
-
...localFunctions.map((f) => ({ name: f.name, body: f.body })),
|
|
30473
|
-
...localConstants.map((c) => ({ name: c.name, body: c.value }))
|
|
30474
|
-
];
|
|
30475
|
-
const reachable = closeOverWritersOfMutableBindings(primaryRefText, declarations, new Set(ir.metadata.localConstants.filter((c) => (c.declarationKind ?? "const") !== "const").map((c) => c.name)));
|
|
30476
|
-
const reachableBodies = [...reachable].map((name) => {
|
|
30477
|
-
const func = localFunctions.find((f) => f.name === name);
|
|
30478
|
-
if (func)
|
|
30479
|
-
return func.body;
|
|
30480
|
-
const constant = localConstants.find((c) => c.name === name);
|
|
30481
|
-
return constant?.value ?? "";
|
|
30482
|
-
}).join(`
|
|
30483
|
-
`);
|
|
30484
|
-
const setterRefText = primaryRefText + `
|
|
30485
|
-
` + reachableBodies;
|
|
30486
|
-
for (const signal of ir.metadata.signals) {
|
|
30487
|
-
if (signal.isModule)
|
|
30488
|
-
continue;
|
|
30489
|
-
if (signal.envReader) {
|
|
30490
|
-
const factory = signal.envFactory ?? ENV_SIGNAL_CLIENT_FACTORY[signal.envReader];
|
|
30491
|
-
if (factory) {
|
|
30492
|
-
lines.push(signal.setter ? ` const [${signal.getter}, ${signal.setter}] = ${factory}()` : ` const [${signal.getter}] = ${factory}()`);
|
|
30493
|
-
}
|
|
30494
|
-
continue;
|
|
30495
|
-
}
|
|
30496
|
-
if (!isElidedFactoryGetter(signal)) {
|
|
30497
|
-
const rawInitialValue = preserveTypes ? signal.typedInitialValue ?? signal.initialValue : signal.initialValue;
|
|
30498
|
-
const initialValue = rawInitialValue.trim().startsWith("{") ? `(${rawInitialValue})` : rawInitialValue;
|
|
30499
|
-
const needsTypeAssertion = preserveTypes && !signal.typedInitialValue && signal.type.kind !== "unknown" && signal.type.kind !== "primitive" && signal.type.raw !== "object";
|
|
30500
|
-
if (needsTypeAssertion) {
|
|
30501
|
-
lines.push(` const ${signal.getter} = () => ${initialValue} as ${signal.type.raw}`);
|
|
30502
|
-
} else {
|
|
30503
|
-
lines.push(` const ${signal.getter} = () => ${initialValue}`);
|
|
30418
|
+
|
|
30419
|
+
// src/static-literal.ts
|
|
30420
|
+
function evaluateStaticLiteral(expr, bindings) {
|
|
30421
|
+
switch (expr.kind) {
|
|
30422
|
+
case "literal":
|
|
30423
|
+
return { value: expr.value };
|
|
30424
|
+
case "template-literal": {
|
|
30425
|
+
let out = "";
|
|
30426
|
+
for (const part of expr.parts) {
|
|
30427
|
+
if (part.type === "string") {
|
|
30428
|
+
out += part.value;
|
|
30429
|
+
continue;
|
|
30504
30430
|
}
|
|
30431
|
+
const resolved = evaluateStaticLiteral(part.expr, bindings);
|
|
30432
|
+
if (!resolved)
|
|
30433
|
+
return null;
|
|
30434
|
+
out += String(resolved.value);
|
|
30505
30435
|
}
|
|
30506
|
-
|
|
30507
|
-
|
|
30508
|
-
|
|
30436
|
+
return { value: out };
|
|
30437
|
+
}
|
|
30438
|
+
case "array-literal": {
|
|
30439
|
+
const values = [];
|
|
30440
|
+
for (const element of expr.elements) {
|
|
30441
|
+
const resolved = evaluateStaticLiteral(element, bindings);
|
|
30442
|
+
if (!resolved)
|
|
30443
|
+
return null;
|
|
30444
|
+
values.push(resolved.value);
|
|
30509
30445
|
}
|
|
30510
|
-
|
|
30511
|
-
|
|
30512
|
-
|
|
30513
|
-
|
|
30514
|
-
|
|
30446
|
+
return { value: values };
|
|
30447
|
+
}
|
|
30448
|
+
case "object-literal": {
|
|
30449
|
+
const out = {};
|
|
30450
|
+
for (const prop of expr.properties) {
|
|
30451
|
+
if (prop.kind === "spread") {
|
|
30452
|
+
const resolved2 = evaluateStaticLiteral(prop.expr, bindings);
|
|
30453
|
+
if (!resolved2)
|
|
30454
|
+
return null;
|
|
30455
|
+
if (resolved2.value === null || resolved2.value === undefined)
|
|
30456
|
+
continue;
|
|
30457
|
+
if (typeof resolved2.value !== "object" || Array.isArray(resolved2.value))
|
|
30458
|
+
return null;
|
|
30459
|
+
Object.assign(out, resolved2.value);
|
|
30460
|
+
continue;
|
|
30515
30461
|
}
|
|
30462
|
+
const resolved = evaluateStaticLiteral(prop.value, bindings);
|
|
30463
|
+
if (!resolved)
|
|
30464
|
+
return null;
|
|
30465
|
+
out[prop.key] = resolved.value;
|
|
30516
30466
|
}
|
|
30467
|
+
return { value: out };
|
|
30517
30468
|
}
|
|
30518
|
-
|
|
30519
|
-
|
|
30520
|
-
|
|
30521
|
-
|
|
30522
|
-
|
|
30469
|
+
case "unary": {
|
|
30470
|
+
const resolved = evaluateStaticLiteral(expr.argument, bindings);
|
|
30471
|
+
if (!resolved)
|
|
30472
|
+
return null;
|
|
30473
|
+
if (expr.op === "-")
|
|
30474
|
+
return typeof resolved.value === "number" ? { value: -resolved.value } : null;
|
|
30475
|
+
if (expr.op === "+")
|
|
30476
|
+
return typeof resolved.value === "number" ? { value: +resolved.value } : null;
|
|
30477
|
+
if (expr.op === "!")
|
|
30478
|
+
return { value: !resolved.value };
|
|
30479
|
+
return null;
|
|
30523
30480
|
}
|
|
30524
|
-
|
|
30525
|
-
|
|
30526
|
-
|
|
30527
|
-
|
|
30528
|
-
if (
|
|
30529
|
-
|
|
30530
|
-
|
|
30531
|
-
if (!constant.value) {
|
|
30532
|
-
const typeAnnotation = preserveTypes && (constant.typeAnnotation ?? constant.type) ? `: ${constant.typeAnnotation ?? constant.type?.raw}` : "";
|
|
30533
|
-
lines.push(` ${keyword} ${constant.name}${typeAnnotation}`);
|
|
30534
|
-
continue;
|
|
30535
|
-
}
|
|
30536
|
-
if (constant.systemConstructKind)
|
|
30537
|
-
continue;
|
|
30538
|
-
if (!reachable.has(constant.name))
|
|
30539
|
-
continue;
|
|
30540
|
-
const constValue = preserveTypes ? constant.typedValue ?? constant.value : constant.value;
|
|
30541
|
-
const letTypeAnnotation = preserveTypes && keyword === "let" && constant.typeAnnotation ? `: ${constant.typeAnnotation}` : "";
|
|
30542
|
-
lines.push(` ${keyword} ${constant.name}${letTypeAnnotation} = ${constValue}`);
|
|
30481
|
+
case "identifier":
|
|
30482
|
+
return bindings?.has(expr.name) ? { value: bindings.get(expr.name) } : null;
|
|
30483
|
+
case "member": {
|
|
30484
|
+
const base = evaluateStaticLiteral(expr.object, bindings);
|
|
30485
|
+
if (!base || base.value === null || typeof base.value !== "object")
|
|
30486
|
+
return null;
|
|
30487
|
+
return { value: base.value[expr.property] };
|
|
30543
30488
|
}
|
|
30544
|
-
|
|
30545
|
-
|
|
30546
|
-
|
|
30547
|
-
if (!
|
|
30548
|
-
|
|
30549
|
-
|
|
30550
|
-
const returnAnnotation = preserveTypes && func.typedReturnType ? `: ${func.typedReturnType}` : "";
|
|
30551
|
-
const body = preserveTypes ? func.typedBody ?? func.body : func.body;
|
|
30552
|
-
const asyncKw = func.isAsync ? "async " : "";
|
|
30553
|
-
lines.push(` ${asyncKw}function ${func.name}(${params})${returnAnnotation} ${body}`);
|
|
30554
|
-
}
|
|
30555
|
-
return lines.join(`
|
|
30556
|
-
`);
|
|
30557
|
-
}
|
|
30558
|
-
moduleScopeNamesCache = new WeakMap;
|
|
30559
|
-
moduleScopeDeclarationNames(ir) {
|
|
30560
|
-
const cached = this.moduleScopeNamesCache.get(ir);
|
|
30561
|
-
if (cached)
|
|
30562
|
-
return cached;
|
|
30563
|
-
const componentScope = new Set;
|
|
30564
|
-
for (const sig of ir.metadata.signals) {
|
|
30565
|
-
if (sig.isModule)
|
|
30566
|
-
continue;
|
|
30567
|
-
componentScope.add(sig.getter);
|
|
30568
|
-
if (sig.setter)
|
|
30569
|
-
componentScope.add(sig.setter);
|
|
30570
|
-
}
|
|
30571
|
-
for (const memo of ir.metadata.memos) {
|
|
30572
|
-
if (!memo.isModule)
|
|
30573
|
-
componentScope.add(memo.name);
|
|
30574
|
-
}
|
|
30575
|
-
for (const p of ir.metadata.propsParams)
|
|
30576
|
-
componentScope.add(p.name);
|
|
30577
|
-
if (ir.metadata.propsObjectName)
|
|
30578
|
-
componentScope.add(ir.metadata.propsObjectName);
|
|
30579
|
-
if (ir.metadata.restPropsName)
|
|
30580
|
-
componentScope.add(ir.metadata.restPropsName);
|
|
30581
|
-
for (const c of ir.metadata.localConstants) {
|
|
30582
|
-
if (!c.isModule)
|
|
30583
|
-
componentScope.add(c.name);
|
|
30584
|
-
}
|
|
30585
|
-
for (const f of ir.metadata.localFunctions) {
|
|
30586
|
-
if (!f.isModule)
|
|
30587
|
-
componentScope.add(f.name);
|
|
30588
|
-
}
|
|
30589
|
-
const exported = new Set;
|
|
30590
|
-
const candidates = new Map;
|
|
30591
|
-
for (const c of ir.metadata.localConstants) {
|
|
30592
|
-
if (!c.isModule)
|
|
30593
|
-
continue;
|
|
30594
|
-
if (c.isJsx || c.isJsxFunction)
|
|
30595
|
-
continue;
|
|
30596
|
-
if (c.isExported) {
|
|
30597
|
-
exported.add(c.name);
|
|
30598
|
-
continue;
|
|
30599
|
-
}
|
|
30600
|
-
candidates.set(c.name, c.freeIdentifiers ?? extractFreeIdentifiersFromText(c.value ?? ""));
|
|
30601
|
-
}
|
|
30602
|
-
for (const f of ir.metadata.localFunctions) {
|
|
30603
|
-
if (!f.isModule)
|
|
30604
|
-
continue;
|
|
30605
|
-
if (f.isJsxFunction || f.isMultiReturnJsxHelper)
|
|
30606
|
-
continue;
|
|
30607
|
-
if (f.isExported) {
|
|
30608
|
-
exported.add(f.name);
|
|
30609
|
-
continue;
|
|
30610
|
-
}
|
|
30611
|
-
const params = f.typedParams !== undefined ? f.typedParams : f.params.map(formatParamWithType).join(", ");
|
|
30612
|
-
candidates.set(f.name, extractFreeIdentifiersFromText(`(${params}) => ${f.body}`));
|
|
30613
|
-
}
|
|
30614
|
-
const referencesAny = (refs, names) => {
|
|
30615
|
-
for (const ref of refs) {
|
|
30616
|
-
if (names.has(ref))
|
|
30617
|
-
return true;
|
|
30618
|
-
}
|
|
30619
|
-
return false;
|
|
30620
|
-
};
|
|
30621
|
-
let changed = true;
|
|
30622
|
-
while (changed) {
|
|
30623
|
-
changed = false;
|
|
30624
|
-
for (const [name, refs] of candidates) {
|
|
30625
|
-
if (referencesAny(refs, componentScope)) {
|
|
30626
|
-
candidates.delete(name);
|
|
30627
|
-
componentScope.add(name);
|
|
30628
|
-
changed = true;
|
|
30629
|
-
}
|
|
30630
|
-
}
|
|
30631
|
-
}
|
|
30632
|
-
const result = new Set([...exported, ...candidates.keys()]);
|
|
30633
|
-
this.moduleScopeNamesCache.set(ir, result);
|
|
30634
|
-
return result;
|
|
30635
|
-
}
|
|
30636
|
-
generateModuleScopeDeclarations(ir) {
|
|
30637
|
-
const { preserveTypes } = this.jsxConfig;
|
|
30638
|
-
const moduleNames = this.moduleScopeDeclarationNames(ir);
|
|
30639
|
-
const entries = [];
|
|
30640
|
-
for (const t of ir.metadata.typeDefinitions) {
|
|
30641
|
-
entries.push({ line: t.loc.start.line, text: t.definition });
|
|
30642
|
-
}
|
|
30643
|
-
for (const c of ir.metadata.localConstants) {
|
|
30644
|
-
if (!c.isModule || !moduleNames.has(c.name))
|
|
30645
|
-
continue;
|
|
30646
|
-
const keyword = c.declarationKind ?? "const";
|
|
30647
|
-
const exportKw = c.isExported ? "export " : "";
|
|
30648
|
-
if (!c.value) {
|
|
30649
|
-
const typeAnnotation = preserveTypes && (c.typeAnnotation ?? c.type) ? `: ${c.typeAnnotation ?? c.type?.raw}` : "";
|
|
30650
|
-
entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${typeAnnotation}` });
|
|
30651
|
-
continue;
|
|
30652
|
-
}
|
|
30653
|
-
if (c.systemConstructKind === "weakMap")
|
|
30654
|
-
continue;
|
|
30655
|
-
if (c.isExported && c.systemConstructKind === "createContext")
|
|
30656
|
-
continue;
|
|
30657
|
-
const value = preserveTypes ? c.typedValue ?? c.value : c.value;
|
|
30658
|
-
const letTypeAnnotation = preserveTypes && keyword === "let" && c.typeAnnotation ? `: ${c.typeAnnotation}` : "";
|
|
30659
|
-
entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${letTypeAnnotation} = ${value}` });
|
|
30660
|
-
}
|
|
30661
|
-
for (const f of ir.metadata.localFunctions) {
|
|
30662
|
-
if (!f.isModule || !moduleNames.has(f.name))
|
|
30663
|
-
continue;
|
|
30664
|
-
const params = preserveTypes && f.typedParams !== undefined ? f.typedParams : f.params.map(formatParamWithType).join(", ");
|
|
30665
|
-
const returnAnnotation = preserveTypes && f.typedReturnType ? `: ${f.typedReturnType}` : "";
|
|
30666
|
-
const body = preserveTypes ? f.typedBody ?? f.body : f.body;
|
|
30667
|
-
const asyncKw = f.isAsync ? "async " : "";
|
|
30668
|
-
const exportKw = f.isExported ? "export " : "";
|
|
30669
|
-
entries.push({
|
|
30670
|
-
line: f.loc.start.line,
|
|
30671
|
-
text: `${exportKw}${asyncKw}function ${f.name}(${params})${returnAnnotation} ${body}`
|
|
30672
|
-
});
|
|
30673
|
-
}
|
|
30674
|
-
entries.sort((a, b) => a.line - b.line);
|
|
30675
|
-
return entries.map((e) => e.text).join(`
|
|
30676
|
-
`);
|
|
30677
|
-
}
|
|
30678
|
-
renderNodeRaw(node) {
|
|
30679
|
-
if (node.type === "expression") {
|
|
30680
|
-
if (node.expr === "null" || node.expr === "undefined") {
|
|
30681
|
-
return "null";
|
|
30682
|
-
}
|
|
30683
|
-
return node.expr;
|
|
30684
|
-
}
|
|
30685
|
-
return this.renderNode(node);
|
|
30686
|
-
}
|
|
30687
|
-
renderTemplatePartsAsJs(parts) {
|
|
30688
|
-
return templatePartsToJsExpr(parts, { typed: this.jsxConfig.preserveTypes });
|
|
30689
|
-
}
|
|
30690
|
-
expressionValueToJs(value) {
|
|
30691
|
-
if (this.jsxConfig.preserveTypes && value.typed && value.expr === value.typed.forExpr) {
|
|
30692
|
-
return value.typed.tsx;
|
|
30693
|
-
}
|
|
30694
|
-
if (this.jsxConfig.preserveTypes && value.parts && value.expr === templatePartsToJsExpr(value.parts)) {
|
|
30695
|
-
return this.renderTemplatePartsAsJs(value.parts);
|
|
30489
|
+
case "index-access": {
|
|
30490
|
+
const base = evaluateStaticLiteral(expr.object, bindings);
|
|
30491
|
+
const index = evaluateStaticLiteral(expr.index, bindings);
|
|
30492
|
+
if (!base || !index || !Array.isArray(base.value) || typeof index.value !== "number")
|
|
30493
|
+
return null;
|
|
30494
|
+
return { value: base.value[index.value] };
|
|
30696
30495
|
}
|
|
30697
|
-
|
|
30496
|
+
default:
|
|
30497
|
+
return null;
|
|
30698
30498
|
}
|
|
30699
|
-
|
|
30700
|
-
|
|
30499
|
+
}
|
|
30500
|
+
function isFullyStaticLiteral(expr) {
|
|
30501
|
+
return evaluateStaticLiteral(expr) !== null;
|
|
30502
|
+
}
|
|
30503
|
+
function resolveStaticLoopSource(arrayParsed, localConstants, opts) {
|
|
30504
|
+
if (!arrayParsed)
|
|
30505
|
+
return null;
|
|
30506
|
+
let target = arrayParsed;
|
|
30507
|
+
if (arrayParsed.kind === "identifier") {
|
|
30508
|
+
if (opts?.isNameShadowed?.(arrayParsed.name))
|
|
30509
|
+
return null;
|
|
30510
|
+
const local = localConstants?.find((c) => c.name === arrayParsed.name);
|
|
30511
|
+
if (!local?.parsed || local.mutatedAfterDeclaration)
|
|
30512
|
+
return null;
|
|
30513
|
+
target = local.parsed;
|
|
30701
30514
|
}
|
|
30702
|
-
|
|
30703
|
-
|
|
30515
|
+
const resolved = evaluateStaticLiteral(target);
|
|
30516
|
+
if (!resolved || !Array.isArray(resolved.value))
|
|
30517
|
+
return null;
|
|
30518
|
+
return resolved.value;
|
|
30519
|
+
}
|
|
30520
|
+
|
|
30521
|
+
// src/adapters/callback-method.ts
|
|
30522
|
+
var PREDICATE_EVAL = {
|
|
30523
|
+
filter: { helper: "filter_eval" },
|
|
30524
|
+
every: { helper: "every_eval" },
|
|
30525
|
+
some: { helper: "some_eval" },
|
|
30526
|
+
find: { helper: "find_eval", forward: true },
|
|
30527
|
+
findLast: { helper: "find_eval", forward: false },
|
|
30528
|
+
findIndex: { helper: "find_index_eval", forward: true },
|
|
30529
|
+
findLastIndex: { helper: "find_index_eval", forward: false }
|
|
30530
|
+
};
|
|
30531
|
+
function isPredicateMethod(method) {
|
|
30532
|
+
return Object.hasOwn(PREDICATE_EVAL, method);
|
|
30533
|
+
}
|
|
30534
|
+
function lowerCallbackMethod(method, arrow, restArgs, options) {
|
|
30535
|
+
const { adapterName } = options;
|
|
30536
|
+
const { body, params } = arrow;
|
|
30537
|
+
if (isPredicateMethod(method))
|
|
30538
|
+
return lowerPredicate(method, arrow, options);
|
|
30539
|
+
if (method === "sort" || method === "toSorted")
|
|
30540
|
+
return lowerSortComparator(method, arrow, adapterName);
|
|
30541
|
+
if (method === "reduce" || method === "reduceRight") {
|
|
30542
|
+
const init = restArgs[0];
|
|
30543
|
+
const plan = init ? reduceEvalPlan(body, params, init, method === "reduceRight" ? "right" : "left") : null;
|
|
30544
|
+
return plan ?? {
|
|
30545
|
+
kind: "refuse",
|
|
30546
|
+
message: `'.${method}(...)' is outside the ${adapterName} adapter's evaluable surface (needs a literal initial value and an evaluable reducer body)`,
|
|
30547
|
+
suggestion: `Pre-compute the reduced value, or move this position to a '/* @client */' boundary.`
|
|
30548
|
+
};
|
|
30704
30549
|
}
|
|
30705
|
-
|
|
30706
|
-
|
|
30550
|
+
if (method === "flatMap" || method === "map") {
|
|
30551
|
+
const plan = projectionEvalPlan(method === "map" ? "map_eval" : "flat_map_eval", body, params);
|
|
30552
|
+
return plan ?? {
|
|
30553
|
+
kind: "refuse",
|
|
30554
|
+
message: `'.${method}(...)' projection is outside the ${adapterName} adapter's evaluable surface`,
|
|
30555
|
+
suggestion: `Pre-compute the projected array, or move this position to a '/* @client */' boundary.`
|
|
30556
|
+
};
|
|
30707
30557
|
}
|
|
30558
|
+
return { kind: "receiver" };
|
|
30708
30559
|
}
|
|
30709
|
-
|
|
30710
|
-
|
|
30711
|
-
|
|
30712
|
-
|
|
30713
|
-
"
|
|
30714
|
-
|
|
30715
|
-
|
|
30716
|
-
|
|
30717
|
-
|
|
30718
|
-
|
|
30719
|
-
|
|
30720
|
-
|
|
30721
|
-
|
|
30722
|
-
|
|
30723
|
-
|
|
30724
|
-
|
|
30560
|
+
function lowerPredicate(method, arrow, options) {
|
|
30561
|
+
const param = String(arrow.params[0]);
|
|
30562
|
+
const native = { kind: "native-predicate", method, param, predicate: arrow.body };
|
|
30563
|
+
const nativeOk = options.nativePredicate === true && !hasOpaqueCall(arrow.body) && !readsNestedCallbackIndex(arrow.body);
|
|
30564
|
+
const identity = method === "filter" && arrow.body.kind === "identifier" && arrow.body.name === param;
|
|
30565
|
+
if (nativeOk && identity)
|
|
30566
|
+
return native;
|
|
30567
|
+
const json = serializeParsedExpr(arrow.body);
|
|
30568
|
+
if (json !== null) {
|
|
30569
|
+
const { helper, forward } = PREDICATE_EVAL[method];
|
|
30570
|
+
const operands = [
|
|
30571
|
+
{ kind: "string", value: json },
|
|
30572
|
+
{ kind: "string", value: param }
|
|
30573
|
+
];
|
|
30574
|
+
if (forward !== undefined)
|
|
30575
|
+
operands.push({ kind: "boolean", value: forward });
|
|
30576
|
+
return { kind: "eval", helper, operands, captured: freeVarsInBody(arrow.body, new Set(arrow.params.slice(0, 1))) };
|
|
30725
30577
|
}
|
|
30726
|
-
|
|
30727
|
-
|
|
30728
|
-
|
|
30729
|
-
|
|
30730
|
-
|
|
30731
|
-
|
|
30578
|
+
if (nativeOk)
|
|
30579
|
+
return native;
|
|
30580
|
+
return {
|
|
30581
|
+
kind: "refuse",
|
|
30582
|
+
message: `'.${method}(...)' predicate is outside the ${options.adapterName} adapter's evaluable surface`,
|
|
30583
|
+
suggestion: `Rewrite the predicate as a pure expression the evaluator can serialize (no nested method-call callbacks), or move this position to a '/* @client */' boundary.`
|
|
30584
|
+
};
|
|
30585
|
+
}
|
|
30586
|
+
function lowerSortComparator(method, arrow, adapterName) {
|
|
30587
|
+
const plan = sortEvalPlan(arrow.body, arrow.params);
|
|
30588
|
+
if (plan)
|
|
30589
|
+
return plan;
|
|
30590
|
+
const comparator = sortComparatorFromArrow(arrow);
|
|
30591
|
+
if (comparator)
|
|
30592
|
+
return { kind: "structured-sort", comparator };
|
|
30593
|
+
return sortRefusal(method, adapterName);
|
|
30594
|
+
}
|
|
30595
|
+
function sortEvalPlan(body, params) {
|
|
30596
|
+
const json = serializeParsedExpr(body);
|
|
30597
|
+
if (json === null || params.length < 2)
|
|
30598
|
+
return null;
|
|
30599
|
+
return {
|
|
30600
|
+
kind: "eval",
|
|
30601
|
+
helper: "sort_eval",
|
|
30602
|
+
operands: [
|
|
30603
|
+
{ kind: "string", value: json },
|
|
30604
|
+
{ kind: "string", value: params[0] },
|
|
30605
|
+
{ kind: "string", value: params[1] }
|
|
30606
|
+
],
|
|
30607
|
+
captured: freeVarsInBody(body, new Set(params))
|
|
30608
|
+
};
|
|
30609
|
+
}
|
|
30610
|
+
function sortRefusal(method, adapterName) {
|
|
30611
|
+
return {
|
|
30612
|
+
kind: "refuse",
|
|
30613
|
+
message: `'.${method}(...)' comparator is outside the ${adapterName} adapter's evaluable / structured surface`,
|
|
30614
|
+
suggestion: `Pre-compute the sorted array, or move this position to a '/* @client */' boundary.`
|
|
30615
|
+
};
|
|
30616
|
+
}
|
|
30617
|
+
function reduceEvalPlan(body, params, init, direction) {
|
|
30618
|
+
const json = serializeParsedExpr(body);
|
|
30619
|
+
if (json === null || init.kind !== "literal" || params.length < 2)
|
|
30620
|
+
return null;
|
|
30621
|
+
let seed;
|
|
30622
|
+
if (init.literalType === "string")
|
|
30623
|
+
seed = { kind: "string", value: String(init.value) };
|
|
30624
|
+
else if (init.literalType === "number")
|
|
30625
|
+
seed = { kind: "number", text: String(init.value) };
|
|
30626
|
+
else
|
|
30627
|
+
return null;
|
|
30628
|
+
return {
|
|
30629
|
+
kind: "eval",
|
|
30630
|
+
helper: "reduce_eval",
|
|
30631
|
+
operands: [
|
|
30632
|
+
{ kind: "string", value: json },
|
|
30633
|
+
{ kind: "string", value: params[0] },
|
|
30634
|
+
{ kind: "string", value: params[1] },
|
|
30635
|
+
seed,
|
|
30636
|
+
{ kind: "string", value: direction }
|
|
30637
|
+
],
|
|
30638
|
+
captured: freeVarsInBody(body, new Set(params))
|
|
30639
|
+
};
|
|
30640
|
+
}
|
|
30641
|
+
function projectionEvalPlan(helper, body, params) {
|
|
30642
|
+
const json = serializeParsedExpr(body);
|
|
30643
|
+
if (json === null)
|
|
30644
|
+
return null;
|
|
30645
|
+
return {
|
|
30646
|
+
kind: "eval",
|
|
30647
|
+
helper,
|
|
30648
|
+
operands: [
|
|
30649
|
+
{ kind: "string", value: json },
|
|
30650
|
+
{ kind: "string", value: String(params[0]) }
|
|
30651
|
+
],
|
|
30652
|
+
captured: freeVarsInBody(body, new Set(params.slice(0, 1)))
|
|
30653
|
+
};
|
|
30654
|
+
}
|
|
30655
|
+
function emitCallbackEval(plan, recv, emit, spelling) {
|
|
30656
|
+
const operands = [recv];
|
|
30657
|
+
for (const operand of plan.operands) {
|
|
30658
|
+
if (operand.kind === "string")
|
|
30659
|
+
operands.push(spelling.string(operand.value));
|
|
30660
|
+
else if (operand.kind === "number")
|
|
30661
|
+
operands.push(operand.text);
|
|
30662
|
+
else
|
|
30663
|
+
operands.push(spelling.boolean(operand.value));
|
|
30664
|
+
}
|
|
30665
|
+
const env = plan.captured.map((name) => [name, emit({ kind: "identifier", name })]);
|
|
30666
|
+
operands.push(spelling.env(env));
|
|
30667
|
+
return spelling.call(plan.helper, operands);
|
|
30668
|
+
}
|
|
30669
|
+
function isUnloweredCall(callee, args, propsObjectName, isGlobal) {
|
|
30670
|
+
if (args.length === 0) {
|
|
30671
|
+
const root = memberRoot(callee);
|
|
30672
|
+
return root !== null && isGlobal(root);
|
|
30673
|
+
}
|
|
30674
|
+
return !(callee.kind === "member" && callee.object.kind === "identifier" && callee.object.name === propsObjectName);
|
|
30675
|
+
}
|
|
30676
|
+
function memberRoot(callee) {
|
|
30677
|
+
if (callee.kind !== "member" && callee.kind !== "index-access")
|
|
30678
|
+
return null;
|
|
30679
|
+
let object = callee.object;
|
|
30680
|
+
while (object.kind === "member" || object.kind === "index-access")
|
|
30681
|
+
object = object.object;
|
|
30682
|
+
return object.kind === "identifier" ? object.name : null;
|
|
30683
|
+
}
|
|
30684
|
+
function unloweredCallRefusal(callee, args, adapterName) {
|
|
30685
|
+
const name = stringifyParsedExpr(callee);
|
|
30686
|
+
return {
|
|
30687
|
+
message: args.length === 0 ? `Call '${name}()' reads a JavaScript global, which has no ${adapterName} template binding; read as a value it would drop the call` : `Call '${name}(...)' has no ${adapterName} template lowering; read as a value it would drop the call and its arguments`,
|
|
30688
|
+
suggestion: "Pre-compute the value in the backend and pass it as a prop, or add /* @client */ for client-only evaluation (no SSR)."
|
|
30689
|
+
};
|
|
30690
|
+
}
|
|
30691
|
+
function filterPredicateShapeRefusal(shape, adapterName) {
|
|
30692
|
+
return {
|
|
30693
|
+
message: `Filter predicate contains ${shape}, which has no ${adapterName} loop-filter form`,
|
|
30694
|
+
suggestion: `Rewrite the predicate as comparisons joined with && / || / !, or add /* @client */ for client-only evaluation (no SSR).`
|
|
30695
|
+
};
|
|
30696
|
+
}
|
|
30697
|
+
function missingFilterPredicateRefusal(raw, adapterName) {
|
|
30698
|
+
return {
|
|
30699
|
+
message: `Filter predicate '${raw}' has no ${adapterName} loop-filter form`,
|
|
30700
|
+
suggestion: `Rewrite the predicate as an expression-body arrow, or add /* @client */ for client-only evaluation (no SSR).`
|
|
30701
|
+
};
|
|
30702
|
+
}
|
|
30703
|
+
function nestedCallbackRefusal(method, adapterName) {
|
|
30704
|
+
return {
|
|
30705
|
+
message: `Filter predicate contains a nested '.${method}(...)' callback, which has no ${adapterName} scalar form`,
|
|
30706
|
+
suggestion: `Rewrite the predicate without a nested callback method, or add /* @client */ for client-only evaluation (no SSR).`
|
|
30707
|
+
};
|
|
30708
|
+
}
|
|
30709
|
+
|
|
30710
|
+
// src/adapters/filter-capture-collisions.ts
|
|
30711
|
+
function filterCaptureCollisions(loop) {
|
|
30712
|
+
const filter = loop.filterPredicate;
|
|
30713
|
+
if (!filter?.predicate)
|
|
30714
|
+
return [];
|
|
30715
|
+
const free = freeIdentifiers(filter.predicate);
|
|
30716
|
+
if (!free)
|
|
30717
|
+
return [];
|
|
30718
|
+
free.delete(filter.param);
|
|
30719
|
+
const rowBound = new Set(loop.paramBindings && loop.paramBindings.length > 0 ? loop.paramBindings.map((b) => b.name) : [loop.param]);
|
|
30720
|
+
if (loop.index)
|
|
30721
|
+
rowBound.add(loop.index);
|
|
30722
|
+
return [...free].filter((name) => rowBound.has(name)).sort();
|
|
30723
|
+
}
|
|
30724
|
+
|
|
30725
|
+
// src/adapters/loop-plan.ts
|
|
30726
|
+
function spellDestructureLocals(plan, item, spelling) {
|
|
30727
|
+
return plan.destructureLocals.map(({ name, value }) => {
|
|
30728
|
+
const parent = spelling.accessor(item, value.segments);
|
|
30729
|
+
if (value.kind === "slice")
|
|
30730
|
+
return { name, value: spelling.slice(parent, value.from) };
|
|
30731
|
+
if (value.kind === "omit")
|
|
30732
|
+
return { name, value: spelling.omit(parent, value.exclude) };
|
|
30733
|
+
return { name, value: parent };
|
|
30734
|
+
});
|
|
30735
|
+
}
|
|
30736
|
+
function spellSortedSource(sort, recv, spelling) {
|
|
30737
|
+
if (!sort)
|
|
30738
|
+
return recv;
|
|
30739
|
+
if (sort.kind === "eval")
|
|
30740
|
+
return emitCallbackEval(sort, recv, spelling.emit, spelling.eval);
|
|
30741
|
+
if (sort.kind === "structured-sort")
|
|
30742
|
+
return spelling.structured(recv, sort.comparator);
|
|
30743
|
+
spelling.refuse(sort.message, sort.suggestion);
|
|
30744
|
+
return recv;
|
|
30745
|
+
}
|
|
30746
|
+
function loopHeaderTargets(loop, plan) {
|
|
30747
|
+
if (loop.objectIteration === "entries")
|
|
30748
|
+
return [loop.index ?? loop.param, loop.param];
|
|
30749
|
+
return loop.objectIteration || plan.itemVar === loop.param ? [loop.param] : [];
|
|
30750
|
+
}
|
|
30751
|
+
var SAVE_ORDER = ["item", "index", "destructure", "preamble"];
|
|
30752
|
+
function savedLoopBindings(scopes, skip, temporary) {
|
|
30753
|
+
const skipped = new Set(skip);
|
|
30754
|
+
const rank = (name) => SAVE_ORDER.indexOf(scopes.row.lookup(name)?.binding.source ?? "param");
|
|
30755
|
+
return scopes.row.innermostNames().filter((name) => !skipped.has(name) && (scopes.templateLevelNames.has(name) || scopes.outside.isBound(name))).sort((a, b) => rank(a) - rank(b)).map((name, ordinal) => {
|
|
30756
|
+
let held = temporary(name, ordinal);
|
|
30757
|
+
while (scopes.row.isBound(held) || scopes.templateLevelNames.has(held))
|
|
30758
|
+
held += "_";
|
|
30759
|
+
return { name, temporary: held };
|
|
30760
|
+
});
|
|
30761
|
+
}
|
|
30762
|
+
function spellFilteredRow(filter, row, spelling) {
|
|
30763
|
+
if (!filter)
|
|
30764
|
+
return [...row];
|
|
30765
|
+
return [spelling.open(filterCondition(filter, spelling)), ...row, spelling.close];
|
|
30766
|
+
}
|
|
30767
|
+
function filterCondition(filter, spelling) {
|
|
30768
|
+
if (filter.kind === "predicate")
|
|
30769
|
+
return spelling.condition(filter);
|
|
30770
|
+
spelling.refuse(filter.message, filter.suggestion);
|
|
30771
|
+
return spelling.refused;
|
|
30772
|
+
}
|
|
30773
|
+
function filterPlan(loop, captureAliases, adapterName) {
|
|
30774
|
+
const filter = loop.filterPredicate;
|
|
30775
|
+
if (!filter)
|
|
30776
|
+
return null;
|
|
30777
|
+
if (!filter.predicate)
|
|
30778
|
+
return { kind: "refuse", ...missingFilterPredicateRefusal(filter.raw, adapterName) };
|
|
30779
|
+
const captureRenames = new Map(captureAliases.map(({ name, alias }) => [name, alias]));
|
|
30780
|
+
const rowRenames = new Map(captureRenames);
|
|
30781
|
+
if (filter.param !== loop.param)
|
|
30782
|
+
rowRenames.set(filter.param, loop.param);
|
|
30783
|
+
return {
|
|
30784
|
+
kind: "predicate",
|
|
30785
|
+
param: filter.param,
|
|
30786
|
+
predicate: filter.predicate,
|
|
30787
|
+
captured: renameFreeIdentifiers(filter.predicate, captureRenames),
|
|
30788
|
+
onRow: renameFreeIdentifiers(filter.predicate, rowRenames),
|
|
30789
|
+
aliases: new Map(captureAliases.map(({ name, alias }) => [alias, name]))
|
|
30790
|
+
};
|
|
30791
|
+
}
|
|
30792
|
+
function planLoop(loop, ctx) {
|
|
30793
|
+
const staticItems = resolveStaticLoopSource(loop.arrayParsed, ctx.localConstants, {
|
|
30794
|
+
isNameShadowed: ctx.scope.asShadowPredicate()
|
|
30795
|
+
});
|
|
30796
|
+
const staticSource = staticItems !== null ? ctx.spellStatic(staticItems) : null;
|
|
30797
|
+
const destructure = destructureKind(loop);
|
|
30798
|
+
const captureAliases = filterCaptureCollisions(loop).map((name) => ({ name, alias: `__bf_cap_${loop.markerId}_${name}` }));
|
|
30799
|
+
return {
|
|
30800
|
+
destructure,
|
|
30801
|
+
staticSource,
|
|
30802
|
+
unresolvableConst: staticSource === null ? unresolvableConst(loop, ctx) : null,
|
|
30803
|
+
sort: loop.sortComparator ? lowerSortComparator("sort", loop.sortComparator.arrow, ctx.callbackLowering.adapterName) : null,
|
|
30804
|
+
captureAliases,
|
|
30805
|
+
filter: filterPlan(loop, captureAliases, ctx.callbackLowering.adapterName),
|
|
30806
|
+
itemVar: loop.iterationShape === "keys" || destructure === "lowerable" ? "__bf_item" : loop.param,
|
|
30807
|
+
indexLocal: indexLocal(loop),
|
|
30808
|
+
destructureLocals: destructure === "lowerable" ? destructureLocals(loop) : []
|
|
30809
|
+
};
|
|
30810
|
+
}
|
|
30811
|
+
function indexLocal(loop) {
|
|
30812
|
+
if (loop.objectIteration)
|
|
30813
|
+
return null;
|
|
30814
|
+
return loop.iterationShape === "keys" ? loop.param : loop.index;
|
|
30815
|
+
}
|
|
30816
|
+
function destructureLocals(loop) {
|
|
30817
|
+
return (loop.paramBindings ?? []).map((b) => {
|
|
30818
|
+
const segments = b.segments ?? [];
|
|
30819
|
+
if (b.rest?.kind === "array")
|
|
30820
|
+
return { name: b.name, value: { kind: "slice", segments, from: b.rest.from } };
|
|
30821
|
+
if (b.rest?.kind === "object")
|
|
30822
|
+
return { name: b.name, value: { kind: "omit", segments, exclude: b.rest.exclude.map((k) => k.key) } };
|
|
30823
|
+
return { name: b.name, value: { kind: "path", segments } };
|
|
30824
|
+
});
|
|
30825
|
+
}
|
|
30826
|
+
function destructureKind(loop) {
|
|
30827
|
+
if (!loop.paramBindings || loop.paramBindings.length === 0)
|
|
30828
|
+
return "none";
|
|
30829
|
+
return isLowerableLoopDestructure(loop) ? "lowerable" : "unlowerable";
|
|
30830
|
+
}
|
|
30831
|
+
function unresolvableConst(loop, ctx) {
|
|
30832
|
+
const source = loop.arrayParsed ?? parseExpression(loop.array.trim());
|
|
30833
|
+
if (source?.kind !== "identifier")
|
|
30834
|
+
return null;
|
|
30835
|
+
const name = source.name;
|
|
30836
|
+
if (ctx.scope.isBound(name))
|
|
30837
|
+
return null;
|
|
30838
|
+
const constant = ctx.localConstants.find((c) => c.name === name);
|
|
30839
|
+
return constant && ctx.resolveLiteralConst(name) === null ? constant : null;
|
|
30840
|
+
}
|
|
30841
|
+
|
|
30842
|
+
// src/adapters/prop-classes.ts
|
|
30843
|
+
function collectBooleanTypedProps(ir) {
|
|
30844
|
+
return new Set(ir.metadata.propsParams.filter((prop) => prop.type?.primitive === "boolean" || prop.type?.raw === "boolean").map((prop) => prop.name));
|
|
30845
|
+
}
|
|
30846
|
+
function collectNullableOptionalProps(ir) {
|
|
30847
|
+
return new Set([
|
|
30848
|
+
...ir.metadata.propsParams.filter((p) => p.defaultValue === undefined && !p.isRest && (p.type?.kind !== "primitive" || p.optional)).map((p) => p.name),
|
|
30849
|
+
...ir.metadata.restPropsExpandedKeys
|
|
30850
|
+
]);
|
|
30851
|
+
}
|
|
30852
|
+
function isBooleanTypedPropRef(expr, ctx) {
|
|
30853
|
+
let bare = expr.trim();
|
|
30854
|
+
if (ctx.propsObjectName && bare.startsWith(`${ctx.propsObjectName}.`)) {
|
|
30855
|
+
bare = bare.slice(ctx.propsObjectName.length + 1);
|
|
30856
|
+
}
|
|
30857
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(bare))
|
|
30858
|
+
return false;
|
|
30859
|
+
if (ctx.isBound(bare))
|
|
30860
|
+
return false;
|
|
30861
|
+
return ctx.booleanTypedProps.has(bare);
|
|
30862
|
+
}
|
|
30863
|
+
|
|
30864
|
+
// src/adapters/template-name-collisions.ts
|
|
30865
|
+
function templateNameCollisionErrors(ir, propNames, ident, adapterName, componentName) {
|
|
30866
|
+
const { metadata } = ir;
|
|
30867
|
+
const rootNames = new Set([
|
|
30868
|
+
...propNames,
|
|
30869
|
+
...metadata.localConstants.map((c) => c.name),
|
|
30870
|
+
...metadata.localFunctions.map((f) => f.name),
|
|
30871
|
+
...metadata.signals.flatMap((s) => s.setter ? [s.getter, s.setter] : [s.getter]),
|
|
30872
|
+
...metadata.memos.map((m) => m.name)
|
|
30873
|
+
]);
|
|
30874
|
+
const errors = [];
|
|
30875
|
+
const reported = new Set;
|
|
30876
|
+
const check = (scope) => {
|
|
30877
|
+
const byTarget = new Map;
|
|
30878
|
+
for (const name of new Set([...rootNames, ...scope.boundNames()])) {
|
|
30879
|
+
const target = ident(name);
|
|
30880
|
+
const group = byTarget.get(target);
|
|
30881
|
+
if (group)
|
|
30882
|
+
group.push(name);
|
|
30883
|
+
else
|
|
30884
|
+
byTarget.set(target, [name]);
|
|
30732
30885
|
}
|
|
30733
|
-
const
|
|
30734
|
-
|
|
30735
|
-
|
|
30736
|
-
|
|
30737
|
-
|
|
30738
|
-
|
|
30739
|
-
|
|
30886
|
+
for (const [target, group] of byTarget) {
|
|
30887
|
+
if (group.length < 2)
|
|
30888
|
+
continue;
|
|
30889
|
+
const key = `${target}\x00${[...group].sort().join("\x00")}`;
|
|
30890
|
+
if (reported.has(key))
|
|
30891
|
+
continue;
|
|
30892
|
+
reported.add(key);
|
|
30893
|
+
const list = group.map((n) => `\`${n}\``).join(" and ");
|
|
30894
|
+
errors.push({
|
|
30895
|
+
code: "BF105",
|
|
30896
|
+
severity: "error",
|
|
30897
|
+
message: `${list} both become the ${adapterName} template variable \`${target}\`, so they would read the same value. ${adapterName} reserves some names and renames them, and the new name collides with another name in this component.`,
|
|
30898
|
+
loc: { file: `${componentName}.tsx`, start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
30899
|
+
suggestion: {
|
|
30900
|
+
message: `Rename one of ${list} so the two names stay distinct after the ${adapterName} renaming.`,
|
|
30901
|
+
escape: [{ kind: "rewrite" }]
|
|
30902
|
+
}
|
|
30903
|
+
});
|
|
30904
|
+
}
|
|
30905
|
+
};
|
|
30906
|
+
const visit3 = (node, scope) => {
|
|
30907
|
+
if (!node)
|
|
30908
|
+
return;
|
|
30909
|
+
switch (node.type) {
|
|
30910
|
+
case "element":
|
|
30911
|
+
case "component":
|
|
30912
|
+
case "fragment":
|
|
30913
|
+
case "provider":
|
|
30914
|
+
for (const child of node.children)
|
|
30915
|
+
visit3(child, scope);
|
|
30916
|
+
break;
|
|
30917
|
+
case "async":
|
|
30918
|
+
visit3(node.fallback, scope);
|
|
30919
|
+
for (const child of node.children)
|
|
30920
|
+
visit3(child, scope);
|
|
30921
|
+
break;
|
|
30922
|
+
case "loop": {
|
|
30923
|
+
if (node.filterPredicate)
|
|
30924
|
+
check(scope.enterCallback([node.filterPredicate.param]));
|
|
30925
|
+
const row = scope.enterLoopRow(node);
|
|
30926
|
+
check(row);
|
|
30927
|
+
for (const child of node.children)
|
|
30928
|
+
visit3(child, row);
|
|
30929
|
+
if (node.childComponent) {
|
|
30930
|
+
for (const child of node.childComponent.children)
|
|
30931
|
+
visit3(child, row);
|
|
30740
30932
|
}
|
|
30933
|
+
for (const nested of node.nestedComponents ?? []) {
|
|
30934
|
+
for (const child of nested.children)
|
|
30935
|
+
visit3(child, row);
|
|
30936
|
+
}
|
|
30937
|
+
for (const seg of node.flatMapCallback?.segments ?? []) {
|
|
30938
|
+
if (seg.kind === "jsx")
|
|
30939
|
+
visit3(seg.ir, row);
|
|
30940
|
+
}
|
|
30941
|
+
for (const seg of node.preamble?.segments ?? []) {
|
|
30942
|
+
if (seg.kind === "jsx")
|
|
30943
|
+
visit3(seg.ir, row);
|
|
30944
|
+
}
|
|
30945
|
+
break;
|
|
30741
30946
|
}
|
|
30742
|
-
|
|
30743
|
-
|
|
30744
|
-
|
|
30745
|
-
|
|
30746
|
-
|
|
30747
|
-
|
|
30748
|
-
|
|
30749
|
-
|
|
30750
|
-
|
|
30947
|
+
case "conditional":
|
|
30948
|
+
visit3(node.whenTrue, scope);
|
|
30949
|
+
visit3(node.whenFalse, scope);
|
|
30950
|
+
break;
|
|
30951
|
+
case "if-statement":
|
|
30952
|
+
visit3(node.consequent, scope);
|
|
30953
|
+
if (node.alternate)
|
|
30954
|
+
visit3(node.alternate, scope);
|
|
30955
|
+
break;
|
|
30956
|
+
case "text":
|
|
30957
|
+
case "expression":
|
|
30958
|
+
case "slot":
|
|
30959
|
+
break;
|
|
30751
30960
|
}
|
|
30752
|
-
}
|
|
30753
|
-
|
|
30754
|
-
|
|
30755
|
-
|
|
30756
|
-
return `${s.isDefault ? "d" : ""}${s.isNamespace ? "n" : ""}:${s.name}:${s.alias ?? ""}`;
|
|
30961
|
+
};
|
|
30962
|
+
check(BindingScope.EMPTY);
|
|
30963
|
+
visit3(ir.root, BindingScope.EMPTY);
|
|
30964
|
+
return errors;
|
|
30757
30965
|
}
|
|
30758
|
-
|
|
30759
|
-
|
|
30760
|
-
|
|
30761
|
-
|
|
30762
|
-
|
|
30763
|
-
|
|
30764
|
-
|
|
30765
|
-
|
|
30966
|
+
|
|
30967
|
+
// src/adapters/dsl-template-adapter.ts
|
|
30968
|
+
class DslTemplateAdapter extends BaseAdapter {
|
|
30969
|
+
componentName = "";
|
|
30970
|
+
errors = [];
|
|
30971
|
+
propsObjectName = null;
|
|
30972
|
+
restPropsName = null;
|
|
30973
|
+
propsParams = [];
|
|
30974
|
+
booleanTypedProps = new Set;
|
|
30975
|
+
stringValueNames = new Set;
|
|
30976
|
+
moduleStringConsts = new Map;
|
|
30977
|
+
_searchParamsLocals = new Set;
|
|
30978
|
+
_loweringMatchers = [];
|
|
30979
|
+
computedConsts = null;
|
|
30980
|
+
localConstants = [];
|
|
30981
|
+
rootPropAliases = new Map;
|
|
30982
|
+
scope = BindingScope.EMPTY;
|
|
30983
|
+
nullableOptionalProps = new Set;
|
|
30984
|
+
nullableSignalGetters = new Set;
|
|
30985
|
+
nullishAttrCtx = { nullableSignals: new Set, memos: new Map };
|
|
30986
|
+
importAliases = new Map;
|
|
30987
|
+
childrenCaptureCounter = 0;
|
|
30988
|
+
inLoop = false;
|
|
30989
|
+
templateIdentifierSpelling = null;
|
|
30990
|
+
resetAdapterState(_ir) {}
|
|
30991
|
+
renderInScope(scope, render) {
|
|
30992
|
+
const outer = this.scope;
|
|
30993
|
+
this.scope = scope;
|
|
30994
|
+
try {
|
|
30995
|
+
return render();
|
|
30996
|
+
} finally {
|
|
30997
|
+
this.scope = outer;
|
|
30766
30998
|
}
|
|
30767
|
-
|
|
30768
|
-
|
|
30769
|
-
|
|
30770
|
-
|
|
30999
|
+
}
|
|
31000
|
+
loopPlanFor(loop, spelling) {
|
|
31001
|
+
return planLoop(loop, { scope: this.scope, localConstants: this.localConstants ?? [], ...spelling });
|
|
31002
|
+
}
|
|
31003
|
+
recordLoopPlanRefusals(loop, plan, spelling) {
|
|
31004
|
+
const loc = loop.loc ?? { file: this.componentName + ".tsx", start: { line: 1, column: 0 }, end: { line: 1, column: 0 } };
|
|
31005
|
+
if (plan.destructure === "unlowerable") {
|
|
31006
|
+
this.errors.push({
|
|
31007
|
+
code: "BF104",
|
|
31008
|
+
severity: "error",
|
|
31009
|
+
message: spelling.destructureMessage(loop.param),
|
|
31010
|
+
loc,
|
|
31011
|
+
suggestion: { message: spelling.destructureSuggestion }
|
|
31012
|
+
});
|
|
30771
31013
|
}
|
|
30772
|
-
|
|
30773
|
-
|
|
30774
|
-
const collect = (literal) => {
|
|
30775
|
-
const specifier = literal.text;
|
|
30776
|
-
if (!specifier.startsWith("."))
|
|
31014
|
+
const constant = plan.unresolvableConst;
|
|
31015
|
+
if (!constant)
|
|
30777
31016
|
return;
|
|
30778
|
-
|
|
30779
|
-
|
|
31017
|
+
if (typeof spelling.unresolvableConst === "function") {
|
|
31018
|
+
spelling.unresolvableConst(constant);
|
|
30780
31019
|
return;
|
|
30781
|
-
|
|
30782
|
-
|
|
30783
|
-
|
|
30784
|
-
|
|
31020
|
+
}
|
|
31021
|
+
this.errors.push({
|
|
31022
|
+
code: "BF101",
|
|
31023
|
+
severity: "error",
|
|
31024
|
+
message: `Loop array \`${constant.name}\` is a const (module- or function-scope) computed value (\`${constant.value}\`) that the ${spelling.unresolvableConst} adapter cannot bind as a template variable — only numeric/string-literal locals inline at their use site.`,
|
|
31025
|
+
loc,
|
|
31026
|
+
suggestion: {
|
|
31027
|
+
message: "Pre-compute the array server-side and pass it as a prop, or mark the loop position as @client-only so it runs in JS on the client.",
|
|
31028
|
+
escape: [{ kind: "prop-precompute" }, { kind: "client-directive" }]
|
|
31029
|
+
}
|
|
30785
31030
|
});
|
|
30786
|
-
};
|
|
30787
|
-
ts33.forEachChild(sf, visit3);
|
|
30788
|
-
if (edits.length === 0)
|
|
30789
|
-
return sourceText;
|
|
30790
|
-
let out = sourceText;
|
|
30791
|
-
for (const edit of edits.sort((a, b) => b.start - a.start)) {
|
|
30792
|
-
out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
|
|
30793
31031
|
}
|
|
30794
|
-
|
|
30795
|
-
|
|
30796
|
-
|
|
30797
|
-
|
|
30798
|
-
|
|
30799
|
-
|
|
30800
|
-
|
|
30801
|
-
|
|
30802
|
-
|
|
30803
|
-
|
|
30804
|
-
|
|
30805
|
-
|
|
30806
|
-
|
|
30807
|
-
const
|
|
30808
|
-
|
|
30809
|
-
|
|
30810
|
-
|
|
30811
|
-
|
|
30812
|
-
|
|
30813
|
-
|
|
30814
|
-
|
|
30815
|
-
|
|
30816
|
-
|
|
30817
|
-
|
|
30818
|
-
const
|
|
30819
|
-
|
|
30820
|
-
|
|
31032
|
+
renderLoopRow(loop, spelling) {
|
|
31033
|
+
const outside = this.scope;
|
|
31034
|
+
const row = outside.enterLoopRow(loop);
|
|
31035
|
+
return this.renderInScope(row, () => {
|
|
31036
|
+
spelling.enter?.(row, outside);
|
|
31037
|
+
const preamble = (loop.preamble?.declarations ?? []).map((d) => spelling.preamble(d));
|
|
31038
|
+
const children = this.renderInLoop(() => this.renderChildren(loop.children));
|
|
31039
|
+
const body = loop.bodyIsItemConditional && loop.key ? `${spelling.keyAnchor(loop.key)}
|
|
31040
|
+
${children}` : children;
|
|
31041
|
+
return { outside, row, rootAliases: rootPropAliasesForLoop(outside, row, this.rootPropAliases), preamble, body };
|
|
31042
|
+
});
|
|
31043
|
+
}
|
|
31044
|
+
renderInLoop(render) {
|
|
31045
|
+
const outer = this.inLoop;
|
|
31046
|
+
this.inLoop = true;
|
|
31047
|
+
try {
|
|
31048
|
+
return render();
|
|
31049
|
+
} finally {
|
|
31050
|
+
this.inLoop = outer;
|
|
31051
|
+
}
|
|
31052
|
+
}
|
|
31053
|
+
generate(ir, options) {
|
|
31054
|
+
this.resetCompileState(ir);
|
|
31055
|
+
this.collectCompileErrors(ir, options);
|
|
31056
|
+
const templateBody = ir.root.type === "if-statement" ? this.renderIfStatement(ir.root) : this.renderNode(ir.root);
|
|
31057
|
+
const scriptReg = options?.skipScriptRegistration ? "" : this.generateScriptRegistrations(ir, options?.scriptBaseName, options?.scriptAssets, options?.preloadAssets);
|
|
31058
|
+
const ctxSeed = this.contextConsumerSeed(ir);
|
|
31059
|
+
const memoSeed = this.derivedMemoSeed(ir);
|
|
31060
|
+
const template = `${scriptReg}${ctxSeed}${memoSeed}${templateBody}
|
|
31061
|
+
`;
|
|
31062
|
+
if (this.errors.length > 0) {
|
|
31063
|
+
ir.errors.push(...this.errors);
|
|
31064
|
+
}
|
|
30821
31065
|
return {
|
|
30822
31066
|
template,
|
|
30823
|
-
sections,
|
|
30824
|
-
types: types || undefined,
|
|
31067
|
+
sections: { imports: "", types: "", component: template, defaultExport: "" },
|
|
30825
31068
|
extension: this.extension
|
|
30826
31069
|
};
|
|
30827
31070
|
}
|
|
30828
|
-
|
|
30829
|
-
|
|
30830
|
-
|
|
30831
|
-
|
|
30832
|
-
|
|
30833
|
-
|
|
30834
|
-
|
|
30835
|
-
|
|
30836
|
-
|
|
30837
|
-
|
|
30838
|
-
|
|
30839
|
-
|
|
30840
|
-
|
|
30841
|
-
|
|
30842
|
-
|
|
30843
|
-
|
|
30844
|
-
|
|
30845
|
-
|
|
31071
|
+
resetCompileState(ir) {
|
|
31072
|
+
this.componentName = ir.metadata.componentName;
|
|
31073
|
+
this.propsObjectName = ir.metadata.propsObjectName ?? null;
|
|
31074
|
+
this.restPropsName = ir.metadata.restPropsName ?? null;
|
|
31075
|
+
augmentInheritedPropAccesses(ir);
|
|
31076
|
+
this.propsParams = ir.metadata.propsParams.map((p) => ({ name: p.name, optional: p.optional }));
|
|
31077
|
+
this.booleanTypedProps = collectBooleanTypedProps(ir);
|
|
31078
|
+
this.localConstants = ir.metadata.localConstants ?? [];
|
|
31079
|
+
this.rootPropAliases = rootPropAliasNames(ir, this.propsParams.map((p) => p.name));
|
|
31080
|
+
this.scope = BindingScope.EMPTY;
|
|
31081
|
+
this.nullableOptionalProps = collectNullableOptionalProps(ir);
|
|
31082
|
+
this.nullableSignalGetters = collectNullableSignalGetters(ir);
|
|
31083
|
+
this.nullishAttrCtx = collectNullishAttrContext(ir);
|
|
31084
|
+
this.stringValueNames = this.stringValueNamesFor(ir);
|
|
31085
|
+
this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants);
|
|
31086
|
+
this._searchParamsLocals = searchParamsLocalNames(ir.metadata);
|
|
31087
|
+
this._loweringMatchers = prepareLoweringMatchers(ir.metadata);
|
|
31088
|
+
this.computedConsts = computedConstContext(ir.metadata, (name) => this.scope.isBound(name));
|
|
31089
|
+
this.importAliases = buildImportAliasMap(ir.metadata.imports ?? []);
|
|
31090
|
+
this.childrenCaptureCounter = 0;
|
|
31091
|
+
this.inLoop = false;
|
|
31092
|
+
this.errors = [];
|
|
31093
|
+
this.resetAdapterState(ir);
|
|
30846
31094
|
}
|
|
30847
|
-
|
|
30848
|
-
const
|
|
30849
|
-
|
|
30850
|
-
|
|
30851
|
-
|
|
30852
|
-
|
|
30853
|
-
|
|
30854
|
-
|
|
30855
|
-
lines.push("}");
|
|
31095
|
+
collectCompileErrors(ir, options) {
|
|
31096
|
+
const spelling = this.templateIdentifierSpelling;
|
|
31097
|
+
if (spelling) {
|
|
31098
|
+
const propNames = this.propsParams.map((p) => p.name);
|
|
31099
|
+
this.errors.push(...templateNameCollisionErrors(ir, propNames, spelling.ident, spelling.label, this.componentName));
|
|
31100
|
+
}
|
|
31101
|
+
if (!options?.siblingTemplatesRegistered) {
|
|
31102
|
+
this.errors.push(...collectImportedLoopChildComponentErrors(ir, this.componentName, this.loopChildDiagnosticName));
|
|
30856
31103
|
}
|
|
30857
|
-
return lines.length > 0 ? lines.join(`
|
|
30858
|
-
`) : null;
|
|
30859
31104
|
}
|
|
30860
|
-
|
|
30861
|
-
|
|
30862
|
-
|
|
30863
|
-
|
|
30864
|
-
|
|
30865
|
-
|
|
30866
|
-
|
|
30867
|
-
const
|
|
30868
|
-
const
|
|
30869
|
-
|
|
30870
|
-
const bfScopeAlias = /\b__bfScope\b/.test(bodyRefText) ? "__bfScope" : "__bfScope: _bfScope";
|
|
30871
|
-
const propsParams = ir.metadata.propsParams.map((p) => propsDestructureBinding(p)).join(", ");
|
|
30872
|
-
const restPropsName = ir.metadata.restPropsName;
|
|
30873
|
-
const hydrationProps = `__instanceId, ${bfScopeAlias}`;
|
|
31105
|
+
}
|
|
31106
|
+
// src/adapters/jsx-adapter.ts
|
|
31107
|
+
import { BF_SCOPE as BF_SCOPE4, BF_SLOT, BF_COND } from "@barefootjs/shared";
|
|
31108
|
+
class JsxAdapter extends BaseAdapter {
|
|
31109
|
+
componentName = "";
|
|
31110
|
+
acceptsCallbackBody = () => true;
|
|
31111
|
+
formatImportSpecifiers(specifiers) {
|
|
31112
|
+
const defaultSpec = specifiers.find((s) => s.isDefault);
|
|
31113
|
+
const namespaceSpec = specifiers.find((s) => s.isNamespace);
|
|
31114
|
+
const namedSpecs = specifiers.filter((s) => !s.isDefault && !s.isNamespace);
|
|
30874
31115
|
const parts = [];
|
|
30875
|
-
if (
|
|
30876
|
-
parts.push(
|
|
30877
|
-
}
|
|
30878
|
-
parts.push(hydrationProps);
|
|
30879
|
-
if (restPropsName) {
|
|
30880
|
-
parts.push(`...${restPropsName}`);
|
|
31116
|
+
if (defaultSpec) {
|
|
31117
|
+
parts.push(defaultSpec.alias || defaultSpec.name);
|
|
30881
31118
|
}
|
|
30882
|
-
|
|
30883
|
-
|
|
30884
|
-
const propsTypeExpr = typeAnnotation.replace(/^:\s*/, "");
|
|
30885
|
-
const noArgDefault = hasRequiredProps ? "" : ` = {} as ${propsTypeExpr}`;
|
|
30886
|
-
const lines = [];
|
|
30887
|
-
const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
|
|
30888
|
-
const typeParameters = ir.metadata.typeParameters ?? "";
|
|
30889
|
-
lines.push(`${exportPrefix}function ${name}${typeParameters}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
|
|
30890
|
-
if (hasClientInteractivity2) {
|
|
30891
|
-
lines.push(` const __scopeId = (/_s\\d/.test(__bfScope || '') ? __bfScope : null) || __instanceId || \`${name}_\${Math.random().toString(36).slice(2, 8)}\``);
|
|
30892
|
-
} else {
|
|
30893
|
-
lines.push(` const __scopeId = __bfScope || __instanceId || \`${name}_\${Math.random().toString(36).slice(2, 8)}\``);
|
|
31119
|
+
if (namespaceSpec) {
|
|
31120
|
+
parts.push(`* as ${namespaceSpec.name}`);
|
|
30894
31121
|
}
|
|
30895
|
-
if (
|
|
30896
|
-
|
|
31122
|
+
if (namedSpecs.length > 0) {
|
|
31123
|
+
const named = namedSpecs.map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ");
|
|
31124
|
+
parts.push(`{ ${named} }`);
|
|
30897
31125
|
}
|
|
30898
|
-
|
|
30899
|
-
lines.push(` return (`);
|
|
30900
|
-
lines.push(` ${jsxBody}`);
|
|
30901
|
-
lines.push(` )`);
|
|
30902
|
-
lines.push(`}`);
|
|
30903
|
-
return lines.join(`
|
|
30904
|
-
`);
|
|
31126
|
+
return parts.join(", ");
|
|
30905
31127
|
}
|
|
30906
|
-
|
|
30907
|
-
|
|
30908
|
-
|
|
30909
|
-
|
|
30910
|
-
|
|
30911
|
-
|
|
30912
|
-
|
|
30913
|
-
|
|
30914
|
-
case "conditional":
|
|
30915
|
-
return this.renderConditional(node);
|
|
30916
|
-
case "loop":
|
|
30917
|
-
return this.renderLoop(node);
|
|
30918
|
-
case "component":
|
|
30919
|
-
return this.renderComponent(node);
|
|
30920
|
-
case "fragment":
|
|
30921
|
-
return this.renderFragment(node);
|
|
30922
|
-
case "slot":
|
|
30923
|
-
return "{children}";
|
|
30924
|
-
default:
|
|
30925
|
-
return "";
|
|
31128
|
+
generateSignalInitializers(ir, jsxBody) {
|
|
31129
|
+
const lines = [];
|
|
31130
|
+
const { preserveTypes } = this.jsxConfig;
|
|
31131
|
+
const primaryRefs = [jsxBody];
|
|
31132
|
+
for (const signal of ir.metadata.signals) {
|
|
31133
|
+
if (signal.isModule)
|
|
31134
|
+
continue;
|
|
31135
|
+
primaryRefs.push(signal.initialValue);
|
|
30926
31136
|
}
|
|
30927
|
-
|
|
30928
|
-
|
|
30929
|
-
|
|
30930
|
-
|
|
30931
|
-
const children = this.renderChildren(element.children);
|
|
30932
|
-
let hydrationAttrs = "";
|
|
30933
|
-
if (element.needsScope) {
|
|
30934
|
-
hydrationAttrs += " bf-s={__scopeId}";
|
|
31137
|
+
for (const memo of ir.metadata.memos) {
|
|
31138
|
+
if (memo.isModule)
|
|
31139
|
+
continue;
|
|
31140
|
+
primaryRefs.push(memo.computation);
|
|
30935
31141
|
}
|
|
30936
|
-
|
|
30937
|
-
|
|
31142
|
+
const primaryRefText = primaryRefs.join(`
|
|
31143
|
+
`);
|
|
31144
|
+
const localFunctions = ir.metadata.localFunctions.filter((f) => !f.isExported);
|
|
31145
|
+
const localConstants = ir.metadata.localConstants.filter((c) => !c.isExported && c.value);
|
|
31146
|
+
const declarations = [
|
|
31147
|
+
...localFunctions.map((f) => ({ name: f.name, body: f.body })),
|
|
31148
|
+
...localConstants.map((c) => ({ name: c.name, body: c.value }))
|
|
31149
|
+
];
|
|
31150
|
+
const reachable = closeOverWritersOfMutableBindings(primaryRefText, declarations, new Set(ir.metadata.localConstants.filter((c) => (c.declarationKind ?? "const") !== "const").map((c) => c.name)));
|
|
31151
|
+
const reachableBodies = [...reachable].map((name) => {
|
|
31152
|
+
const func = localFunctions.find((f) => f.name === name);
|
|
31153
|
+
if (func)
|
|
31154
|
+
return func.body;
|
|
31155
|
+
const constant = localConstants.find((c) => c.name === name);
|
|
31156
|
+
return constant?.value ?? "";
|
|
31157
|
+
}).join(`
|
|
31158
|
+
`);
|
|
31159
|
+
const setterRefText = primaryRefText + `
|
|
31160
|
+
` + reachableBodies;
|
|
31161
|
+
for (const signal of ir.metadata.signals) {
|
|
31162
|
+
if (signal.isModule)
|
|
31163
|
+
continue;
|
|
31164
|
+
if (signal.envReader) {
|
|
31165
|
+
const factory = signal.envFactory ?? ENV_SIGNAL_CLIENT_FACTORY[signal.envReader];
|
|
31166
|
+
if (factory) {
|
|
31167
|
+
lines.push(signal.setter ? ` const [${signal.getter}, ${signal.setter}] = ${factory}()` : ` const [${signal.getter}] = ${factory}()`);
|
|
31168
|
+
}
|
|
31169
|
+
continue;
|
|
31170
|
+
}
|
|
31171
|
+
if (!isElidedFactoryGetter(signal)) {
|
|
31172
|
+
const rawInitialValue = preserveTypes ? signal.typedInitialValue ?? signal.initialValue : signal.initialValue;
|
|
31173
|
+
const initialValue = rawInitialValue.trim().startsWith("{") ? `(${rawInitialValue})` : rawInitialValue;
|
|
31174
|
+
const needsTypeAssertion = preserveTypes && !signal.typedInitialValue && signal.type.kind !== "unknown" && signal.type.kind !== "primitive" && signal.type.raw !== "object";
|
|
31175
|
+
if (needsTypeAssertion) {
|
|
31176
|
+
lines.push(` const ${signal.getter} = () => ${initialValue} as ${signal.type.raw}`);
|
|
31177
|
+
} else {
|
|
31178
|
+
lines.push(` const ${signal.getter} = () => ${initialValue}`);
|
|
31179
|
+
}
|
|
31180
|
+
}
|
|
31181
|
+
const action = signal.factory?.action;
|
|
31182
|
+
if (action && identifierPattern(action).test(setterRefText)) {
|
|
31183
|
+
lines.push(preserveTypes ? ` const ${action}: any = Object.assign(() => {}, { isPending: () => false, error: () => undefined })` : ` const ${action} = Object.assign(() => {}, { isPending: () => false, error: () => undefined })`);
|
|
31184
|
+
}
|
|
31185
|
+
if (signal.setter) {
|
|
31186
|
+
const setterUsed = identifierPattern(signal.setter).test(setterRefText);
|
|
31187
|
+
if (setterUsed) {
|
|
31188
|
+
const setterType = preserveTypes && signal.type.kind !== "unknown" ? `(valueOrFn: ${signal.type.raw} | ((prev: ${signal.type.raw}) => ${signal.type.raw})) => void` : null;
|
|
31189
|
+
lines.push(setterType ? ` const ${signal.setter}: ${setterType} = () => {}` : ` const ${signal.setter} = (..._args: any[]) => {}`);
|
|
31190
|
+
}
|
|
31191
|
+
}
|
|
30938
31192
|
}
|
|
30939
|
-
|
|
30940
|
-
|
|
30941
|
-
|
|
30942
|
-
|
|
31193
|
+
for (const memo of ir.metadata.memos) {
|
|
31194
|
+
if (memo.isModule)
|
|
31195
|
+
continue;
|
|
31196
|
+
const computation = preserveTypes ? memo.typedComputation ?? memo.computation : memo.computation;
|
|
31197
|
+
lines.push(` const ${memo.name} = ${computation}`);
|
|
30943
31198
|
}
|
|
30944
|
-
|
|
30945
|
-
|
|
30946
|
-
|
|
30947
|
-
|
|
31199
|
+
const moduleScopeNames = this.moduleScopeDeclarationNames(ir);
|
|
31200
|
+
for (const constant of ir.metadata.localConstants) {
|
|
31201
|
+
if (constant.isExported)
|
|
31202
|
+
continue;
|
|
31203
|
+
if (moduleScopeNames.has(constant.name))
|
|
31204
|
+
continue;
|
|
31205
|
+
const keyword = constant.declarationKind ?? "const";
|
|
31206
|
+
if (!constant.value) {
|
|
31207
|
+
const typeAnnotation = preserveTypes && (constant.typeAnnotation ?? constant.type) ? `: ${constant.typeAnnotation ?? constant.type?.raw}` : "";
|
|
31208
|
+
lines.push(` ${keyword} ${constant.name}${typeAnnotation}`);
|
|
31209
|
+
continue;
|
|
31210
|
+
}
|
|
31211
|
+
if (constant.systemConstructKind)
|
|
31212
|
+
continue;
|
|
31213
|
+
if (!reachable.has(constant.name))
|
|
31214
|
+
continue;
|
|
31215
|
+
const constValue = preserveTypes ? constant.typedValue ?? constant.value : constant.value;
|
|
31216
|
+
const letTypeAnnotation = preserveTypes && keyword === "let" && constant.typeAnnotation ? `: ${constant.typeAnnotation}` : "";
|
|
31217
|
+
lines.push(` ${keyword} ${constant.name}${letTypeAnnotation} = ${constValue}`);
|
|
30948
31218
|
}
|
|
30949
|
-
|
|
30950
|
-
|
|
31219
|
+
for (const func of localFunctions) {
|
|
31220
|
+
if (moduleScopeNames.has(func.name))
|
|
31221
|
+
continue;
|
|
31222
|
+
if (!reachable.has(func.name))
|
|
31223
|
+
continue;
|
|
31224
|
+
const params = preserveTypes && func.typedParams !== undefined ? func.typedParams : func.params.map(formatParamWithType).join(", ");
|
|
31225
|
+
const returnAnnotation = preserveTypes && func.typedReturnType ? `: ${func.typedReturnType}` : "";
|
|
31226
|
+
const body = preserveTypes ? func.typedBody ?? func.body : func.body;
|
|
31227
|
+
const asyncKw = func.isAsync ? "async " : "";
|
|
31228
|
+
lines.push(` ${asyncKw}function ${func.name}(${params})${returnAnnotation} ${body}`);
|
|
30951
31229
|
}
|
|
30952
|
-
return `
|
|
31230
|
+
return lines.join(`
|
|
31231
|
+
`);
|
|
30953
31232
|
}
|
|
30954
|
-
|
|
30955
|
-
|
|
30956
|
-
|
|
30957
|
-
if (
|
|
30958
|
-
|
|
31233
|
+
moduleScopeNamesCache = new WeakMap;
|
|
31234
|
+
moduleScopeDeclarationNames(ir) {
|
|
31235
|
+
const cached = this.moduleScopeNamesCache.get(ir);
|
|
31236
|
+
if (cached)
|
|
31237
|
+
return cached;
|
|
31238
|
+
const componentScope = new Set;
|
|
31239
|
+
for (const sig of ir.metadata.signals) {
|
|
31240
|
+
if (sig.isModule)
|
|
31241
|
+
continue;
|
|
31242
|
+
componentScope.add(sig.getter);
|
|
31243
|
+
if (sig.setter)
|
|
31244
|
+
componentScope.add(sig.setter);
|
|
30959
31245
|
}
|
|
30960
|
-
|
|
30961
|
-
|
|
30962
|
-
|
|
30963
|
-
const indexParam = loop.index ? `, ${loop.index}` : "";
|
|
30964
|
-
const children = this.renderChildren(loop.children);
|
|
30965
|
-
const safeChildren = children.startsWith("{") ? `<>${children}</>` : children;
|
|
30966
|
-
const preamble = loop.preamble?.ssrText;
|
|
30967
|
-
if (preamble) {
|
|
30968
|
-
return `{${loop.array}.map((${loop.param}${indexParam}) => { ${preamble} return ${safeChildren} })}`;
|
|
31246
|
+
for (const memo of ir.metadata.memos) {
|
|
31247
|
+
if (!memo.isModule)
|
|
31248
|
+
componentScope.add(memo.name);
|
|
30969
31249
|
}
|
|
30970
|
-
|
|
30971
|
-
|
|
30972
|
-
|
|
30973
|
-
|
|
30974
|
-
|
|
30975
|
-
|
|
30976
|
-
|
|
30977
|
-
|
|
30978
|
-
|
|
30979
|
-
return `<${comp.name}${props}${scopeAttr} />`;
|
|
31250
|
+
for (const p of ir.metadata.propsParams)
|
|
31251
|
+
componentScope.add(p.name);
|
|
31252
|
+
if (ir.metadata.propsObjectName)
|
|
31253
|
+
componentScope.add(ir.metadata.propsObjectName);
|
|
31254
|
+
if (ir.metadata.restPropsName)
|
|
31255
|
+
componentScope.add(ir.metadata.restPropsName);
|
|
31256
|
+
for (const c of ir.metadata.localConstants) {
|
|
31257
|
+
if (!c.isModule)
|
|
31258
|
+
componentScope.add(c.name);
|
|
30980
31259
|
}
|
|
30981
|
-
|
|
30982
|
-
|
|
30983
|
-
|
|
30984
|
-
|
|
30985
|
-
|
|
30986
|
-
|
|
30987
|
-
const
|
|
30988
|
-
|
|
30989
|
-
|
|
30990
|
-
|
|
30991
|
-
|
|
30992
|
-
|
|
30993
|
-
|
|
30994
|
-
|
|
30995
|
-
parts.push(attrName);
|
|
30996
|
-
break;
|
|
30997
|
-
case "expression":
|
|
30998
|
-
parts.push(`${attrName}={${attr.value.expr}}`);
|
|
30999
|
-
break;
|
|
31000
|
-
case "template":
|
|
31001
|
-
parts.push(`${attrName}={${this.flattenTemplate(attr.value)}}`);
|
|
31002
|
-
break;
|
|
31003
|
-
case "literal":
|
|
31004
|
-
parts.push(`${attrName}="${attr.value.value}"`);
|
|
31005
|
-
break;
|
|
31006
|
-
case "boolean-shorthand":
|
|
31007
|
-
case "jsx-children":
|
|
31008
|
-
break;
|
|
31260
|
+
for (const f of ir.metadata.localFunctions) {
|
|
31261
|
+
if (!f.isModule)
|
|
31262
|
+
componentScope.add(f.name);
|
|
31263
|
+
}
|
|
31264
|
+
const exported = new Set;
|
|
31265
|
+
const candidates = new Map;
|
|
31266
|
+
for (const c of ir.metadata.localConstants) {
|
|
31267
|
+
if (!c.isModule)
|
|
31268
|
+
continue;
|
|
31269
|
+
if (c.isJsx || c.isJsxFunction)
|
|
31270
|
+
continue;
|
|
31271
|
+
if (c.isExported) {
|
|
31272
|
+
exported.add(c.name);
|
|
31273
|
+
continue;
|
|
31009
31274
|
}
|
|
31275
|
+
candidates.set(c.name, c.freeIdentifiers ?? extractFreeIdentifiersFromText(c.value ?? ""));
|
|
31010
31276
|
}
|
|
31011
|
-
for (const
|
|
31012
|
-
|
|
31013
|
-
|
|
31277
|
+
for (const f of ir.metadata.localFunctions) {
|
|
31278
|
+
if (!f.isModule)
|
|
31279
|
+
continue;
|
|
31280
|
+
if (f.isJsxFunction || f.isMultiReturnJsxHelper)
|
|
31281
|
+
continue;
|
|
31282
|
+
if (f.isExported) {
|
|
31283
|
+
exported.add(f.name);
|
|
31284
|
+
continue;
|
|
31285
|
+
}
|
|
31286
|
+
const params = f.typedParams !== undefined ? f.typedParams : f.params.map(formatParamWithType).join(", ");
|
|
31287
|
+
candidates.set(f.name, extractFreeIdentifiersFromText(`(${params}) => ${f.body}`));
|
|
31014
31288
|
}
|
|
31015
|
-
|
|
31016
|
-
|
|
31017
|
-
|
|
31018
|
-
|
|
31019
|
-
|
|
31020
|
-
|
|
31021
|
-
|
|
31022
|
-
|
|
31023
|
-
|
|
31024
|
-
|
|
31025
|
-
|
|
31026
|
-
|
|
31027
|
-
|
|
31028
|
-
|
|
31289
|
+
const referencesAny = (refs, names) => {
|
|
31290
|
+
for (const ref of refs) {
|
|
31291
|
+
if (names.has(ref))
|
|
31292
|
+
return true;
|
|
31293
|
+
}
|
|
31294
|
+
return false;
|
|
31295
|
+
};
|
|
31296
|
+
let changed = true;
|
|
31297
|
+
while (changed) {
|
|
31298
|
+
changed = false;
|
|
31299
|
+
for (const [name, refs] of candidates) {
|
|
31300
|
+
if (referencesAny(refs, componentScope)) {
|
|
31301
|
+
candidates.delete(name);
|
|
31302
|
+
componentScope.add(name);
|
|
31303
|
+
changed = true;
|
|
31029
31304
|
}
|
|
31030
|
-
case "spread":
|
|
31031
|
-
parts.push(`{...${prop.value.expr}}`);
|
|
31032
|
-
break;
|
|
31033
|
-
case "expression":
|
|
31034
|
-
parts.push(`${prop.name}={${prop.value.expr}}`);
|
|
31035
|
-
break;
|
|
31036
|
-
case "template":
|
|
31037
|
-
parts.push(`${prop.name}={${this.flattenTemplate(prop.value)}}`);
|
|
31038
|
-
break;
|
|
31039
|
-
case "boolean-shorthand":
|
|
31040
|
-
parts.push(prop.name);
|
|
31041
|
-
break;
|
|
31042
|
-
case "literal":
|
|
31043
|
-
parts.push(`${prop.name}="${prop.value.value}"`);
|
|
31044
|
-
break;
|
|
31045
|
-
case "boolean-attr":
|
|
31046
|
-
parts.push(prop.name);
|
|
31047
|
-
break;
|
|
31048
31305
|
}
|
|
31049
31306
|
}
|
|
31050
|
-
|
|
31051
|
-
|
|
31052
|
-
|
|
31053
|
-
var testAdapter = new TestAdapter;
|
|
31054
|
-
// src/adapters/parsed-expr-emitter.ts
|
|
31055
|
-
function isStringTypedOperand(expr, isStringName) {
|
|
31056
|
-
if (expr.kind === "literal" && expr.literalType === "string")
|
|
31057
|
-
return true;
|
|
31058
|
-
if (expr.kind === "template-literal")
|
|
31059
|
-
return true;
|
|
31060
|
-
if (expr.kind === "call" && expr.callee.kind === "identifier" && expr.args.length === 0) {
|
|
31061
|
-
return isStringName(expr.callee.name);
|
|
31062
|
-
}
|
|
31063
|
-
if (expr.kind === "member" && expr.object.kind === "identifier" && expr.object.name === "props") {
|
|
31064
|
-
return isStringName(expr.property, true);
|
|
31065
|
-
}
|
|
31066
|
-
if (expr.kind === "identifier")
|
|
31067
|
-
return isStringName(expr.name);
|
|
31068
|
-
if (expr.kind === "binary" && expr.op === "+") {
|
|
31069
|
-
return isStringTypedOperand(expr.left, isStringName) || isStringTypedOperand(expr.right, isStringName);
|
|
31307
|
+
const result = new Set([...exported, ...candidates.keys()]);
|
|
31308
|
+
this.moduleScopeNamesCache.set(ir, result);
|
|
31309
|
+
return result;
|
|
31070
31310
|
}
|
|
31071
|
-
|
|
31072
|
-
}
|
|
31073
|
-
|
|
31074
|
-
|
|
31075
|
-
|
|
31076
|
-
|
|
31077
|
-
if (!expr)
|
|
31078
|
-
return false;
|
|
31079
|
-
if (expr.kind === "unary")
|
|
31080
|
-
return expr.op === "-";
|
|
31081
|
-
if (expr.kind !== "binary")
|
|
31082
|
-
return false;
|
|
31083
|
-
if (expr.op === "+")
|
|
31084
|
-
return !isStringConcatBinary(expr.op, expr.left, expr.right, isStringName);
|
|
31085
|
-
return expr.op === "-" || expr.op === "*" || expr.op === "/" || expr.op === "%";
|
|
31086
|
-
}
|
|
31087
|
-
function arithmeticHelper(op) {
|
|
31088
|
-
if (op === "%")
|
|
31089
|
-
return "mod";
|
|
31090
|
-
if (op === "/")
|
|
31091
|
-
return "div";
|
|
31092
|
-
return null;
|
|
31093
|
-
}
|
|
31094
|
-
function groupBinaryOperand(operand, emitted) {
|
|
31095
|
-
return operand.kind === "binary" || operand.kind === "logical" || operand.kind === "conditional" ? `(${emitted})` : emitted;
|
|
31096
|
-
}
|
|
31097
|
-
function groupUnaryOperand(operand, emitted) {
|
|
31098
|
-
return operand.kind === "unary" ? `(${emitted})` : groupBinaryOperand(operand, emitted);
|
|
31099
|
-
}
|
|
31100
|
-
function groupObjectLiteralSegments(properties, literalOf, emit) {
|
|
31101
|
-
const segments = [];
|
|
31102
|
-
let run = [];
|
|
31103
|
-
const flushRun = () => {
|
|
31104
|
-
if (run.length > 0) {
|
|
31105
|
-
segments.push(literalOf(run));
|
|
31106
|
-
run = [];
|
|
31107
|
-
}
|
|
31108
|
-
};
|
|
31109
|
-
for (const p of properties) {
|
|
31110
|
-
if (p.kind === "spread") {
|
|
31111
|
-
flushRun();
|
|
31112
|
-
segments.push(emit(p.expr));
|
|
31113
|
-
} else {
|
|
31114
|
-
run.push(p);
|
|
31311
|
+
generateModuleScopeDeclarations(ir) {
|
|
31312
|
+
const { preserveTypes } = this.jsxConfig;
|
|
31313
|
+
const moduleNames = this.moduleScopeDeclarationNames(ir);
|
|
31314
|
+
const entries = [];
|
|
31315
|
+
for (const t of ir.metadata.typeDefinitions) {
|
|
31316
|
+
entries.push({ line: t.loc.start.line, text: t.definition });
|
|
31115
31317
|
}
|
|
31116
|
-
|
|
31117
|
-
|
|
31118
|
-
|
|
31119
|
-
|
|
31120
|
-
|
|
31121
|
-
|
|
31122
|
-
|
|
31123
|
-
|
|
31124
|
-
|
|
31125
|
-
return null;
|
|
31126
|
-
return callee.object;
|
|
31127
|
-
}
|
|
31128
|
-
function emitParsedExpr(expr, emitter) {
|
|
31129
|
-
const emit = (child) => emitParsedExpr(child, emitter);
|
|
31130
|
-
switch (expr.kind) {
|
|
31131
|
-
case "identifier":
|
|
31132
|
-
return emitter.identifier(expr.name);
|
|
31133
|
-
case "literal":
|
|
31134
|
-
return emitter.literal(expr.value, expr.literalType);
|
|
31135
|
-
case "call": {
|
|
31136
|
-
if (emitter.lowering) {
|
|
31137
|
-
for (const matcher of emitter.lowering.matchers) {
|
|
31138
|
-
const node = matcher(expr.callee, expr.args);
|
|
31139
|
-
if (!node)
|
|
31140
|
-
continue;
|
|
31141
|
-
const rendered = emitter.lowering.render(node, emit);
|
|
31142
|
-
if (rendered !== null)
|
|
31143
|
-
return rendered;
|
|
31144
|
-
break;
|
|
31145
|
-
}
|
|
31146
|
-
}
|
|
31147
|
-
const toStringReceiver = asToStringCall(expr);
|
|
31148
|
-
if (toStringReceiver) {
|
|
31149
|
-
return emitter.call({ kind: "identifier", name: "String" }, [toStringReceiver], emit);
|
|
31318
|
+
for (const c of ir.metadata.localConstants) {
|
|
31319
|
+
if (!c.isModule || !moduleNames.has(c.name))
|
|
31320
|
+
continue;
|
|
31321
|
+
const keyword = c.declarationKind ?? "const";
|
|
31322
|
+
const exportKw = c.isExported ? "export " : "";
|
|
31323
|
+
if (!c.value) {
|
|
31324
|
+
const typeAnnotation = preserveTypes && (c.typeAnnotation ?? c.type) ? `: ${c.typeAnnotation ?? c.type?.raw}` : "";
|
|
31325
|
+
entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${typeAnnotation}` });
|
|
31326
|
+
continue;
|
|
31150
31327
|
}
|
|
31151
|
-
|
|
31152
|
-
|
|
31153
|
-
|
|
31154
|
-
|
|
31328
|
+
if (c.systemConstructKind === "weakMap")
|
|
31329
|
+
continue;
|
|
31330
|
+
if (c.isExported && c.systemConstructKind === "createContext")
|
|
31331
|
+
continue;
|
|
31332
|
+
const value = preserveTypes ? c.typedValue ?? c.value : c.value;
|
|
31333
|
+
const letTypeAnnotation = preserveTypes && keyword === "let" && c.typeAnnotation ? `: ${c.typeAnnotation}` : "";
|
|
31334
|
+
entries.push({ line: c.loc.start.line, text: `${exportKw}${keyword} ${c.name}${letTypeAnnotation} = ${value}` });
|
|
31335
|
+
}
|
|
31336
|
+
for (const f of ir.metadata.localFunctions) {
|
|
31337
|
+
if (!f.isModule || !moduleNames.has(f.name))
|
|
31338
|
+
continue;
|
|
31339
|
+
const params = preserveTypes && f.typedParams !== undefined ? f.typedParams : f.params.map(formatParamWithType).join(", ");
|
|
31340
|
+
const returnAnnotation = preserveTypes && f.typedReturnType ? `: ${f.typedReturnType}` : "";
|
|
31341
|
+
const body = preserveTypes ? f.typedBody ?? f.body : f.body;
|
|
31342
|
+
const asyncKw = f.isAsync ? "async " : "";
|
|
31343
|
+
const exportKw = f.isExported ? "export " : "";
|
|
31344
|
+
entries.push({
|
|
31345
|
+
line: f.loc.start.line,
|
|
31346
|
+
text: `${exportKw}${asyncKw}function ${f.name}(${params})${returnAnnotation} ${body}`
|
|
31347
|
+
});
|
|
31155
31348
|
}
|
|
31156
|
-
|
|
31157
|
-
|
|
31158
|
-
|
|
31159
|
-
|
|
31160
|
-
|
|
31161
|
-
|
|
31162
|
-
|
|
31163
|
-
|
|
31164
|
-
case "logical":
|
|
31165
|
-
return emitter.logical(expr.op, expr.left, expr.right, emit);
|
|
31166
|
-
case "conditional":
|
|
31167
|
-
return emitter.conditional(expr.test, expr.consequent, expr.alternate, emit);
|
|
31168
|
-
case "template-literal":
|
|
31169
|
-
return emitter.templateLiteral(expr.parts, emit);
|
|
31170
|
-
case "arrow":
|
|
31171
|
-
return emitter.arrow(expr.params, expr.body, emit);
|
|
31172
|
-
case "regex":
|
|
31173
|
-
return emitter.regex(expr.raw);
|
|
31174
|
-
case "array-literal":
|
|
31175
|
-
return emitter.arrayLiteral(expr.elements, emit);
|
|
31176
|
-
case "object-literal":
|
|
31177
|
-
return emitter.objectLiteral(expr.properties, expr.raw, emit);
|
|
31178
|
-
case "array-method":
|
|
31179
|
-
if (expr.method === "flat") {
|
|
31180
|
-
return emitter.flatMethod(expr.object, expr.depthExpr ? { expr: expr.depthExpr } : expr.flatDepth, emit);
|
|
31349
|
+
entries.sort((a, b) => a.line - b.line);
|
|
31350
|
+
return entries.map((e) => e.text).join(`
|
|
31351
|
+
`);
|
|
31352
|
+
}
|
|
31353
|
+
renderNodeRaw(node) {
|
|
31354
|
+
if (node.type === "expression") {
|
|
31355
|
+
if (node.expr === "null" || node.expr === "undefined") {
|
|
31356
|
+
return "null";
|
|
31181
31357
|
}
|
|
31182
|
-
return
|
|
31183
|
-
case "unsupported":
|
|
31184
|
-
return emitter.unsupported(expr.raw, expr.reason);
|
|
31185
|
-
default: {
|
|
31186
|
-
const _exhaustive = expr;
|
|
31187
|
-
throw new Error(`emitParsedExpr: unhandled ParsedExpr kind ${_exhaustive.kind}`);
|
|
31358
|
+
return node.expr;
|
|
31188
31359
|
}
|
|
31360
|
+
return this.renderNode(node);
|
|
31189
31361
|
}
|
|
31190
|
-
|
|
31191
|
-
|
|
31192
|
-
function staticString(value) {
|
|
31193
|
-
if (value.kind === "literal" && value.literalType === "string" && typeof value.value === "string")
|
|
31194
|
-
return value.value;
|
|
31195
|
-
if (value.kind === "template-literal" && value.parts.every((p) => p.type === "string")) {
|
|
31196
|
-
return value.parts.map((p) => p.type === "string" ? p.value : "").join("");
|
|
31362
|
+
renderTemplatePartsAsJs(parts) {
|
|
31363
|
+
return templatePartsToJsExpr(parts, { typed: this.jsxConfig.preserveTypes });
|
|
31197
31364
|
}
|
|
31198
|
-
|
|
31199
|
-
|
|
31200
|
-
|
|
31201
|
-
const parsed = value.parsed;
|
|
31202
|
-
if (parsed?.kind !== "object-literal" || parsed.properties.length === 0)
|
|
31203
|
-
return null;
|
|
31204
|
-
const entries = [];
|
|
31205
|
-
for (const prop of parsed.properties) {
|
|
31206
|
-
if (prop.kind !== "prop" || prop.keyKind === "numeric")
|
|
31207
|
-
return null;
|
|
31208
|
-
const cssKey = cssKebabCase(prop.key);
|
|
31209
|
-
const literal = staticString(prop.value);
|
|
31210
|
-
if (literal !== null) {
|
|
31211
|
-
entries.push({ cssKey, kind: "literal", value: literal });
|
|
31212
|
-
} else if (isSupported(prop.value).supported) {
|
|
31213
|
-
entries.push({ cssKey, kind: "expr", expr: stringifyParsedExpr(prop.value), parsed: prop.value });
|
|
31214
|
-
} else {
|
|
31215
|
-
return null;
|
|
31365
|
+
expressionValueToJs(value) {
|
|
31366
|
+
if (this.jsxConfig.preserveTypes && value.typed && value.expr === value.typed.forExpr) {
|
|
31367
|
+
return value.typed.tsx;
|
|
31216
31368
|
}
|
|
31369
|
+
if (this.jsxConfig.preserveTypes && value.parts && value.expr === templatePartsToJsExpr(value.parts)) {
|
|
31370
|
+
return this.renderTemplatePartsAsJs(value.parts);
|
|
31371
|
+
}
|
|
31372
|
+
return value.expr;
|
|
31373
|
+
}
|
|
31374
|
+
renderScopeMarker(instanceIdExpr) {
|
|
31375
|
+
return `${BF_SCOPE4}={${instanceIdExpr}}`;
|
|
31376
|
+
}
|
|
31377
|
+
renderSlotMarker(slotId) {
|
|
31378
|
+
return `${BF_SLOT}="${slotId}"`;
|
|
31379
|
+
}
|
|
31380
|
+
renderCondMarker(condId) {
|
|
31381
|
+
return `${BF_COND}="${condId}"`;
|
|
31217
31382
|
}
|
|
31218
|
-
return entries;
|
|
31219
|
-
}
|
|
31220
|
-
// src/adapters/filter-capture-collisions.ts
|
|
31221
|
-
function filterCaptureCollisions(loop) {
|
|
31222
|
-
const filter = loop.filterPredicate;
|
|
31223
|
-
if (!filter?.predicate)
|
|
31224
|
-
return [];
|
|
31225
|
-
const free = freeIdentifiers(filter.predicate);
|
|
31226
|
-
if (!free)
|
|
31227
|
-
return [];
|
|
31228
|
-
free.delete(filter.param);
|
|
31229
|
-
const rowBound = new Set(loop.paramBindings && loop.paramBindings.length > 0 ? loop.paramBindings.map((b) => b.name) : [loop.param]);
|
|
31230
|
-
if (loop.index)
|
|
31231
|
-
rowBound.add(loop.index);
|
|
31232
|
-
return [...free].filter((name) => rowBound.has(name)).sort();
|
|
31233
31383
|
}
|
|
31234
|
-
|
|
31235
|
-
|
|
31236
|
-
|
|
31237
|
-
|
|
31238
|
-
"
|
|
31239
|
-
"
|
|
31240
|
-
"==",
|
|
31241
|
-
"===",
|
|
31242
|
-
"!=",
|
|
31243
|
-
"!=="
|
|
31384
|
+
|
|
31385
|
+
// src/adapters/template-imports.ts
|
|
31386
|
+
import ts33 from "typescript";
|
|
31387
|
+
var CLIENT_PACKAGE_SOURCES = new Set([
|
|
31388
|
+
"@barefootjs/client",
|
|
31389
|
+
"@barefootjs/client/runtime"
|
|
31244
31390
|
]);
|
|
31245
|
-
function
|
|
31246
|
-
|
|
31247
|
-
|
|
31248
|
-
return
|
|
31249
|
-
|
|
31250
|
-
|
|
31251
|
-
|
|
31252
|
-
|
|
31253
|
-
|
|
31254
|
-
|
|
31255
|
-
|
|
31256
|
-
|
|
31257
|
-
|
|
31258
|
-
|
|
31259
|
-
|
|
31260
|
-
|
|
31261
|
-
|
|
31262
|
-
|
|
31263
|
-
|
|
31264
|
-
|
|
31391
|
+
function rewriteImportsForTemplate(imports, shimSource, rewriteRelative) {
|
|
31392
|
+
const remap = (imp) => {
|
|
31393
|
+
if (!rewriteRelative || !imp.source.startsWith("."))
|
|
31394
|
+
return imp;
|
|
31395
|
+
const next = rewriteRelative(imp.source);
|
|
31396
|
+
return next === imp.source ? imp : { ...imp, source: next };
|
|
31397
|
+
};
|
|
31398
|
+
if (!shimSource) {
|
|
31399
|
+
return imports.filter((imp) => !CLIENT_PACKAGE_SOURCES.has(imp.source)).map(remap);
|
|
31400
|
+
}
|
|
31401
|
+
const merged = new Map;
|
|
31402
|
+
const result = [];
|
|
31403
|
+
for (const imp of imports) {
|
|
31404
|
+
if (!CLIENT_PACKAGE_SOURCES.has(imp.source)) {
|
|
31405
|
+
result.push(remap(imp));
|
|
31406
|
+
continue;
|
|
31407
|
+
}
|
|
31408
|
+
const existing = merged.get(shimSource);
|
|
31409
|
+
if (existing) {
|
|
31410
|
+
const seen = new Set(existing.specifiers.map(specKey));
|
|
31411
|
+
for (const spec of imp.specifiers) {
|
|
31412
|
+
if (!seen.has(specKey(spec))) {
|
|
31413
|
+
existing.specifiers.push(spec);
|
|
31414
|
+
seen.add(specKey(spec));
|
|
31415
|
+
}
|
|
31416
|
+
}
|
|
31417
|
+
existing.isTypeOnly = existing.isTypeOnly && imp.isTypeOnly;
|
|
31418
|
+
} else {
|
|
31419
|
+
const rewritten = {
|
|
31420
|
+
...imp,
|
|
31421
|
+
source: shimSource,
|
|
31422
|
+
specifiers: imp.specifiers.map((s) => ({ ...s }))
|
|
31423
|
+
};
|
|
31424
|
+
merged.set(shimSource, rewritten);
|
|
31425
|
+
result.push(rewritten);
|
|
31426
|
+
}
|
|
31265
31427
|
}
|
|
31428
|
+
return result;
|
|
31266
31429
|
}
|
|
31267
|
-
function
|
|
31268
|
-
|
|
31269
|
-
return node;
|
|
31270
|
-
return {
|
|
31271
|
-
...node,
|
|
31272
|
-
consequent: stringifyBooleanBranch(node.consequent),
|
|
31273
|
-
alternate: stringifyBooleanBranch(node.alternate)
|
|
31274
|
-
};
|
|
31430
|
+
function specKey(s) {
|
|
31431
|
+
return `${s.isDefault ? "d" : ""}${s.isNamespace ? "n" : ""}:${s.name}:${s.alias ?? ""}`;
|
|
31275
31432
|
}
|
|
31276
|
-
function
|
|
31277
|
-
if (!
|
|
31278
|
-
return
|
|
31279
|
-
|
|
31280
|
-
|
|
31281
|
-
|
|
31282
|
-
|
|
31283
|
-
|
|
31284
|
-
|
|
31285
|
-
|
|
31286
|
-
|
|
31433
|
+
function rewriteDynamicImportsInSource(sourceText, rewriteRelative) {
|
|
31434
|
+
if (!sourceText.includes("import"))
|
|
31435
|
+
return sourceText;
|
|
31436
|
+
const sf = ts33.createSourceFile("bf-template-fragment.tsx", sourceText, ts33.ScriptTarget.Latest, false, ts33.ScriptKind.TSX);
|
|
31437
|
+
const edits = [];
|
|
31438
|
+
const visit3 = (node) => {
|
|
31439
|
+
if (ts33.isCallExpression(node) && node.expression.kind === ts33.SyntaxKind.ImportKeyword && node.arguments.length > 0 && ts33.isStringLiteralLike(node.arguments[0])) {
|
|
31440
|
+
collect(node.arguments[0]);
|
|
31441
|
+
}
|
|
31442
|
+
if (ts33.isImportTypeNode(node) && ts33.isLiteralTypeNode(node.argument)) {
|
|
31443
|
+
const literal = node.argument.literal;
|
|
31444
|
+
if (ts33.isStringLiteralLike(literal))
|
|
31445
|
+
collect(literal);
|
|
31446
|
+
}
|
|
31447
|
+
ts33.forEachChild(node, visit3);
|
|
31287
31448
|
};
|
|
31288
|
-
|
|
31289
|
-
|
|
31290
|
-
|
|
31291
|
-
|
|
31292
|
-
const
|
|
31293
|
-
|
|
31449
|
+
const collect = (literal) => {
|
|
31450
|
+
const specifier = literal.text;
|
|
31451
|
+
if (!specifier.startsWith("."))
|
|
31452
|
+
return;
|
|
31453
|
+
const next = rewriteRelative(specifier);
|
|
31454
|
+
if (next === specifier)
|
|
31455
|
+
return;
|
|
31456
|
+
edits.push({
|
|
31457
|
+
start: literal.getStart(sf),
|
|
31458
|
+
end: literal.getEnd(),
|
|
31459
|
+
text: `'${next}'`
|
|
31460
|
+
});
|
|
31294
31461
|
};
|
|
31295
|
-
|
|
31296
|
-
|
|
31297
|
-
|
|
31298
|
-
|
|
31299
|
-
|
|
31462
|
+
ts33.forEachChild(sf, visit3);
|
|
31463
|
+
if (edits.length === 0)
|
|
31464
|
+
return sourceText;
|
|
31465
|
+
let out = sourceText;
|
|
31466
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) {
|
|
31467
|
+
out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
|
|
31468
|
+
}
|
|
31469
|
+
return out;
|
|
31470
|
+
}
|
|
31471
|
+
|
|
31472
|
+
// src/adapters/test-adapter.ts
|
|
31473
|
+
class TestAdapter extends JsxAdapter {
|
|
31474
|
+
name = "test";
|
|
31475
|
+
extension = ".test.tsx";
|
|
31476
|
+
jsxConfig = { preserveTypes: false };
|
|
31477
|
+
generate(ir) {
|
|
31478
|
+
this.componentName = ir.metadata.componentName;
|
|
31479
|
+
const imports = this.generateImports(ir);
|
|
31480
|
+
const moduleConstants = this.generateModuleScopeDeclarations(ir);
|
|
31481
|
+
const types = this.generateTypes(ir);
|
|
31482
|
+
const component = this.generateComponent(ir);
|
|
31483
|
+
const defaultExport = ir.metadata.hasDefaultExport ? `
|
|
31484
|
+
export default ${this.componentName}` : "";
|
|
31485
|
+
const sections = {
|
|
31486
|
+
imports,
|
|
31487
|
+
types: types || "",
|
|
31488
|
+
component,
|
|
31489
|
+
defaultExport,
|
|
31490
|
+
moduleConstants,
|
|
31491
|
+
moduleConstantsIncludeExports: true
|
|
31492
|
+
};
|
|
31493
|
+
const template = [imports, moduleConstants, types, component].filter(Boolean).join(`
|
|
31494
|
+
|
|
31495
|
+
`) + defaultExport;
|
|
31496
|
+
return {
|
|
31497
|
+
template,
|
|
31498
|
+
sections,
|
|
31499
|
+
types: types || undefined,
|
|
31500
|
+
extension: this.extension
|
|
31501
|
+
};
|
|
31300
31502
|
}
|
|
31301
|
-
|
|
31302
|
-
|
|
31303
|
-
|
|
31503
|
+
generateImports(ir) {
|
|
31504
|
+
const lines = [];
|
|
31505
|
+
const templateImports = rewriteImportsForTemplate(ir.metadata.templateImports, undefined);
|
|
31506
|
+
for (const imp of templateImports) {
|
|
31507
|
+
if (imp.specifiers.length === 0) {
|
|
31508
|
+
if (!imp.isTypeOnly) {
|
|
31509
|
+
lines.push(`import '${imp.source}'`);
|
|
31510
|
+
}
|
|
31511
|
+
continue;
|
|
31512
|
+
}
|
|
31513
|
+
if (imp.isTypeOnly) {
|
|
31514
|
+
lines.push(`import type ${this.formatImportSpecifiers(imp.specifiers)} from '${imp.source}'`);
|
|
31515
|
+
} else {
|
|
31516
|
+
lines.push(`import ${this.formatImportSpecifiers(imp.specifiers)} from '${imp.source}'`);
|
|
31517
|
+
}
|
|
31518
|
+
}
|
|
31519
|
+
return lines.join(`
|
|
31520
|
+
`);
|
|
31304
31521
|
}
|
|
31305
|
-
|
|
31306
|
-
|
|
31307
|
-
|
|
31308
|
-
|
|
31309
|
-
|
|
31310
|
-
|
|
31311
|
-
|
|
31312
|
-
|
|
31313
|
-
|
|
31314
|
-
|
|
31522
|
+
generateTypes(ir) {
|
|
31523
|
+
const lines = [];
|
|
31524
|
+
const propsTypeName = ir.metadata.propsType?.raw;
|
|
31525
|
+
if (propsTypeName && !ir.metadata.propsObjectName) {
|
|
31526
|
+
lines.push("");
|
|
31527
|
+
lines.push(`type ${this.componentName}PropsWithHydration = ${propsTypeName} & {`);
|
|
31528
|
+
lines.push(" __instanceId?: string");
|
|
31529
|
+
lines.push(" __bfScope?: string");
|
|
31530
|
+
lines.push("}");
|
|
31531
|
+
}
|
|
31532
|
+
return lines.length > 0 ? lines.join(`
|
|
31533
|
+
`) : null;
|
|
31315
31534
|
}
|
|
31316
|
-
|
|
31317
|
-
|
|
31318
|
-
|
|
31319
|
-
|
|
31320
|
-
|
|
31321
|
-
|
|
31322
|
-
|
|
31535
|
+
generateComponent(ir) {
|
|
31536
|
+
const name = ir.metadata.componentName;
|
|
31537
|
+
const propsTypeName = ir.metadata.propsType?.raw;
|
|
31538
|
+
const hasClientInteractivity2 = ir.metadata.signals.length > 0 || ir.metadata.memos.length > 0;
|
|
31539
|
+
const typeAnnotation = propsTypeName ? `: ${name}PropsWithHydration` : ": { __instanceId?: string; __bfScope?: string }";
|
|
31540
|
+
const jsxBody = this.renderNode(ir.root);
|
|
31541
|
+
const signalInits = this.generateSignalInitializers(ir, jsxBody);
|
|
31542
|
+
const scopeIdLine = hasClientInteractivity2 ? `(/_s\\d/.test(__bfScope || '') ? __bfScope : null) || __instanceId` : `__bfScope || __instanceId`;
|
|
31543
|
+
const bodyRefText = [jsxBody, signalInits, scopeIdLine].join(`
|
|
31544
|
+
`);
|
|
31545
|
+
const bfScopeAlias = /\b__bfScope\b/.test(bodyRefText) ? "__bfScope" : "__bfScope: _bfScope";
|
|
31546
|
+
const propsParams = ir.metadata.propsParams.map((p) => propsDestructureBinding(p)).join(", ");
|
|
31547
|
+
const restPropsName = ir.metadata.restPropsName;
|
|
31548
|
+
const hydrationProps = `__instanceId, ${bfScopeAlias}`;
|
|
31549
|
+
const parts = [];
|
|
31550
|
+
if (propsParams) {
|
|
31551
|
+
parts.push(propsParams);
|
|
31323
31552
|
}
|
|
31324
|
-
|
|
31325
|
-
|
|
31326
|
-
|
|
31553
|
+
parts.push(hydrationProps);
|
|
31554
|
+
if (restPropsName) {
|
|
31555
|
+
parts.push(`...${restPropsName}`);
|
|
31327
31556
|
}
|
|
31328
|
-
|
|
31329
|
-
|
|
31330
|
-
|
|
31331
|
-
|
|
31332
|
-
|
|
31333
|
-
|
|
31334
|
-
|
|
31557
|
+
const fullPropsDestructure = `{ ${parts.join(", ")} }`;
|
|
31558
|
+
const hasRequiredProps = ir.metadata.propsParams.some((p) => !p.optional && p.defaultValue === undefined && !p.isRest);
|
|
31559
|
+
const propsTypeExpr = typeAnnotation.replace(/^:\s*/, "");
|
|
31560
|
+
const noArgDefault = hasRequiredProps ? "" : ` = {} as ${propsTypeExpr}`;
|
|
31561
|
+
const lines = [];
|
|
31562
|
+
const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
|
|
31563
|
+
const typeParameters = ir.metadata.typeParameters ?? "";
|
|
31564
|
+
lines.push(`${exportPrefix}function ${name}${typeParameters}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
|
|
31565
|
+
if (hasClientInteractivity2) {
|
|
31566
|
+
lines.push(` const __scopeId = (/_s\\d/.test(__bfScope || '') ? __bfScope : null) || __instanceId || \`${name}_\${Math.random().toString(36).slice(2, 8)}\``);
|
|
31567
|
+
} else {
|
|
31568
|
+
lines.push(` const __scopeId = __bfScope || __instanceId || \`${name}_\${Math.random().toString(36).slice(2, 8)}\``);
|
|
31569
|
+
}
|
|
31570
|
+
if (signalInits) {
|
|
31571
|
+
lines.push(signalInits);
|
|
31572
|
+
}
|
|
31573
|
+
lines.push("");
|
|
31574
|
+
lines.push(` return (`);
|
|
31575
|
+
lines.push(` ${jsxBody}`);
|
|
31576
|
+
lines.push(` )`);
|
|
31577
|
+
lines.push(`}`);
|
|
31578
|
+
return lines.join(`
|
|
31579
|
+
`);
|
|
31335
31580
|
}
|
|
31336
|
-
|
|
31337
|
-
|
|
31338
|
-
|
|
31339
|
-
|
|
31340
|
-
|
|
31341
|
-
|
|
31342
|
-
|
|
31343
|
-
|
|
31344
|
-
|
|
31345
|
-
|
|
31346
|
-
|
|
31347
|
-
|
|
31348
|
-
|
|
31349
|
-
|
|
31350
|
-
|
|
31351
|
-
|
|
31352
|
-
|
|
31353
|
-
|
|
31354
|
-
|
|
31355
|
-
|
|
31356
|
-
|
|
31357
|
-
|
|
31358
|
-
|
|
31359
|
-
|
|
31360
|
-
|
|
31361
|
-
|
|
31362
|
-
|
|
31363
|
-
|
|
31364
|
-
|
|
31365
|
-
}
|
|
31366
|
-
|
|
31367
|
-
|
|
31368
|
-
|
|
31369
|
-
|
|
31370
|
-
|
|
31371
|
-
if (!initialValue)
|
|
31372
|
-
return false;
|
|
31373
|
-
const v = initialValue.trim();
|
|
31374
|
-
return v.startsWith("'") && v.endsWith("'") || v.startsWith('"') && v.endsWith('"');
|
|
31375
|
-
}
|
|
31376
|
-
function isLiteralIndex(index) {
|
|
31377
|
-
return index.kind === "literal" && (index.literalType === "number" || index.literalType === "string");
|
|
31378
|
-
}
|
|
31379
|
-
// src/adapters/array-method.ts
|
|
31380
|
-
var required = { kind: "required" };
|
|
31381
|
-
var optional = { kind: "optional" };
|
|
31382
|
-
var zero = { kind: "default", value: { kind: "number", value: 0 } };
|
|
31383
|
-
var ARRAY_METHOD_CATALOGUE = {
|
|
31384
|
-
join: { helper: "join", params: [{ kind: "default", value: { kind: "string", value: "," } }] },
|
|
31385
|
-
includes: { helper: "includes", params: [required] },
|
|
31386
|
-
indexOf: { helper: "index_of", params: [required] },
|
|
31387
|
-
lastIndexOf: { helper: "last_index_of", params: [required] },
|
|
31388
|
-
at: { helper: "at", params: [zero] },
|
|
31389
|
-
concat: { helper: "concat", params: [required], receiverWhenNoArgs: true },
|
|
31390
|
-
slice: { helper: "slice", params: [zero, { kind: "default", value: { kind: "undefined" } }] },
|
|
31391
|
-
reverse: { helper: "reverse", params: [] },
|
|
31392
|
-
toReversed: { helper: "reverse", params: [] },
|
|
31393
|
-
toLowerCase: { helper: "lc", params: [] },
|
|
31394
|
-
toUpperCase: { helper: "uc", params: [] },
|
|
31395
|
-
trim: { helper: "trim", params: [] },
|
|
31396
|
-
trimStart: { helper: "trim_start", params: [] },
|
|
31397
|
-
trimEnd: { helper: "trim_end", params: [] },
|
|
31398
|
-
toFixed: { helper: "to_fixed", params: [zero] },
|
|
31399
|
-
split: { helper: "split", params: [optional, optional] },
|
|
31400
|
-
startsWith: { helper: "starts_with", params: [required, optional] },
|
|
31401
|
-
endsWith: { helper: "ends_with", params: [required, optional] },
|
|
31402
|
-
replace: { helper: "replace", params: [required, required] },
|
|
31403
|
-
replaceAll: { helper: "replace_all", params: [required, required] },
|
|
31404
|
-
repeat: { helper: "repeat", params: [zero] },
|
|
31405
|
-
padStart: { helper: "pad_start", params: [zero, optional] },
|
|
31406
|
-
padEnd: { helper: "pad_end", params: [zero, optional] }
|
|
31407
|
-
};
|
|
31408
|
-
function lowerArrayMethod(method, object, args) {
|
|
31409
|
-
const entry = ARRAY_METHOD_CATALOGUE[method];
|
|
31410
|
-
if (entry.receiverWhenNoArgs && args.length === 0)
|
|
31411
|
-
return { kind: "receiver", object };
|
|
31412
|
-
const out = [];
|
|
31413
|
-
for (const [i, param] of entry.params.entries()) {
|
|
31414
|
-
const arg = args[i];
|
|
31415
|
-
if (arg) {
|
|
31416
|
-
out.push({ kind: "expr", expr: arg });
|
|
31417
|
-
} else if (param.kind === "default") {
|
|
31418
|
-
out.push({ kind: "default", value: param.value });
|
|
31419
|
-
} else if (param.kind === "optional") {
|
|
31420
|
-
break;
|
|
31581
|
+
renderNode(node) {
|
|
31582
|
+
switch (node.type) {
|
|
31583
|
+
case "element":
|
|
31584
|
+
return this.renderElement(node);
|
|
31585
|
+
case "text":
|
|
31586
|
+
return node.value;
|
|
31587
|
+
case "expression":
|
|
31588
|
+
return this.renderExpression(node);
|
|
31589
|
+
case "conditional":
|
|
31590
|
+
return this.renderConditional(node);
|
|
31591
|
+
case "loop":
|
|
31592
|
+
return this.renderLoop(node);
|
|
31593
|
+
case "component":
|
|
31594
|
+
return this.renderComponent(node);
|
|
31595
|
+
case "fragment":
|
|
31596
|
+
return this.renderFragment(node);
|
|
31597
|
+
case "slot":
|
|
31598
|
+
return "{children}";
|
|
31599
|
+
default:
|
|
31600
|
+
return "";
|
|
31601
|
+
}
|
|
31602
|
+
}
|
|
31603
|
+
renderElement(element) {
|
|
31604
|
+
const tag = element.tag;
|
|
31605
|
+
const attrs = this.renderAttributes(element);
|
|
31606
|
+
const children = this.renderChildren(element.children);
|
|
31607
|
+
let hydrationAttrs = "";
|
|
31608
|
+
if (element.needsScope) {
|
|
31609
|
+
hydrationAttrs += " bf-s={__scopeId}";
|
|
31610
|
+
}
|
|
31611
|
+
if (element.slotId) {
|
|
31612
|
+
hydrationAttrs += ` bf="${element.slotId}"`;
|
|
31613
|
+
}
|
|
31614
|
+
if (children) {
|
|
31615
|
+
return `<${tag}${attrs}${hydrationAttrs}>${children}</${tag}>`;
|
|
31421
31616
|
} else {
|
|
31422
|
-
|
|
31617
|
+
return `<${tag}${attrs}${hydrationAttrs} />`;
|
|
31618
|
+
}
|
|
31619
|
+
}
|
|
31620
|
+
renderExpression(expr) {
|
|
31621
|
+
if (expr.expr === "null" || expr.expr === "undefined") {
|
|
31622
|
+
return "null";
|
|
31623
|
+
}
|
|
31624
|
+
if (expr.reactive && expr.slotId) {
|
|
31625
|
+
return `{bfText("${expr.slotId}")}{${expr.expr}}{bfTextEnd()}`;
|
|
31423
31626
|
}
|
|
31627
|
+
return `{${expr.expr}}`;
|
|
31424
31628
|
}
|
|
31425
|
-
|
|
31426
|
-
|
|
31427
|
-
|
|
31428
|
-
|
|
31429
|
-
|
|
31430
|
-
|
|
31431
|
-
|
|
31432
|
-
operands.push(arg.kind === "expr" ? emit(arg.expr) : defaultLiteral(arg.value, spelling));
|
|
31629
|
+
renderConditional(cond) {
|
|
31630
|
+
const whenTrue = this.renderNodeRaw(cond.whenTrue);
|
|
31631
|
+
let whenFalse = this.renderNodeRaw(cond.whenFalse);
|
|
31632
|
+
if (!whenFalse || whenFalse === "" || whenFalse === "null") {
|
|
31633
|
+
whenFalse = "null";
|
|
31634
|
+
}
|
|
31635
|
+
return `{${cond.condition} ? ${whenTrue} : ${whenFalse}}`;
|
|
31433
31636
|
}
|
|
31434
|
-
|
|
31435
|
-
}
|
|
31436
|
-
|
|
31437
|
-
|
|
31438
|
-
|
|
31439
|
-
|
|
31440
|
-
|
|
31441
|
-
|
|
31442
|
-
|
|
31443
|
-
return spelling.undefinedLiteral;
|
|
31637
|
+
renderLoop(loop) {
|
|
31638
|
+
const indexParam = loop.index ? `, ${loop.index}` : "";
|
|
31639
|
+
const children = this.renderChildren(loop.children);
|
|
31640
|
+
const safeChildren = children.startsWith("{") ? `<>${children}</>` : children;
|
|
31641
|
+
const preamble = loop.preamble?.ssrText;
|
|
31642
|
+
if (preamble) {
|
|
31643
|
+
return `{${loop.array}.map((${loop.param}${indexParam}) => { ${preamble} return ${safeChildren} })}`;
|
|
31644
|
+
}
|
|
31645
|
+
return `{${loop.array}.map((${loop.param}${indexParam}) => ${safeChildren})}`;
|
|
31444
31646
|
}
|
|
31445
|
-
|
|
31446
|
-
|
|
31447
|
-
|
|
31448
|
-
|
|
31449
|
-
|
|
31450
|
-
|
|
31451
|
-
}
|
|
31452
|
-
|
|
31453
|
-
|
|
31454
|
-
filter: { helper: "filter_eval" },
|
|
31455
|
-
every: { helper: "every_eval" },
|
|
31456
|
-
some: { helper: "some_eval" },
|
|
31457
|
-
find: { helper: "find_eval", forward: true },
|
|
31458
|
-
findLast: { helper: "find_eval", forward: false },
|
|
31459
|
-
findIndex: { helper: "find_index_eval", forward: true },
|
|
31460
|
-
findLastIndex: { helper: "find_index_eval", forward: false }
|
|
31461
|
-
};
|
|
31462
|
-
function isPredicateMethod(method) {
|
|
31463
|
-
return Object.hasOwn(PREDICATE_EVAL, method);
|
|
31464
|
-
}
|
|
31465
|
-
function lowerCallbackMethod(method, arrow, restArgs, options) {
|
|
31466
|
-
const { adapterName } = options;
|
|
31467
|
-
const { body, params } = arrow;
|
|
31468
|
-
if (isPredicateMethod(method))
|
|
31469
|
-
return lowerPredicate(method, arrow, options);
|
|
31470
|
-
if (method === "sort" || method === "toSorted")
|
|
31471
|
-
return lowerSortComparator(method, arrow, adapterName);
|
|
31472
|
-
if (method === "reduce" || method === "reduceRight") {
|
|
31473
|
-
const init = restArgs[0];
|
|
31474
|
-
const plan = init ? reduceEvalPlan(body, params, init, method === "reduceRight" ? "right" : "left") : null;
|
|
31475
|
-
return plan ?? {
|
|
31476
|
-
kind: "refuse",
|
|
31477
|
-
message: `'.${method}(...)' is outside the ${adapterName} adapter's evaluable surface (needs a literal initial value and an evaluable reducer body)`,
|
|
31478
|
-
suggestion: `Pre-compute the reduced value, or move this position to a '/* @client */' boundary.`
|
|
31479
|
-
};
|
|
31647
|
+
renderComponent(comp) {
|
|
31648
|
+
const props = this.renderComponentProps(comp);
|
|
31649
|
+
const children = this.renderChildren(comp.children);
|
|
31650
|
+
const scopeAttr = " __bfScope={__scopeId}";
|
|
31651
|
+
if (children) {
|
|
31652
|
+
return `<${comp.name}${props}${scopeAttr}>${children}</${comp.name}>`;
|
|
31653
|
+
} else {
|
|
31654
|
+
return `<${comp.name}${props}${scopeAttr} />`;
|
|
31655
|
+
}
|
|
31480
31656
|
}
|
|
31481
|
-
|
|
31482
|
-
const
|
|
31483
|
-
return
|
|
31484
|
-
kind: "refuse",
|
|
31485
|
-
message: `'.${method}(...)' projection is outside the ${adapterName} adapter's evaluable surface`,
|
|
31486
|
-
suggestion: `Pre-compute the projected array, or move this position to a '/* @client */' boundary.`
|
|
31487
|
-
};
|
|
31657
|
+
renderFragment(fragment) {
|
|
31658
|
+
const children = this.renderChildren(fragment.children);
|
|
31659
|
+
return `<>${children}</>`;
|
|
31488
31660
|
}
|
|
31489
|
-
|
|
31490
|
-
|
|
31491
|
-
|
|
31492
|
-
|
|
31493
|
-
|
|
31494
|
-
|
|
31495
|
-
|
|
31496
|
-
|
|
31497
|
-
|
|
31498
|
-
|
|
31499
|
-
|
|
31500
|
-
|
|
31501
|
-
|
|
31502
|
-
|
|
31503
|
-
|
|
31504
|
-
|
|
31505
|
-
|
|
31506
|
-
|
|
31507
|
-
|
|
31661
|
+
renderAttributes(element) {
|
|
31662
|
+
const parts = [];
|
|
31663
|
+
for (const attr of element.attrs) {
|
|
31664
|
+
const attrName = attr.name === "class" ? "className" : attr.name;
|
|
31665
|
+
switch (attr.value.kind) {
|
|
31666
|
+
case "spread":
|
|
31667
|
+
parts.push(`{...${attr.value.expr}}`);
|
|
31668
|
+
break;
|
|
31669
|
+
case "boolean-attr":
|
|
31670
|
+
parts.push(attrName);
|
|
31671
|
+
break;
|
|
31672
|
+
case "expression":
|
|
31673
|
+
parts.push(`${attrName}={${attr.value.expr}}`);
|
|
31674
|
+
break;
|
|
31675
|
+
case "template":
|
|
31676
|
+
parts.push(`${attrName}={${this.flattenTemplate(attr.value)}}`);
|
|
31677
|
+
break;
|
|
31678
|
+
case "literal":
|
|
31679
|
+
parts.push(`${attrName}="${attr.value.value}"`);
|
|
31680
|
+
break;
|
|
31681
|
+
case "boolean-shorthand":
|
|
31682
|
+
case "jsx-children":
|
|
31683
|
+
break;
|
|
31684
|
+
}
|
|
31685
|
+
}
|
|
31686
|
+
for (const event of element.events) {
|
|
31687
|
+
const handlerName = event.originalAttr ?? `on${event.name.charAt(0).toUpperCase()}${event.name.slice(1)}`;
|
|
31688
|
+
parts.push(`${handlerName}={() => {}}`);
|
|
31689
|
+
}
|
|
31690
|
+
return parts.length > 0 ? " " + parts.join(" ") : "";
|
|
31508
31691
|
}
|
|
31509
|
-
|
|
31510
|
-
|
|
31511
|
-
|
|
31512
|
-
|
|
31513
|
-
|
|
31514
|
-
|
|
31515
|
-
|
|
31516
|
-
|
|
31517
|
-
|
|
31518
|
-
|
|
31519
|
-
|
|
31520
|
-
|
|
31521
|
-
|
|
31522
|
-
|
|
31523
|
-
|
|
31524
|
-
|
|
31525
|
-
|
|
31526
|
-
|
|
31527
|
-
|
|
31528
|
-
|
|
31529
|
-
|
|
31530
|
-
|
|
31531
|
-
|
|
31532
|
-
|
|
31533
|
-
|
|
31534
|
-
|
|
31535
|
-
|
|
31536
|
-
|
|
31537
|
-
|
|
31538
|
-
|
|
31539
|
-
|
|
31540
|
-
}
|
|
31541
|
-
|
|
31542
|
-
|
|
31543
|
-
kind: "refuse",
|
|
31544
|
-
message: `'.${method}(...)' comparator is outside the ${adapterName} adapter's evaluable / structured surface`,
|
|
31545
|
-
suggestion: `Pre-compute the sorted array, or move this position to a '/* @client */' boundary.`
|
|
31546
|
-
};
|
|
31547
|
-
}
|
|
31548
|
-
function reduceEvalPlan(body, params, init, direction) {
|
|
31549
|
-
const json = serializeParsedExpr(body);
|
|
31550
|
-
if (json === null || init.kind !== "literal" || params.length < 2)
|
|
31551
|
-
return null;
|
|
31552
|
-
let seed;
|
|
31553
|
-
if (init.literalType === "string")
|
|
31554
|
-
seed = { kind: "string", value: String(init.value) };
|
|
31555
|
-
else if (init.literalType === "number")
|
|
31556
|
-
seed = { kind: "number", text: String(init.value) };
|
|
31557
|
-
else
|
|
31558
|
-
return null;
|
|
31559
|
-
return {
|
|
31560
|
-
kind: "eval",
|
|
31561
|
-
helper: "reduce_eval",
|
|
31562
|
-
operands: [
|
|
31563
|
-
{ kind: "string", value: json },
|
|
31564
|
-
{ kind: "string", value: params[0] },
|
|
31565
|
-
{ kind: "string", value: params[1] },
|
|
31566
|
-
seed,
|
|
31567
|
-
{ kind: "string", value: direction }
|
|
31568
|
-
],
|
|
31569
|
-
captured: freeVarsInBody(body, new Set(params))
|
|
31570
|
-
};
|
|
31571
|
-
}
|
|
31572
|
-
function projectionEvalPlan(helper, body, params) {
|
|
31573
|
-
const json = serializeParsedExpr(body);
|
|
31574
|
-
if (json === null)
|
|
31575
|
-
return null;
|
|
31576
|
-
return {
|
|
31577
|
-
kind: "eval",
|
|
31578
|
-
helper,
|
|
31579
|
-
operands: [
|
|
31580
|
-
{ kind: "string", value: json },
|
|
31581
|
-
{ kind: "string", value: String(params[0]) }
|
|
31582
|
-
],
|
|
31583
|
-
captured: freeVarsInBody(body, new Set(params.slice(0, 1)))
|
|
31584
|
-
};
|
|
31585
|
-
}
|
|
31586
|
-
function emitCallbackEval(plan, recv, emit, spelling) {
|
|
31587
|
-
const operands = [recv];
|
|
31588
|
-
for (const operand of plan.operands) {
|
|
31589
|
-
if (operand.kind === "string")
|
|
31590
|
-
operands.push(spelling.string(operand.value));
|
|
31591
|
-
else if (operand.kind === "number")
|
|
31592
|
-
operands.push(operand.text);
|
|
31593
|
-
else
|
|
31594
|
-
operands.push(spelling.boolean(operand.value));
|
|
31692
|
+
flattenTemplate(value) {
|
|
31693
|
+
const v = value;
|
|
31694
|
+
return this.renderTemplatePartsAsJs(v.parts);
|
|
31695
|
+
}
|
|
31696
|
+
renderComponentProps(comp) {
|
|
31697
|
+
const parts = [];
|
|
31698
|
+
for (const prop of comp.props) {
|
|
31699
|
+
switch (prop.value.kind) {
|
|
31700
|
+
case "jsx-children": {
|
|
31701
|
+
const rendered = prop.value.children.map((c) => this.renderNode(c)).join("");
|
|
31702
|
+
parts.push(`${prop.name}={<>${rendered}</>}`);
|
|
31703
|
+
break;
|
|
31704
|
+
}
|
|
31705
|
+
case "spread":
|
|
31706
|
+
parts.push(`{...${prop.value.expr}}`);
|
|
31707
|
+
break;
|
|
31708
|
+
case "expression":
|
|
31709
|
+
parts.push(`${prop.name}={${prop.value.expr}}`);
|
|
31710
|
+
break;
|
|
31711
|
+
case "template":
|
|
31712
|
+
parts.push(`${prop.name}={${this.flattenTemplate(prop.value)}}`);
|
|
31713
|
+
break;
|
|
31714
|
+
case "boolean-shorthand":
|
|
31715
|
+
parts.push(prop.name);
|
|
31716
|
+
break;
|
|
31717
|
+
case "literal":
|
|
31718
|
+
parts.push(`${prop.name}="${prop.value.value}"`);
|
|
31719
|
+
break;
|
|
31720
|
+
case "boolean-attr":
|
|
31721
|
+
parts.push(prop.name);
|
|
31722
|
+
break;
|
|
31723
|
+
}
|
|
31724
|
+
}
|
|
31725
|
+
return parts.length > 0 ? " " + parts.join(" ") : "";
|
|
31595
31726
|
}
|
|
31596
|
-
const env = plan.captured.map((name) => [name, emit({ kind: "identifier", name })]);
|
|
31597
|
-
operands.push(spelling.env(env));
|
|
31598
|
-
return spelling.call(plan.helper, operands);
|
|
31599
31727
|
}
|
|
31600
|
-
|
|
31601
|
-
|
|
31602
|
-
|
|
31603
|
-
|
|
31728
|
+
var testAdapter = new TestAdapter;
|
|
31729
|
+
// src/adapters/parsed-expr-emitter.ts
|
|
31730
|
+
function isStringTypedOperand(expr, isStringName) {
|
|
31731
|
+
if (expr.kind === "literal" && expr.literalType === "string")
|
|
31732
|
+
return true;
|
|
31733
|
+
if (expr.kind === "template-literal")
|
|
31734
|
+
return true;
|
|
31735
|
+
if (expr.kind === "call" && expr.callee.kind === "identifier" && expr.args.length === 0) {
|
|
31736
|
+
return isStringName(expr.callee.name);
|
|
31604
31737
|
}
|
|
31605
|
-
|
|
31606
|
-
|
|
31607
|
-
|
|
31608
|
-
if (
|
|
31609
|
-
return
|
|
31610
|
-
|
|
31611
|
-
|
|
31612
|
-
|
|
31613
|
-
return
|
|
31614
|
-
}
|
|
31615
|
-
function unloweredCallRefusal(callee, args, adapterName) {
|
|
31616
|
-
const name = stringifyParsedExpr(callee);
|
|
31617
|
-
return {
|
|
31618
|
-
message: args.length === 0 ? `Call '${name}()' reads a JavaScript global, which has no ${adapterName} template binding; read as a value it would drop the call` : `Call '${name}(...)' has no ${adapterName} template lowering; read as a value it would drop the call and its arguments`,
|
|
31619
|
-
suggestion: "Pre-compute the value in the backend and pass it as a prop, or add /* @client */ for client-only evaluation (no SSR)."
|
|
31620
|
-
};
|
|
31738
|
+
if (expr.kind === "member" && expr.object.kind === "identifier" && expr.object.name === "props") {
|
|
31739
|
+
return isStringName(expr.property, true);
|
|
31740
|
+
}
|
|
31741
|
+
if (expr.kind === "identifier")
|
|
31742
|
+
return isStringName(expr.name);
|
|
31743
|
+
if (expr.kind === "binary" && expr.op === "+") {
|
|
31744
|
+
return isStringTypedOperand(expr.left, isStringName) || isStringTypedOperand(expr.right, isStringName);
|
|
31745
|
+
}
|
|
31746
|
+
return false;
|
|
31621
31747
|
}
|
|
31622
|
-
function
|
|
31623
|
-
return
|
|
31624
|
-
message: `Filter predicate contains ${shape}, which has no ${adapterName} loop-filter form`,
|
|
31625
|
-
suggestion: `Rewrite the predicate as comparisons joined with && / || / !, or add /* @client */ for client-only evaluation (no SSR).`
|
|
31626
|
-
};
|
|
31748
|
+
function isStringConcatBinary(op, left, right, isStringName) {
|
|
31749
|
+
return op === "+" && (isStringTypedOperand(left, isStringName) || isStringTypedOperand(right, isStringName));
|
|
31627
31750
|
}
|
|
31628
|
-
function
|
|
31629
|
-
|
|
31630
|
-
|
|
31631
|
-
|
|
31632
|
-
|
|
31751
|
+
function isNumericArithmeticResult(expr, isStringName) {
|
|
31752
|
+
if (!expr)
|
|
31753
|
+
return false;
|
|
31754
|
+
if (expr.kind === "unary")
|
|
31755
|
+
return expr.op === "-";
|
|
31756
|
+
if (expr.kind !== "binary")
|
|
31757
|
+
return false;
|
|
31758
|
+
if (expr.op === "+")
|
|
31759
|
+
return !isStringConcatBinary(expr.op, expr.left, expr.right, isStringName);
|
|
31760
|
+
return expr.op === "-" || expr.op === "*" || expr.op === "/" || expr.op === "%";
|
|
31633
31761
|
}
|
|
31634
|
-
function
|
|
31635
|
-
|
|
31636
|
-
|
|
31637
|
-
|
|
31638
|
-
|
|
31762
|
+
function arithmeticHelper(op) {
|
|
31763
|
+
if (op === "%")
|
|
31764
|
+
return "mod";
|
|
31765
|
+
if (op === "/")
|
|
31766
|
+
return "div";
|
|
31767
|
+
return null;
|
|
31639
31768
|
}
|
|
31640
|
-
|
|
31641
|
-
|
|
31642
|
-
function propsSpreadParam(param, earlier) {
|
|
31643
|
-
if (param.optional === false)
|
|
31644
|
-
return "entry";
|
|
31645
|
-
return earlier.spread || earlier.keys.has(param.name) ? "present" : "entry";
|
|
31769
|
+
function groupBinaryOperand(operand, emitted) {
|
|
31770
|
+
return operand.kind === "binary" || operand.kind === "logical" || operand.kind === "conditional" ? `(${emitted})` : emitted;
|
|
31646
31771
|
}
|
|
31647
|
-
function
|
|
31648
|
-
|
|
31649
|
-
return "_bf_slot";
|
|
31650
|
-
if (entry.kind === "children")
|
|
31651
|
-
return "children";
|
|
31652
|
-
return entry.name;
|
|
31772
|
+
function groupUnaryOperand(operand, emitted) {
|
|
31773
|
+
return operand.kind === "unary" ? `(${emitted})` : groupBinaryOperand(operand, emitted);
|
|
31653
31774
|
}
|
|
31654
|
-
function
|
|
31655
|
-
const segments = [
|
|
31656
|
-
|
|
31657
|
-
const
|
|
31658
|
-
|
|
31659
|
-
|
|
31660
|
-
|
|
31661
|
-
segments.push({ kind: "entries", entries: [entry] });
|
|
31662
|
-
return;
|
|
31775
|
+
function groupObjectLiteralSegments(properties, literalOf, emit) {
|
|
31776
|
+
const segments = [];
|
|
31777
|
+
let run = [];
|
|
31778
|
+
const flushRun = () => {
|
|
31779
|
+
if (run.length > 0) {
|
|
31780
|
+
segments.push(literalOf(run));
|
|
31781
|
+
run = [];
|
|
31663
31782
|
}
|
|
31664
|
-
const at = last.entries.findIndex((e) => componentPropKey(e) === componentPropKey(entry));
|
|
31665
|
-
if (at === -1)
|
|
31666
|
-
last.entries.push(entry);
|
|
31667
|
-
else
|
|
31668
|
-
last.entries[at] = entry;
|
|
31669
31783
|
};
|
|
31670
|
-
const
|
|
31671
|
-
|
|
31672
|
-
|
|
31673
|
-
|
|
31674
|
-
|
|
31675
|
-
|
|
31676
|
-
|
|
31677
|
-
|
|
31784
|
+
for (const p of properties) {
|
|
31785
|
+
if (p.kind === "spread") {
|
|
31786
|
+
flushRun();
|
|
31787
|
+
segments.push(emit(p.expr));
|
|
31788
|
+
} else {
|
|
31789
|
+
run.push(p);
|
|
31790
|
+
}
|
|
31791
|
+
}
|
|
31792
|
+
flushRun();
|
|
31793
|
+
return segments;
|
|
31794
|
+
}
|
|
31795
|
+
function asToStringCall(expr) {
|
|
31796
|
+
if (expr.kind !== "call" || expr.args.length !== 0)
|
|
31797
|
+
return null;
|
|
31798
|
+
const callee = expr.callee;
|
|
31799
|
+
if (callee.kind !== "member" || callee.computed || callee.optional || callee.property !== "toString")
|
|
31800
|
+
return null;
|
|
31801
|
+
return callee.object;
|
|
31802
|
+
}
|
|
31803
|
+
function emitParsedExpr(expr, emitter) {
|
|
31804
|
+
const emit = (child) => emitParsedExpr(child, emitter);
|
|
31805
|
+
switch (expr.kind) {
|
|
31806
|
+
case "identifier":
|
|
31807
|
+
return emitter.identifier(expr.name);
|
|
31808
|
+
case "literal":
|
|
31809
|
+
return emitter.literal(expr.value, expr.literalType);
|
|
31810
|
+
case "call": {
|
|
31811
|
+
if (emitter.lowering) {
|
|
31812
|
+
for (const matcher of emitter.lowering.matchers) {
|
|
31813
|
+
const node = matcher(expr.callee, expr.args);
|
|
31814
|
+
if (!node)
|
|
31815
|
+
continue;
|
|
31816
|
+
const rendered = emitter.lowering.render(node, emit);
|
|
31817
|
+
if (rendered !== null)
|
|
31818
|
+
return rendered;
|
|
31819
|
+
break;
|
|
31820
|
+
}
|
|
31821
|
+
}
|
|
31822
|
+
const toStringReceiver = asToStringCall(expr);
|
|
31823
|
+
if (toStringReceiver) {
|
|
31824
|
+
return emitter.call({ kind: "identifier", name: "String" }, [toStringReceiver], emit);
|
|
31678
31825
|
}
|
|
31826
|
+
const cb = asCallbackMethodCall(expr);
|
|
31827
|
+
if (cb)
|
|
31828
|
+
return emitter.callbackMethod(cb.method, cb.object, cb.arrow, cb.args, emit);
|
|
31829
|
+
return emitter.call(expr.callee, expr.args, emit);
|
|
31679
31830
|
}
|
|
31680
|
-
|
|
31681
|
-
|
|
31682
|
-
|
|
31683
|
-
|
|
31684
|
-
|
|
31685
|
-
|
|
31686
|
-
|
|
31687
|
-
|
|
31688
|
-
|
|
31689
|
-
|
|
31690
|
-
|
|
31691
|
-
|
|
31692
|
-
|
|
31831
|
+
case "member":
|
|
31832
|
+
return emitter.member(expr.object, expr.property, expr.computed, expr.optional, emit);
|
|
31833
|
+
case "index-access":
|
|
31834
|
+
return emitter.indexAccess(expr.object, expr.index, emit);
|
|
31835
|
+
case "binary":
|
|
31836
|
+
return emitter.binary(expr.op, expr.left, expr.right, emit);
|
|
31837
|
+
case "unary":
|
|
31838
|
+
return emitter.unary(expr.op, expr.argument, emit);
|
|
31839
|
+
case "logical":
|
|
31840
|
+
return emitter.logical(expr.op, expr.left, expr.right, emit);
|
|
31841
|
+
case "conditional":
|
|
31842
|
+
return emitter.conditional(expr.test, expr.consequent, expr.alternate, emit);
|
|
31843
|
+
case "template-literal":
|
|
31844
|
+
return emitter.templateLiteral(expr.parts, emit);
|
|
31845
|
+
case "arrow":
|
|
31846
|
+
return emitter.arrow(expr.params, expr.body, emit);
|
|
31847
|
+
case "regex":
|
|
31848
|
+
return emitter.regex(expr.raw);
|
|
31849
|
+
case "array-literal":
|
|
31850
|
+
return emitter.arrayLiteral(expr.elements, emit);
|
|
31851
|
+
case "object-literal":
|
|
31852
|
+
return emitter.objectLiteral(expr.properties, expr.raw, emit);
|
|
31853
|
+
case "array-method":
|
|
31854
|
+
if (expr.method === "flat") {
|
|
31855
|
+
return emitter.flatMethod(expr.object, expr.depthExpr ? { expr: expr.depthExpr } : expr.flatDepth, emit);
|
|
31693
31856
|
}
|
|
31857
|
+
return emitter.arrayMethod(expr.method, expr.object, expr.args, emit);
|
|
31858
|
+
case "unsupported":
|
|
31859
|
+
return emitter.unsupported(expr.raw, expr.reason);
|
|
31860
|
+
default: {
|
|
31861
|
+
const _exhaustive = expr;
|
|
31862
|
+
throw new Error(`emitParsedExpr: unhandled ParsedExpr kind ${_exhaustive.kind}`);
|
|
31863
|
+
}
|
|
31864
|
+
}
|
|
31865
|
+
}
|
|
31866
|
+
// src/adapters/style-object.ts
|
|
31867
|
+
function staticString(value) {
|
|
31868
|
+
if (value.kind === "literal" && value.literalType === "string" && typeof value.value === "string")
|
|
31869
|
+
return value.value;
|
|
31870
|
+
if (value.kind === "template-literal" && value.parts.every((p) => p.type === "string")) {
|
|
31871
|
+
return value.parts.map((p) => p.type === "string" ? p.value : "").join("");
|
|
31872
|
+
}
|
|
31873
|
+
return null;
|
|
31874
|
+
}
|
|
31875
|
+
function planStyleObject(value) {
|
|
31876
|
+
const parsed = value.parsed;
|
|
31877
|
+
if (parsed?.kind !== "object-literal" || parsed.properties.length === 0)
|
|
31878
|
+
return null;
|
|
31879
|
+
const entries = [];
|
|
31880
|
+
for (const prop of parsed.properties) {
|
|
31881
|
+
if (prop.kind !== "prop" || prop.keyKind === "numeric")
|
|
31882
|
+
return null;
|
|
31883
|
+
const cssKey = cssKebabCase(prop.key);
|
|
31884
|
+
const literal = staticString(prop.value);
|
|
31885
|
+
if (literal !== null) {
|
|
31886
|
+
entries.push({ cssKey, kind: "literal", value: literal });
|
|
31887
|
+
} else if (isSupported(prop.value).supported) {
|
|
31888
|
+
entries.push({ cssKey, kind: "expr", expr: stringifyParsedExpr(prop.value), parsed: prop.value });
|
|
31694
31889
|
} else {
|
|
31695
|
-
|
|
31890
|
+
return null;
|
|
31696
31891
|
}
|
|
31697
31892
|
}
|
|
31698
|
-
|
|
31699
|
-
|
|
31700
|
-
|
|
31701
|
-
|
|
31702
|
-
|
|
31703
|
-
|
|
31893
|
+
return entries;
|
|
31894
|
+
}
|
|
31895
|
+
// src/adapters/boolean-result.ts
|
|
31896
|
+
var COMPARISON_OPS = new Set([
|
|
31897
|
+
"<",
|
|
31898
|
+
">",
|
|
31899
|
+
"<=",
|
|
31900
|
+
">=",
|
|
31901
|
+
"==",
|
|
31902
|
+
"===",
|
|
31903
|
+
"!=",
|
|
31904
|
+
"!=="
|
|
31905
|
+
]);
|
|
31906
|
+
function isBooleanResultParsed(node, isBooleanName) {
|
|
31907
|
+
switch (node.kind) {
|
|
31908
|
+
case "literal":
|
|
31909
|
+
return node.literalType === "boolean";
|
|
31910
|
+
case "binary":
|
|
31911
|
+
return COMPARISON_OPS.has(node.op);
|
|
31912
|
+
case "unary":
|
|
31913
|
+
return node.op === "!";
|
|
31914
|
+
case "logical":
|
|
31915
|
+
return isBooleanResultParsed(node.left, isBooleanName) && isBooleanResultParsed(node.right, isBooleanName);
|
|
31916
|
+
case "conditional":
|
|
31917
|
+
return isBooleanResultParsed(node.consequent, isBooleanName) && isBooleanResultParsed(node.alternate, isBooleanName);
|
|
31918
|
+
case "call":
|
|
31919
|
+
return !!isBooleanName && node.callee.kind === "identifier" && node.args.length === 0 && isBooleanName(node.callee.name);
|
|
31920
|
+
case "member":
|
|
31921
|
+
return !!isBooleanName && !node.computed && node.object.kind === "identifier" && node.object.name === "props" && isBooleanName(node.property, true);
|
|
31922
|
+
case "identifier":
|
|
31923
|
+
return !!isBooleanName && isBooleanName(node.name);
|
|
31924
|
+
default:
|
|
31925
|
+
return false;
|
|
31926
|
+
}
|
|
31704
31927
|
}
|
|
31705
|
-
function
|
|
31706
|
-
|
|
31707
|
-
|
|
31708
|
-
|
|
31709
|
-
|
|
31710
|
-
|
|
31711
|
-
|
|
31712
|
-
|
|
31713
|
-
const part = spelling.entry(entry);
|
|
31714
|
-
if (part)
|
|
31715
|
-
parts.push(part);
|
|
31716
|
-
}
|
|
31717
|
-
return { kind: "entries", parts };
|
|
31718
|
-
});
|
|
31928
|
+
function stringifyBooleanTernaryBranches(node) {
|
|
31929
|
+
if (node.kind !== "conditional" || isBooleanResultParsed(node))
|
|
31930
|
+
return node;
|
|
31931
|
+
return {
|
|
31932
|
+
...node,
|
|
31933
|
+
consequent: stringifyBooleanBranch(node.consequent),
|
|
31934
|
+
alternate: stringifyBooleanBranch(node.alternate)
|
|
31935
|
+
};
|
|
31719
31936
|
}
|
|
31720
|
-
function
|
|
31721
|
-
|
|
31722
|
-
|
|
31723
|
-
|
|
31724
|
-
|
|
31725
|
-
|
|
31726
|
-
|
|
31727
|
-
|
|
31728
|
-
|
|
31937
|
+
function stringifyBooleanBranch(branch) {
|
|
31938
|
+
if (!isBooleanResultParsed(branch))
|
|
31939
|
+
return stringifyBooleanTernaryBranches(branch);
|
|
31940
|
+
if (branch.kind === "literal") {
|
|
31941
|
+
return { kind: "literal", value: String(branch.value), literalType: "string" };
|
|
31942
|
+
}
|
|
31943
|
+
return {
|
|
31944
|
+
kind: "conditional",
|
|
31945
|
+
test: branch,
|
|
31946
|
+
consequent: { kind: "literal", value: "true", literalType: "string" },
|
|
31947
|
+
alternate: { kind: "literal", value: "false", literalType: "string" }
|
|
31729
31948
|
};
|
|
31730
|
-
|
|
31731
|
-
|
|
31732
|
-
|
|
31733
|
-
|
|
31734
|
-
|
|
31949
|
+
}
|
|
31950
|
+
function collectBooleanValueNames(metadata) {
|
|
31951
|
+
const isBoolean = (type) => type?.kind === "primitive" && type.primitive === "boolean";
|
|
31952
|
+
const isBooleanSeed = (type, seed) => {
|
|
31953
|
+
const text = seed?.trim();
|
|
31954
|
+
return isBoolean(type) || (!type || type.kind === "unknown") && (text === "true" || text === "false");
|
|
31955
|
+
};
|
|
31956
|
+
const names = new Set;
|
|
31957
|
+
const props = new Set;
|
|
31958
|
+
for (const signal of metadata.signals) {
|
|
31959
|
+
if (isBooleanSeed(signal.type, signal.initialValue))
|
|
31960
|
+
names.add(signal.getter);
|
|
31961
|
+
}
|
|
31962
|
+
for (const memo of metadata.memos ?? []) {
|
|
31963
|
+
if (isBoolean(memo.type))
|
|
31964
|
+
names.add(memo.name);
|
|
31965
|
+
}
|
|
31966
|
+
const provenParams = new Set;
|
|
31967
|
+
for (const param of metadata.propsParams) {
|
|
31968
|
+
if (!isBoolean(param.type))
|
|
31969
|
+
continue;
|
|
31970
|
+
if (param.optional && !(param.parsed && isBooleanResultParsed(param.parsed, (n, member) => !member && provenParams.has(n))))
|
|
31735
31971
|
continue;
|
|
31972
|
+
provenParams.add(param.name);
|
|
31973
|
+
props.add(param.sourceName ?? param.name);
|
|
31974
|
+
if (!metadata.propsObjectName)
|
|
31975
|
+
names.add(param.name);
|
|
31976
|
+
}
|
|
31977
|
+
const propsObject = metadata.propsObjectName;
|
|
31978
|
+
const booleanTyped = new Set(metadata.propsParams.filter((p) => isBoolean(p.type)).map((p) => p.sourceName ?? p.name));
|
|
31979
|
+
const readsBooleanProp = (e) => {
|
|
31980
|
+
if (!e)
|
|
31981
|
+
return false;
|
|
31982
|
+
if (e.kind === "member") {
|
|
31983
|
+
return !e.computed && !!propsObject && e.object.kind === "identifier" && e.object.name === propsObject && props.has(e.property);
|
|
31736
31984
|
}
|
|
31737
|
-
|
|
31738
|
-
const
|
|
31739
|
-
|
|
31740
|
-
resolved.presentParams = [];
|
|
31985
|
+
if (e.kind === "logical" && (e.op === "??" || e.op === "||")) {
|
|
31986
|
+
const left = e.left;
|
|
31987
|
+
return left.kind === "member" && !left.computed && !!propsObject && left.object.kind === "identifier" && left.object.name === propsObject && booleanTyped.has(left.property) && e.right.kind === "literal" && e.right.literalType === "boolean";
|
|
31741
31988
|
}
|
|
31989
|
+
return false;
|
|
31990
|
+
};
|
|
31991
|
+
for (const constant of metadata.localConstants ?? []) {
|
|
31992
|
+
if (readsBooleanProp(constant.parsed) || isBooleanSeed(constant.type ?? undefined, constant.value))
|
|
31993
|
+
names.add(constant.name);
|
|
31994
|
+
else
|
|
31995
|
+
names.delete(constant.name);
|
|
31742
31996
|
}
|
|
31743
|
-
return
|
|
31744
|
-
}
|
|
31745
|
-
function isEmptyComponentProps(segments) {
|
|
31746
|
-
return segments.every((segment) => segment.kind === "entries" && segment.parts.length === 0);
|
|
31997
|
+
return { names, props };
|
|
31747
31998
|
}
|
|
31748
|
-
function
|
|
31749
|
-
const
|
|
31750
|
-
|
|
31999
|
+
function isBooleanResultExpr(expr) {
|
|
32000
|
+
const parsed = parseExpression(expr.trim());
|
|
32001
|
+
if (!parsed)
|
|
32002
|
+
return false;
|
|
32003
|
+
return isBooleanResultParsed(parsed);
|
|
31751
32004
|
}
|
|
31752
|
-
|
|
31753
|
-
var IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
31754
|
-
function unsupportedAttrExpression(expr, loweringMatchers) {
|
|
31755
|
-
let probe = expr.trim();
|
|
31756
|
-
while (probe.startsWith("("))
|
|
31757
|
-
probe = probe.slice(1).trimStart();
|
|
31758
|
-
const startsAsObjectLiteral = probe.startsWith("{");
|
|
31759
|
-
const hasTaggedTemplate = /[A-Za-z_$][\w$]*\s*`/.test(probe);
|
|
31760
|
-
if (!startsAsObjectLiteral && !hasTaggedTemplate)
|
|
31761
|
-
return null;
|
|
32005
|
+
function isExplicitStringCall(expr) {
|
|
31762
32006
|
const parsed = parseExpression(expr.trim());
|
|
31763
|
-
|
|
31764
|
-
if (parsed.kind !== "unsupported" && support.supported)
|
|
31765
|
-
return null;
|
|
31766
|
-
return { reason: support.reason ?? (parsed.kind === "unsupported" ? parsed.reason : undefined) };
|
|
32007
|
+
return !!parsed && parsed.kind === "call" && parsed.callee.kind === "identifier" && parsed.callee.name === "String" && parsed.args.length === 1;
|
|
31767
32008
|
}
|
|
31768
|
-
|
|
31769
|
-
|
|
31770
|
-
|
|
31771
|
-
|
|
31772
|
-
|
|
31773
|
-
|
|
31774
|
-
|
|
31775
|
-
|
|
31776
|
-
|
|
31777
|
-
|
|
31778
|
-
|
|
31779
|
-
|
|
31780
|
-
|
|
31781
|
-
|
|
31782
|
-
|
|
32009
|
+
var ARIA_BOOLEAN_ATTRS = new Set([
|
|
32010
|
+
"aria-atomic",
|
|
32011
|
+
"aria-busy",
|
|
32012
|
+
"aria-disabled",
|
|
32013
|
+
"aria-hidden",
|
|
32014
|
+
"aria-modal",
|
|
32015
|
+
"aria-multiline",
|
|
32016
|
+
"aria-multiselectable",
|
|
32017
|
+
"aria-readonly",
|
|
32018
|
+
"aria-required",
|
|
32019
|
+
"aria-selected",
|
|
32020
|
+
"aria-expanded",
|
|
32021
|
+
"aria-checked",
|
|
32022
|
+
"aria-pressed"
|
|
32023
|
+
]);
|
|
32024
|
+
function isAriaBooleanAttr(name) {
|
|
32025
|
+
return ARIA_BOOLEAN_ATTRS.has(name);
|
|
31783
32026
|
}
|
|
31784
|
-
|
|
31785
|
-
|
|
31786
|
-
|
|
31787
|
-
const nullable = nullableBareRead(value, ctx);
|
|
31788
|
-
if (nullable !== null)
|
|
31789
|
-
return { kind: "omit-nullable", boolStr: ctx.boolStr(value.expr, name), restKey: nullable.restKey };
|
|
31790
|
-
}
|
|
31791
|
-
if (booleanAttr)
|
|
31792
|
-
return { kind: "boolean-attr" };
|
|
31793
|
-
if (value.presenceOrUndefined)
|
|
31794
|
-
return { kind: "presence", boolStr: ctx.boolStr(value.expr, name) };
|
|
31795
|
-
const ternary = parseUndefinedAlternateTernary(value.expr);
|
|
31796
|
-
if (ternary)
|
|
31797
|
-
return { kind: "undefined-alternate", ternary };
|
|
31798
|
-
const boolStr = ctx.boolStr(value.expr, name);
|
|
31799
|
-
if (attrValueMayBeNullish(value.parsed, ctx.nullishAttrCtx, (n) => ctx.isLoopBound(n)))
|
|
31800
|
-
return { kind: "omit-nil", boolStr };
|
|
31801
|
-
return { kind: "plain", boolStr };
|
|
32027
|
+
// src/adapters/literal-value.ts
|
|
32028
|
+
function isStringTypeInfo(type) {
|
|
32029
|
+
return type?.kind === "primitive" && type.primitive === "string";
|
|
31802
32030
|
}
|
|
31803
|
-
function
|
|
31804
|
-
|
|
31805
|
-
|
|
31806
|
-
|
|
31807
|
-
|
|
31808
|
-
normalized = bare.slice(ctx.propsObjectName.length + 1);
|
|
31809
|
-
else if (restKey)
|
|
31810
|
-
normalized = bare.slice(ctx.restPropsName.length + 1);
|
|
31811
|
-
const prop = IDENTIFIER.test(normalized) && ctx.nullableOptionalProps.has(normalized) && !ctx.isLoopBound(normalized);
|
|
31812
|
-
const signal = nullableSignalAttrGetter(value.parsed, ctx.nullableSignalGetters);
|
|
31813
|
-
if (prop || signal !== null && !ctx.isLoopBound(signal))
|
|
31814
|
-
return { restKey };
|
|
31815
|
-
return null;
|
|
32031
|
+
function isBareStringLiteral(initialValue) {
|
|
32032
|
+
if (!initialValue)
|
|
32033
|
+
return false;
|
|
32034
|
+
const v = initialValue.trim();
|
|
32035
|
+
return v.startsWith("'") && v.endsWith("'") || v.startsWith('"') && v.endsWith('"');
|
|
31816
32036
|
}
|
|
31817
|
-
function
|
|
31818
|
-
|
|
31819
|
-
if (parsed?.kind !== "conditional")
|
|
31820
|
-
return null;
|
|
31821
|
-
const alt = parsed.alternate;
|
|
31822
|
-
const isUndef = alt.kind === "identifier" && (alt.name === "undefined" || alt.name === "null") || alt.kind === "literal" && (alt.value === null || alt.value === undefined);
|
|
31823
|
-
if (!isUndef)
|
|
31824
|
-
return null;
|
|
31825
|
-
return {
|
|
31826
|
-
condition: exprToString(parsed.test),
|
|
31827
|
-
consequent: exprToString(parsed.consequent),
|
|
31828
|
-
testParsed: parsed.test,
|
|
31829
|
-
consequentParsed: parsed.consequent
|
|
31830
|
-
};
|
|
32037
|
+
function isLiteralIndex(index) {
|
|
32038
|
+
return index.kind === "literal" && (index.literalType === "number" || index.literalType === "string");
|
|
31831
32039
|
}
|
|
31832
|
-
|
|
31833
|
-
|
|
31834
|
-
|
|
31835
|
-
|
|
32040
|
+
// src/adapters/array-method.ts
|
|
32041
|
+
var required = { kind: "required" };
|
|
32042
|
+
var optional = { kind: "optional" };
|
|
32043
|
+
var zero = { kind: "default", value: { kind: "number", value: 0 } };
|
|
32044
|
+
var ARRAY_METHOD_CATALOGUE = {
|
|
32045
|
+
join: { helper: "join", params: [{ kind: "default", value: { kind: "string", value: "," } }] },
|
|
32046
|
+
includes: { helper: "includes", params: [required] },
|
|
32047
|
+
indexOf: { helper: "index_of", params: [required] },
|
|
32048
|
+
lastIndexOf: { helper: "last_index_of", params: [required] },
|
|
32049
|
+
at: { helper: "at", params: [zero] },
|
|
32050
|
+
concat: { helper: "concat", params: [required], receiverWhenNoArgs: true },
|
|
32051
|
+
slice: { helper: "slice", params: [zero, { kind: "default", value: { kind: "undefined" } }] },
|
|
32052
|
+
reverse: { helper: "reverse", params: [] },
|
|
32053
|
+
toReversed: { helper: "reverse", params: [] },
|
|
32054
|
+
toLowerCase: { helper: "lc", params: [] },
|
|
32055
|
+
toUpperCase: { helper: "uc", params: [] },
|
|
32056
|
+
trim: { helper: "trim", params: [] },
|
|
32057
|
+
trimStart: { helper: "trim_start", params: [] },
|
|
32058
|
+
trimEnd: { helper: "trim_end", params: [] },
|
|
32059
|
+
toFixed: { helper: "to_fixed", params: [zero] },
|
|
32060
|
+
split: { helper: "split", params: [optional, optional] },
|
|
32061
|
+
startsWith: { helper: "starts_with", params: [required, optional] },
|
|
32062
|
+
endsWith: { helper: "ends_with", params: [required, optional] },
|
|
32063
|
+
replace: { helper: "replace", params: [required, required] },
|
|
32064
|
+
replaceAll: { helper: "replace_all", params: [required, required] },
|
|
32065
|
+
repeat: { helper: "repeat", params: [zero] },
|
|
32066
|
+
padStart: { helper: "pad_start", params: [zero, optional] },
|
|
32067
|
+
padEnd: { helper: "pad_end", params: [zero, optional] }
|
|
32068
|
+
};
|
|
32069
|
+
function lowerArrayMethod(method, object, args) {
|
|
32070
|
+
const entry = ARRAY_METHOD_CATALOGUE[method];
|
|
32071
|
+
if (entry.receiverWhenNoArgs && args.length === 0)
|
|
32072
|
+
return { kind: "receiver", object };
|
|
32073
|
+
const out = [];
|
|
32074
|
+
for (const [i, param] of entry.params.entries()) {
|
|
32075
|
+
const arg = args[i];
|
|
32076
|
+
if (arg) {
|
|
32077
|
+
out.push({ kind: "expr", expr: arg });
|
|
32078
|
+
} else if (param.kind === "default") {
|
|
32079
|
+
out.push({ kind: "default", value: param.value });
|
|
32080
|
+
} else if (param.kind === "optional") {
|
|
32081
|
+
break;
|
|
32082
|
+
} else {
|
|
32083
|
+
throw new Error(`lowerArrayMethod: '.${method}()' needs argument ${i + 1}`);
|
|
32084
|
+
}
|
|
31836
32085
|
}
|
|
31837
|
-
|
|
31838
|
-
const init = localConstInitializer(trimmed, ctx);
|
|
31839
|
-
if (init !== null)
|
|
31840
|
-
candidates.push(parseExpression(init));
|
|
31841
|
-
return { kind: "value", candidates };
|
|
31842
|
-
}
|
|
31843
|
-
function localConstInitializer(name, ctx) {
|
|
31844
|
-
if (!IDENTIFIER.test(name) || ctx.isBound(name))
|
|
31845
|
-
return null;
|
|
31846
|
-
const init = ctx.localConstants.find((c) => c.name === name && !c.isModule)?.value?.trim();
|
|
31847
|
-
return init !== undefined && !IDENTIFIER.test(init) ? init : null;
|
|
32086
|
+
return { kind: "call", helper: entry.helper, object, args: out };
|
|
31848
32087
|
}
|
|
31849
|
-
|
|
31850
|
-
|
|
31851
|
-
|
|
31852
|
-
|
|
31853
|
-
|
|
31854
|
-
|
|
31855
|
-
return false;
|
|
31856
|
-
for (const name of [...bindings.map((b) => b.name), loop.index]) {
|
|
31857
|
-
if (name && name.startsWith("__bf_"))
|
|
31858
|
-
return false;
|
|
32088
|
+
function emitArrayMethod(plan, emit, spelling) {
|
|
32089
|
+
if (plan.kind === "receiver")
|
|
32090
|
+
return emit(plan.object);
|
|
32091
|
+
const operands = [emit(plan.object)];
|
|
32092
|
+
for (const arg of plan.args) {
|
|
32093
|
+
operands.push(arg.kind === "expr" ? emit(arg.expr) : defaultLiteral(arg.value, spelling));
|
|
31859
32094
|
}
|
|
31860
|
-
|
|
31861
|
-
|
|
31862
|
-
|
|
31863
|
-
|
|
31864
|
-
|
|
31865
|
-
return
|
|
31866
|
-
|
|
32095
|
+
return spelling.call(plan.helper, operands);
|
|
32096
|
+
}
|
|
32097
|
+
function defaultLiteral(value, spelling) {
|
|
32098
|
+
switch (value.kind) {
|
|
32099
|
+
case "number":
|
|
32100
|
+
return String(value.value);
|
|
32101
|
+
case "string":
|
|
32102
|
+
return `'${value.value}'`;
|
|
32103
|
+
case "undefined":
|
|
32104
|
+
return spelling.undefinedLiteral;
|
|
31867
32105
|
}
|
|
31868
|
-
const objectRestNames = bindings.filter((b) => b.rest?.kind === "object").map((b) => b.name);
|
|
31869
|
-
if (objectRestNames.length === 0)
|
|
31870
|
-
return true;
|
|
31871
|
-
return !restNamesMisused(loop, objectRestNames);
|
|
31872
32106
|
}
|
|
31873
|
-
|
|
31874
|
-
|
|
31875
|
-
|
|
31876
|
-
|
|
31877
|
-
let misused = false;
|
|
31878
|
-
const check = (s) => {
|
|
31879
|
-
if (!s || misused)
|
|
31880
|
-
return;
|
|
31881
|
-
for (const re of valueUse) {
|
|
31882
|
-
if (re.test(s)) {
|
|
31883
|
-
misused = true;
|
|
31884
|
-
return;
|
|
31885
|
-
}
|
|
31886
|
-
}
|
|
31887
|
-
};
|
|
31888
|
-
const attr = (v, isIntrinsicElementAttrs) => {
|
|
31889
|
-
if (v.kind === "spread" && isIntrinsicElementAttrs && nameSet.has(v.expr.trim())) {
|
|
31890
|
-
return;
|
|
31891
|
-
}
|
|
31892
|
-
if (v.kind === "expression" || v.kind === "spread") {
|
|
31893
|
-
check(v.expr);
|
|
31894
|
-
check(v.templateExpr);
|
|
31895
|
-
} else if (v.kind === "template") {
|
|
31896
|
-
v.parts.forEach(part);
|
|
31897
|
-
}
|
|
31898
|
-
};
|
|
31899
|
-
const part = (p) => {
|
|
31900
|
-
if (p.type === "ternary") {
|
|
31901
|
-
check(p.condition);
|
|
31902
|
-
check(p.templateCondition);
|
|
31903
|
-
check(p.whenTrue);
|
|
31904
|
-
check(p.whenFalse);
|
|
31905
|
-
} else if (p.type === "lookup") {
|
|
31906
|
-
check(p.key);
|
|
31907
|
-
check(p.templateKey);
|
|
31908
|
-
}
|
|
31909
|
-
};
|
|
31910
|
-
const visitLoop = (l) => {
|
|
31911
|
-
if (misused)
|
|
31912
|
-
return;
|
|
31913
|
-
check(l.array);
|
|
31914
|
-
check(l.templateArray);
|
|
31915
|
-
check(l.key);
|
|
31916
|
-
if (l.preamble) {
|
|
31917
|
-
check(preambleAnalysisText(l.preamble));
|
|
31918
|
-
check(preambleAnalysisTemplateText(l.preamble));
|
|
31919
|
-
}
|
|
31920
|
-
if (l.flatMapCallback) {
|
|
31921
|
-
check(preambleAnalysisText(l.flatMapCallback));
|
|
31922
|
-
for (const seg of l.flatMapCallback.segments) {
|
|
31923
|
-
if (seg.kind === "jsx")
|
|
31924
|
-
visit3(seg.ir);
|
|
31925
|
-
}
|
|
31926
|
-
}
|
|
31927
|
-
l.children.forEach(visit3);
|
|
31928
|
-
};
|
|
31929
|
-
const visit3 = (node) => {
|
|
31930
|
-
if (misused)
|
|
31931
|
-
return;
|
|
31932
|
-
switch (node.type) {
|
|
31933
|
-
case "expression":
|
|
31934
|
-
check(node.expr);
|
|
31935
|
-
check(node.templateExpr);
|
|
31936
|
-
break;
|
|
31937
|
-
case "conditional":
|
|
31938
|
-
check(node.condition);
|
|
31939
|
-
check(node.templateCondition);
|
|
31940
|
-
visit3(node.whenTrue);
|
|
31941
|
-
visit3(node.whenFalse);
|
|
31942
|
-
break;
|
|
31943
|
-
case "if-statement":
|
|
31944
|
-
check(node.condition);
|
|
31945
|
-
check(node.templateCondition);
|
|
31946
|
-
for (const sv of node.scopeVariables) {
|
|
31947
|
-
check(sv.initializer);
|
|
31948
|
-
check(sv.templateInitializer);
|
|
31949
|
-
}
|
|
31950
|
-
visit3(node.consequent);
|
|
31951
|
-
if (node.alternate)
|
|
31952
|
-
visit3(node.alternate);
|
|
31953
|
-
break;
|
|
31954
|
-
case "element":
|
|
31955
|
-
node.attrs.forEach((a) => attr(a.value, true));
|
|
31956
|
-
node.events.forEach((e) => check(e.handler));
|
|
31957
|
-
node.children.forEach(visit3);
|
|
31958
|
-
break;
|
|
31959
|
-
case "component":
|
|
31960
|
-
node.props.forEach((p) => attr(p.value, false));
|
|
31961
|
-
node.children.forEach(visit3);
|
|
31962
|
-
break;
|
|
31963
|
-
case "provider":
|
|
31964
|
-
attr(node.valueProp.value, false);
|
|
31965
|
-
node.children.forEach(visit3);
|
|
31966
|
-
break;
|
|
31967
|
-
case "fragment":
|
|
31968
|
-
node.children.forEach(visit3);
|
|
31969
|
-
break;
|
|
31970
|
-
case "async":
|
|
31971
|
-
visit3(node.fallback);
|
|
31972
|
-
node.children.forEach(visit3);
|
|
31973
|
-
break;
|
|
31974
|
-
case "loop":
|
|
31975
|
-
visitLoop(node);
|
|
31976
|
-
break;
|
|
31977
|
-
case "text":
|
|
31978
|
-
case "slot":
|
|
31979
|
-
break;
|
|
31980
|
-
}
|
|
32107
|
+
function prefixedArrayMethodSpelling(prefix, undefinedLiteral) {
|
|
32108
|
+
return {
|
|
32109
|
+
call: (helper, operands) => `${prefix}${helper}(${operands.join(", ")})`,
|
|
32110
|
+
undefinedLiteral
|
|
31981
32111
|
};
|
|
31982
|
-
visitLoop(loop);
|
|
31983
|
-
return misused;
|
|
31984
32112
|
}
|
|
31985
|
-
|
|
31986
|
-
|
|
32113
|
+
// src/adapters/component-props.ts
|
|
32114
|
+
import { resolveJsxChildrenProp } from "@barefootjs/shared";
|
|
32115
|
+
function propsSpreadParam(param, earlier) {
|
|
32116
|
+
if (param.optional === false)
|
|
32117
|
+
return "entry";
|
|
32118
|
+
return earlier.spread || earlier.keys.has(param.name) ? "present" : "entry";
|
|
31987
32119
|
}
|
|
31988
|
-
|
|
31989
|
-
|
|
31990
|
-
|
|
31991
|
-
|
|
31992
|
-
|
|
31993
|
-
|
|
31994
|
-
|
|
31995
|
-
|
|
31996
|
-
|
|
31997
|
-
|
|
31998
|
-
|
|
31999
|
-
|
|
32000
|
-
|
|
32001
|
-
|
|
32002
|
-
|
|
32003
|
-
|
|
32004
|
-
out += String(resolved.value);
|
|
32005
|
-
}
|
|
32006
|
-
return { value: out };
|
|
32007
|
-
}
|
|
32008
|
-
case "array-literal": {
|
|
32009
|
-
const values = [];
|
|
32010
|
-
for (const element of expr.elements) {
|
|
32011
|
-
const resolved = evaluateStaticLiteral(element, bindings);
|
|
32012
|
-
if (!resolved)
|
|
32013
|
-
return null;
|
|
32014
|
-
values.push(resolved.value);
|
|
32015
|
-
}
|
|
32016
|
-
return { value: values };
|
|
32120
|
+
function componentPropKey(entry) {
|
|
32121
|
+
if (entry.kind === "slot-id")
|
|
32122
|
+
return "_bf_slot";
|
|
32123
|
+
if (entry.kind === "children")
|
|
32124
|
+
return "children";
|
|
32125
|
+
return entry.name;
|
|
32126
|
+
}
|
|
32127
|
+
function planComponentProps(comp, options) {
|
|
32128
|
+
const segments = [{ kind: "entries", entries: [] }];
|
|
32129
|
+
const earlier = { keys: new Set, spread: false };
|
|
32130
|
+
const push = (entry) => {
|
|
32131
|
+
earlier.keys.add(componentPropKey(entry));
|
|
32132
|
+
const last = segments[segments.length - 1];
|
|
32133
|
+
if (last.kind !== "entries") {
|
|
32134
|
+
segments.push({ kind: "entries", entries: [entry] });
|
|
32135
|
+
return;
|
|
32017
32136
|
}
|
|
32018
|
-
|
|
32019
|
-
|
|
32020
|
-
|
|
32021
|
-
|
|
32022
|
-
|
|
32023
|
-
|
|
32024
|
-
|
|
32025
|
-
|
|
32026
|
-
|
|
32027
|
-
|
|
32028
|
-
|
|
32029
|
-
|
|
32030
|
-
|
|
32031
|
-
}
|
|
32032
|
-
const resolved = evaluateStaticLiteral(prop.value, bindings);
|
|
32033
|
-
if (!resolved)
|
|
32034
|
-
return null;
|
|
32035
|
-
out[prop.key] = resolved.value;
|
|
32137
|
+
const at = last.entries.findIndex((e) => componentPropKey(e) === componentPropKey(entry));
|
|
32138
|
+
if (at === -1)
|
|
32139
|
+
last.entries.push(entry);
|
|
32140
|
+
else
|
|
32141
|
+
last.entries[at] = entry;
|
|
32142
|
+
};
|
|
32143
|
+
const pushPropsSpread = () => {
|
|
32144
|
+
const before = { keys: new Set(earlier.keys), spread: earlier.spread };
|
|
32145
|
+
for (const param of options.propsParams) {
|
|
32146
|
+
if (propsSpreadParam(param, before) === "entry") {
|
|
32147
|
+
push({ kind: "props-param", name: param.name });
|
|
32148
|
+
} else {
|
|
32149
|
+
earlier.keys.add(param.name);
|
|
32150
|
+
segments.push({ kind: "present-param", name: param.name });
|
|
32036
32151
|
}
|
|
32037
|
-
return { value: out };
|
|
32038
|
-
}
|
|
32039
|
-
case "unary": {
|
|
32040
|
-
const resolved = evaluateStaticLiteral(expr.argument, bindings);
|
|
32041
|
-
if (!resolved)
|
|
32042
|
-
return null;
|
|
32043
|
-
if (expr.op === "-")
|
|
32044
|
-
return typeof resolved.value === "number" ? { value: -resolved.value } : null;
|
|
32045
|
-
if (expr.op === "+")
|
|
32046
|
-
return typeof resolved.value === "number" ? { value: +resolved.value } : null;
|
|
32047
|
-
if (expr.op === "!")
|
|
32048
|
-
return { value: !resolved.value };
|
|
32049
|
-
return null;
|
|
32050
|
-
}
|
|
32051
|
-
case "identifier":
|
|
32052
|
-
return bindings?.has(expr.name) ? { value: bindings.get(expr.name) } : null;
|
|
32053
|
-
case "member": {
|
|
32054
|
-
const base = evaluateStaticLiteral(expr.object, bindings);
|
|
32055
|
-
if (!base || base.value === null || typeof base.value !== "object")
|
|
32056
|
-
return null;
|
|
32057
|
-
return { value: base.value[expr.property] };
|
|
32058
32152
|
}
|
|
32059
|
-
|
|
32060
|
-
|
|
32061
|
-
|
|
32062
|
-
|
|
32063
|
-
|
|
32064
|
-
|
|
32153
|
+
};
|
|
32154
|
+
for (const p of comp.props) {
|
|
32155
|
+
if ((/^on[A-Z]/.test(p.name) || p.name === "ref") && p.value.kind === "expression")
|
|
32156
|
+
continue;
|
|
32157
|
+
if (p.value.kind === "jsx-children") {
|
|
32158
|
+
if (p.name !== "children")
|
|
32159
|
+
push({ kind: "named-slot", name: p.name, children: p.value.children });
|
|
32160
|
+
} else if (p.value.kind === "spread") {
|
|
32161
|
+
if (options.propsObjectName !== null && options.propsObjectName === p.value.expr.trim()) {
|
|
32162
|
+
pushPropsSpread();
|
|
32163
|
+
} else {
|
|
32164
|
+
earlier.spread = true;
|
|
32165
|
+
segments.push({ kind: "spread", value: p.value });
|
|
32166
|
+
}
|
|
32167
|
+
} else {
|
|
32168
|
+
push({ kind: "value", name: p.name, value: p.value });
|
|
32065
32169
|
}
|
|
32066
|
-
default:
|
|
32067
|
-
return null;
|
|
32068
32170
|
}
|
|
32171
|
+
if (derivesScopeFromSlot(comp))
|
|
32172
|
+
push({ kind: "slot-id", slotId: comp.slotId });
|
|
32173
|
+
const children = comp.children.length > 0 ? comp.children : resolveJsxChildrenProp(comp.props);
|
|
32174
|
+
if (children.length > 0)
|
|
32175
|
+
push({ kind: "children", children });
|
|
32176
|
+
return segments;
|
|
32069
32177
|
}
|
|
32070
|
-
function
|
|
32071
|
-
return
|
|
32178
|
+
function spellComponentProps(segments, spelling) {
|
|
32179
|
+
return segments.map((segment) => {
|
|
32180
|
+
if (segment.kind === "spread")
|
|
32181
|
+
return { kind: "spread", expr: spelling.spread(segment.value) };
|
|
32182
|
+
if (segment.kind === "present-param")
|
|
32183
|
+
return { kind: "spread", expr: spelling.presentParam(segment.name) };
|
|
32184
|
+
const parts = [];
|
|
32185
|
+
for (const entry of segment.entries) {
|
|
32186
|
+
const part = spelling.entry(entry);
|
|
32187
|
+
if (part)
|
|
32188
|
+
parts.push(part);
|
|
32189
|
+
}
|
|
32190
|
+
return { kind: "entries", parts };
|
|
32191
|
+
});
|
|
32072
32192
|
}
|
|
32073
|
-
function
|
|
32074
|
-
|
|
32075
|
-
|
|
32076
|
-
|
|
32077
|
-
|
|
32078
|
-
|
|
32079
|
-
|
|
32080
|
-
|
|
32081
|
-
|
|
32193
|
+
function resolveComponentPropKeys(segments) {
|
|
32194
|
+
const byKey = new Map;
|
|
32195
|
+
const at = (key) => {
|
|
32196
|
+
let resolved = byKey.get(key);
|
|
32197
|
+
if (!resolved) {
|
|
32198
|
+
resolved = { key, base: null, presentParams: [] };
|
|
32199
|
+
byKey.set(key, resolved);
|
|
32200
|
+
}
|
|
32201
|
+
return resolved;
|
|
32202
|
+
};
|
|
32203
|
+
for (const segment of segments) {
|
|
32204
|
+
if (segment.kind === "spread")
|
|
32082
32205
|
return null;
|
|
32083
|
-
|
|
32206
|
+
if (segment.kind === "present-param") {
|
|
32207
|
+
at(segment.name).presentParams.push(segment.name);
|
|
32208
|
+
continue;
|
|
32209
|
+
}
|
|
32210
|
+
for (const entry of segment.entries) {
|
|
32211
|
+
const resolved = at(componentPropKey(entry));
|
|
32212
|
+
resolved.base = entry;
|
|
32213
|
+
resolved.presentParams = [];
|
|
32214
|
+
}
|
|
32084
32215
|
}
|
|
32085
|
-
|
|
32086
|
-
if (!resolved || !Array.isArray(resolved.value))
|
|
32087
|
-
return null;
|
|
32088
|
-
return resolved.value;
|
|
32216
|
+
return [...byKey.values()];
|
|
32089
32217
|
}
|
|
32090
|
-
|
|
32091
|
-
|
|
32092
|
-
function spellDestructureLocals(plan, item, spelling) {
|
|
32093
|
-
return plan.destructureLocals.map(({ name, value }) => {
|
|
32094
|
-
const parent = spelling.accessor(item, value.segments);
|
|
32095
|
-
if (value.kind === "slice")
|
|
32096
|
-
return { name, value: spelling.slice(parent, value.from) };
|
|
32097
|
-
if (value.kind === "omit")
|
|
32098
|
-
return { name, value: spelling.omit(parent, value.exclude) };
|
|
32099
|
-
return { name, value: parent };
|
|
32100
|
-
});
|
|
32218
|
+
function isEmptyComponentProps(segments) {
|
|
32219
|
+
return segments.every((segment) => segment.kind === "entries" && segment.parts.length === 0);
|
|
32101
32220
|
}
|
|
32102
|
-
function
|
|
32103
|
-
|
|
32104
|
-
|
|
32105
|
-
if (sort.kind === "eval")
|
|
32106
|
-
return emitCallbackEval(sort, recv, spelling.emit, spelling.eval);
|
|
32107
|
-
if (sort.kind === "structured-sort")
|
|
32108
|
-
return spelling.structured(recv, sort.comparator);
|
|
32109
|
-
spelling.refuse(sort.message, sort.suggestion);
|
|
32110
|
-
return recv;
|
|
32221
|
+
function childTemplateName(componentName, importAliases) {
|
|
32222
|
+
const declaredName = importAliases.get(componentName) ?? componentName;
|
|
32223
|
+
return declaredName.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
|
|
32111
32224
|
}
|
|
32112
|
-
|
|
32113
|
-
|
|
32114
|
-
|
|
32115
|
-
|
|
32225
|
+
// src/adapters/attr-plan.ts
|
|
32226
|
+
var IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
32227
|
+
function planAttrExpression(value, name, ctx) {
|
|
32228
|
+
const booleanAttr = isBooleanAttr(name);
|
|
32229
|
+
if (!booleanAttr && !value.presenceOrUndefined) {
|
|
32230
|
+
const nullable = nullableBareRead(value, ctx);
|
|
32231
|
+
if (nullable !== null)
|
|
32232
|
+
return { kind: "omit-nullable", boolStr: ctx.boolStr(value.expr, name), restKey: nullable.restKey };
|
|
32233
|
+
}
|
|
32234
|
+
if (booleanAttr)
|
|
32235
|
+
return { kind: "boolean-attr" };
|
|
32236
|
+
if (value.presenceOrUndefined)
|
|
32237
|
+
return { kind: "presence", boolStr: ctx.boolStr(value.expr, name) };
|
|
32238
|
+
const ternary = parseUndefinedAlternateTernary(value.expr);
|
|
32239
|
+
if (ternary)
|
|
32240
|
+
return { kind: "undefined-alternate", ternary };
|
|
32241
|
+
const boolStr = ctx.boolStr(value.expr, name);
|
|
32242
|
+
if (attrValueMayBeNullish(value.parsed, ctx.nullishAttrCtx, (n) => ctx.isLoopBound(n)))
|
|
32243
|
+
return { kind: "omit-nil", boolStr };
|
|
32244
|
+
return { kind: "plain", boolStr };
|
|
32116
32245
|
}
|
|
32117
|
-
function
|
|
32118
|
-
|
|
32119
|
-
|
|
32120
|
-
|
|
32121
|
-
|
|
32246
|
+
function nullableBareRead(value, ctx) {
|
|
32247
|
+
const bare = value.expr.trim();
|
|
32248
|
+
const restKey = ctx.restPropsName !== null && bare.startsWith(`${ctx.restPropsName}.`);
|
|
32249
|
+
let normalized = bare;
|
|
32250
|
+
if (ctx.propsObjectName && bare.startsWith(`${ctx.propsObjectName}.`))
|
|
32251
|
+
normalized = bare.slice(ctx.propsObjectName.length + 1);
|
|
32252
|
+
else if (restKey)
|
|
32253
|
+
normalized = bare.slice(ctx.restPropsName.length + 1);
|
|
32254
|
+
const prop = IDENTIFIER.test(normalized) && ctx.nullableOptionalProps.has(normalized) && !ctx.isLoopBound(normalized);
|
|
32255
|
+
const signal = nullableSignalAttrGetter(value.parsed, ctx.nullableSignalGetters);
|
|
32256
|
+
if (prop || signal !== null && !ctx.isLoopBound(signal))
|
|
32257
|
+
return { restKey };
|
|
32258
|
+
return null;
|
|
32122
32259
|
}
|
|
32123
|
-
function
|
|
32124
|
-
const
|
|
32125
|
-
if (
|
|
32260
|
+
function parseUndefinedAlternateTernary(expr) {
|
|
32261
|
+
const parsed = parseExpression(expr.trim());
|
|
32262
|
+
if (parsed?.kind !== "conditional")
|
|
32263
|
+
return null;
|
|
32264
|
+
const alt = parsed.alternate;
|
|
32265
|
+
const isUndef = alt.kind === "identifier" && (alt.name === "undefined" || alt.name === "null") || alt.kind === "literal" && (alt.value === null || alt.value === undefined);
|
|
32266
|
+
if (!isUndef)
|
|
32126
32267
|
return null;
|
|
32127
|
-
if (!filter.predicate)
|
|
32128
|
-
return { kind: "refuse", ...missingFilterPredicateRefusal(filter.raw, adapterName) };
|
|
32129
|
-
const captureRenames = new Map(captureAliases.map(({ name, alias }) => [name, alias]));
|
|
32130
|
-
const rowRenames = new Map(captureRenames);
|
|
32131
|
-
if (filter.param !== loop.param)
|
|
32132
|
-
rowRenames.set(filter.param, loop.param);
|
|
32133
|
-
return {
|
|
32134
|
-
kind: "predicate",
|
|
32135
|
-
param: filter.param,
|
|
32136
|
-
predicate: filter.predicate,
|
|
32137
|
-
captured: renameFreeIdentifiers(filter.predicate, captureRenames),
|
|
32138
|
-
onRow: renameFreeIdentifiers(filter.predicate, rowRenames),
|
|
32139
|
-
aliases: new Map(captureAliases.map(({ name, alias }) => [alias, name]))
|
|
32140
|
-
};
|
|
32141
|
-
}
|
|
32142
|
-
function planLoop(loop, ctx) {
|
|
32143
|
-
const staticItems = resolveStaticLoopSource(loop.arrayParsed, ctx.localConstants, {
|
|
32144
|
-
isNameShadowed: ctx.scope.asShadowPredicate()
|
|
32145
|
-
});
|
|
32146
|
-
const staticSource = staticItems !== null ? ctx.spellStatic(staticItems) : null;
|
|
32147
|
-
const destructure = destructureKind(loop);
|
|
32148
|
-
const captureAliases = filterCaptureCollisions(loop).map((name) => ({ name, alias: `__bf_cap_${loop.markerId}_${name}` }));
|
|
32149
32268
|
return {
|
|
32150
|
-
|
|
32151
|
-
|
|
32152
|
-
|
|
32153
|
-
|
|
32154
|
-
captureAliases,
|
|
32155
|
-
filter: filterPlan(loop, captureAliases, ctx.callbackLowering.adapterName),
|
|
32156
|
-
itemVar: loop.iterationShape === "keys" || destructure === "lowerable" ? "__bf_item" : loop.param,
|
|
32157
|
-
indexLocal: indexLocal(loop),
|
|
32158
|
-
destructureLocals: destructure === "lowerable" ? destructureLocals(loop) : []
|
|
32269
|
+
condition: exprToString(parsed.test),
|
|
32270
|
+
consequent: exprToString(parsed.consequent),
|
|
32271
|
+
testParsed: parsed.test,
|
|
32272
|
+
consequentParsed: parsed.consequent
|
|
32159
32273
|
};
|
|
32160
32274
|
}
|
|
32161
|
-
function
|
|
32162
|
-
|
|
32163
|
-
|
|
32164
|
-
|
|
32165
|
-
}
|
|
32166
|
-
|
|
32167
|
-
|
|
32168
|
-
|
|
32169
|
-
|
|
32170
|
-
|
|
32171
|
-
if (b.rest?.kind === "object")
|
|
32172
|
-
return { name: b.name, value: { kind: "omit", segments, exclude: b.rest.exclude.map((k) => k.key) } };
|
|
32173
|
-
return { name: b.name, value: { kind: "path", segments } };
|
|
32174
|
-
});
|
|
32175
|
-
}
|
|
32176
|
-
function destructureKind(loop) {
|
|
32177
|
-
if (!loop.paramBindings || loop.paramBindings.length === 0)
|
|
32178
|
-
return "none";
|
|
32179
|
-
return isLowerableLoopDestructure(loop) ? "lowerable" : "unlowerable";
|
|
32275
|
+
function planSpreadAttr(value, ctx) {
|
|
32276
|
+
const trimmed = value.expr.trim();
|
|
32277
|
+
if (ctx.propsObjectName && ctx.propsObjectName === trimmed) {
|
|
32278
|
+
return { kind: "props-object", params: ctx.propsParams.map((p) => p.name) };
|
|
32279
|
+
}
|
|
32280
|
+
const candidates = [value.parsed];
|
|
32281
|
+
const init = localConstInitializer(trimmed, ctx);
|
|
32282
|
+
if (init !== null)
|
|
32283
|
+
candidates.push(parseExpression(init));
|
|
32284
|
+
return { kind: "value", candidates };
|
|
32180
32285
|
}
|
|
32181
|
-
function
|
|
32182
|
-
|
|
32183
|
-
if (source?.kind !== "identifier")
|
|
32184
|
-
return null;
|
|
32185
|
-
const name = source.name;
|
|
32186
|
-
if (ctx.scope.isBound(name))
|
|
32286
|
+
function localConstInitializer(name, ctx) {
|
|
32287
|
+
if (!IDENTIFIER.test(name) || ctx.isBound(name))
|
|
32187
32288
|
return null;
|
|
32188
|
-
const
|
|
32189
|
-
return
|
|
32289
|
+
const init = ctx.localConstants.find((c) => c.name === name && !c.isModule)?.value?.trim();
|
|
32290
|
+
return init !== undefined && !IDENTIFIER.test(init) ? init : null;
|
|
32190
32291
|
}
|
|
32191
32292
|
// src/query-href-lowering.ts
|
|
32192
32293
|
function matchQueryHrefCall(callee, args, localNames) {
|
|
@@ -34116,6 +34217,8 @@ function attrValueToString2(value) {
|
|
|
34116
34217
|
return value.expr;
|
|
34117
34218
|
case "template":
|
|
34118
34219
|
return value.parts.map((p) => {
|
|
34220
|
+
if (p.type === "expression")
|
|
34221
|
+
return p.expr;
|
|
34119
34222
|
if (p.type === "ternary")
|
|
34120
34223
|
return `${p.condition} ${p.whenTrue} ${p.whenFalse}`;
|
|
34121
34224
|
if (p.type === "lookup")
|
|
@@ -35449,8 +35552,6 @@ function profileToJSON(profile) {
|
|
|
35449
35552
|
// src/index.ts
|
|
35450
35553
|
registerBuiltinLoweringPlugins();
|
|
35451
35554
|
export {
|
|
35452
|
-
unsupportedAttrExpressionError,
|
|
35453
|
-
unsupportedAttrExpression,
|
|
35454
35555
|
unloweredCallRefusal,
|
|
35455
35556
|
unboundCallbackParamReason,
|
|
35456
35557
|
unboundCallbackParamRead,
|
|
@@ -35471,6 +35572,7 @@ export {
|
|
|
35471
35572
|
serializeParsedExpr,
|
|
35472
35573
|
searchParamsLocalNames,
|
|
35473
35574
|
scanComponentFile,
|
|
35575
|
+
savedLoopBindings,
|
|
35474
35576
|
rootPropReadName,
|
|
35475
35577
|
rootPropAliasesForLoop,
|
|
35476
35578
|
rootPropAliasNames,
|
|
@@ -35526,6 +35628,7 @@ export {
|
|
|
35526
35628
|
lowerSortComparator,
|
|
35527
35629
|
lowerCallbackMethod,
|
|
35528
35630
|
lowerArrayMethod,
|
|
35631
|
+
loopHeaderTargets,
|
|
35529
35632
|
lookupStaticRecordLiteral,
|
|
35530
35633
|
lookupLiteralConst,
|
|
35531
35634
|
literalMemberIndex,
|