@barefootjs/vite 0.33.1 → 0.33.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/discover.d.ts +78 -6
- package/dist/discover.d.ts.map +1 -1
- package/dist/index.js +846 -410
- package/package.json +6 -6
- package/src/__tests__/discover.test.ts +140 -12
- package/src/__tests__/e2e-vite-build.test.ts +45 -1
- package/src/__tests__/e2e-vite-dev.test.ts +20 -0
- package/src/__tests__/plugin.test.ts +29 -4
- package/src/discover.ts +159 -27
- package/src/plugin.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { mkdir as mkdir2, readFile as readFile2, rm, writeFile as writeFile2 } f
|
|
|
3
3
|
import { relative as relative2, resolve as resolve7, sep as sep3 } from "node:path";
|
|
4
4
|
|
|
5
5
|
// ../jsx/src/compiler.ts
|
|
6
|
-
import
|
|
6
|
+
import ts25 from "typescript";
|
|
7
7
|
|
|
8
8
|
// ../jsx/src/analyzer.ts
|
|
9
9
|
import ts9 from "typescript";
|
|
@@ -1885,6 +1885,9 @@ function loopEndMarker(markerId) {
|
|
|
1885
1885
|
}
|
|
1886
1886
|
var BF_KEY = "data-key";
|
|
1887
1887
|
var BF_KEY_PREFIX = "data-key-";
|
|
1888
|
+
function keyAttrName(loopDepth) {
|
|
1889
|
+
return loopDepth > 0 ? `${BF_KEY_PREFIX}${loopDepth}` : BF_KEY;
|
|
1890
|
+
}
|
|
1888
1891
|
var BF_PLACEHOLDER = "data-bf-ph";
|
|
1889
1892
|
var BF_PARENT_SCOPE_PLACEHOLDER = "__BF_PARENT_SCOPE__";
|
|
1890
1893
|
// ../shared/src/dom-prop.ts
|
|
@@ -2058,6 +2061,29 @@ var SVG_XML_CAMEL_ATTRS = new Set([
|
|
|
2058
2061
|
"yChannelSelector",
|
|
2059
2062
|
"zoomAndPan"
|
|
2060
2063
|
]);
|
|
2064
|
+
function isEventProp(key) {
|
|
2065
|
+
return key.length > 2 && key[0] === "o" && key[1] === "n" && key[2] >= "A" && key[2] <= "Z";
|
|
2066
|
+
}
|
|
2067
|
+
function classifyDOMProp(key) {
|
|
2068
|
+
if (key === "children")
|
|
2069
|
+
return { kind: "skip", attrName: key };
|
|
2070
|
+
if (key === "ref")
|
|
2071
|
+
return { kind: "ref", attrName: key };
|
|
2072
|
+
if (key === "dangerouslySetInnerHTML")
|
|
2073
|
+
return { kind: "innerHTML", attrName: key };
|
|
2074
|
+
if (isEventProp(key))
|
|
2075
|
+
return { kind: "event", attrName: key };
|
|
2076
|
+
const attrName = toHTMLAttrNameRuntime(key);
|
|
2077
|
+
if (attrName === "style")
|
|
2078
|
+
return { kind: "style", attrName };
|
|
2079
|
+
if (attrName === "value")
|
|
2080
|
+
return { kind: "property", attrName };
|
|
2081
|
+
if (attrName === "checked")
|
|
2082
|
+
return { kind: "property", attrName };
|
|
2083
|
+
if (BOOLEAN_ATTRS.has(attrName.toLowerCase()))
|
|
2084
|
+
return { kind: "boolean", attrName };
|
|
2085
|
+
return { kind: "attr", attrName };
|
|
2086
|
+
}
|
|
2061
2087
|
function toHTMLAttrName(key) {
|
|
2062
2088
|
if (key === "className")
|
|
2063
2089
|
return "class";
|
|
@@ -2071,6 +2097,24 @@ function toHTMLAttrName(key) {
|
|
|
2071
2097
|
return svgKebab;
|
|
2072
2098
|
return key;
|
|
2073
2099
|
}
|
|
2100
|
+
function toHTMLAttrNameRuntime(key) {
|
|
2101
|
+
if (key === "className")
|
|
2102
|
+
return "class";
|
|
2103
|
+
if (key === "htmlFor")
|
|
2104
|
+
return "for";
|
|
2105
|
+
const htmlAlias = HTML_CAMEL_ALIASES[key];
|
|
2106
|
+
if (htmlAlias !== undefined)
|
|
2107
|
+
return htmlAlias;
|
|
2108
|
+
const svgKebab = SVG_CAMEL_TO_KEBAB[key];
|
|
2109
|
+
if (svgKebab !== undefined)
|
|
2110
|
+
return svgKebab;
|
|
2111
|
+
if (SVG_XML_CAMEL_ATTRS.has(key))
|
|
2112
|
+
return key;
|
|
2113
|
+
if (key.startsWith("data") || key.startsWith("aria")) {
|
|
2114
|
+
return key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
2115
|
+
}
|
|
2116
|
+
return key;
|
|
2117
|
+
}
|
|
2074
2118
|
function isBooleanAttr(name) {
|
|
2075
2119
|
return BOOLEAN_ATTRS.has(name.toLowerCase());
|
|
2076
2120
|
}
|
|
@@ -2146,8 +2190,12 @@ function escapeHtml(text) {
|
|
|
2146
2190
|
}
|
|
2147
2191
|
// ../jsx/src/ir-to-client-js/utils.ts
|
|
2148
2192
|
var PROPS_PARAM = "_p";
|
|
2149
|
-
|
|
2150
|
-
|
|
2193
|
+
var keyAttrName2 = keyAttrName;
|
|
2194
|
+
function mapArrayKeyArgs(bfIdArg, keyed, loopDepth) {
|
|
2195
|
+
if (!keyed || loopDepth <= 0)
|
|
2196
|
+
return bfIdArg;
|
|
2197
|
+
const bfIdSlot = bfIdArg || ", undefined";
|
|
2198
|
+
return `${bfIdSlot}, ${JSON.stringify(keyAttrName2(loopDepth))}`;
|
|
2151
2199
|
}
|
|
2152
2200
|
function varSlotId(slotId) {
|
|
2153
2201
|
return slotId.startsWith("^") ? slotId.slice(1) : slotId;
|
|
@@ -3130,6 +3178,14 @@ function escapeAttrValueExpr(valExpr) {
|
|
|
3130
3178
|
function escapeTextSlotExpr(innerExpr, isMarkup = false) {
|
|
3131
3179
|
return `${isMarkup ? "escapeTextOrMarkup" : "escapeText"}(${innerExpr})`;
|
|
3132
3180
|
}
|
|
3181
|
+
function isChildrenPassthroughExpr(expr) {
|
|
3182
|
+
return /^([A-Za-z_$][\w$]*\.)?children$/.test(expr.trim());
|
|
3183
|
+
}
|
|
3184
|
+
function bareSpliceExpr(node, valueExpr) {
|
|
3185
|
+
const resolved = valueExpr.trim().replace(/^\(+|\)+$/g, "");
|
|
3186
|
+
const isChildren = isChildrenPassthroughExpr(node.expr) || isChildrenPassthroughExpr(resolved);
|
|
3187
|
+
return !node.joinArrayChild && isChildren ? `markupOrEmpty(${valueExpr})` : valueExpr;
|
|
3188
|
+
}
|
|
3133
3189
|
function dangerouslyHtmlChildren(attrs, toExpr) {
|
|
3134
3190
|
const attr = attrs.find((a) => a.name === "dangerouslySetInnerHTML");
|
|
3135
3191
|
if (!attr || attr.value.kind !== "expression")
|
|
@@ -3337,7 +3393,7 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
|
|
|
3337
3393
|
case "element": {
|
|
3338
3394
|
const mergeCtx = {
|
|
3339
3395
|
isFilteredSpread: (v) => !!restSpreadNames?.has(v.expr),
|
|
3340
|
-
honorClientOnly:
|
|
3396
|
+
honorClientOnly: true
|
|
3341
3397
|
};
|
|
3342
3398
|
const useMerge = shouldUseSpreadAttrsMerge(node.attrs, mergeCtx);
|
|
3343
3399
|
const firstMergeableIdx = useMerge ? node.attrs.findIndex((a) => isMergeableAttr(a, mergeCtx)) : -1;
|
|
@@ -3348,10 +3404,12 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
|
|
|
3348
3404
|
templateExprFor: (v) => wrapExpr(attrValueToString(v) ?? "")
|
|
3349
3405
|
}) : null;
|
|
3350
3406
|
const attrParts = node.attrs.map((a, idx) => {
|
|
3407
|
+
if (a.clientOnly)
|
|
3408
|
+
return "";
|
|
3351
3409
|
if (useMerge && isMergeableAttr(a, mergeCtx)) {
|
|
3352
3410
|
return idx === firstMergeableIdx ? mergeCall : "";
|
|
3353
3411
|
}
|
|
3354
|
-
const attrName = a.name === "..." ? "..." : a.name === "key" ?
|
|
3412
|
+
const attrName = a.name === "..." ? "..." : a.name === "key" ? keyAttrName2(loopDepth) : toHTMLAttrName(a.name);
|
|
3355
3413
|
return renderTemplateAttrPart(a, attrName, wrapExpr, restSpreadNames);
|
|
3356
3414
|
}).filter(Boolean);
|
|
3357
3415
|
const hoistedScopeAttr = maybeHoistedScopeAttr(inHoistedChildren, node);
|
|
@@ -3373,17 +3431,18 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
|
|
|
3373
3431
|
case "expression": {
|
|
3374
3432
|
if (node.expr === "null" || node.expr === "undefined")
|
|
3375
3433
|
return "";
|
|
3434
|
+
const escapeForClient = (e) => node.escapeInClientTemplate ? `escapeText(${e})` : e;
|
|
3376
3435
|
if (node.markerless) {
|
|
3377
|
-
const bare = wrapInterpolation(wrapExpr(node.expr));
|
|
3436
|
+
const bare = escapeForClient(wrapInterpolation(wrapExpr(node.expr)));
|
|
3378
3437
|
return `\${${bare}}`;
|
|
3379
3438
|
}
|
|
3380
|
-
const inner = wrapInterpolation(wrapExpr(node.expr));
|
|
3439
|
+
const inner = escapeForClient(wrapInterpolation(wrapExpr(node.expr)));
|
|
3381
3440
|
const valueExpr = node.joinArrayChild ? `Array.isArray(${inner}) ? ${inner}.join('') : (${inner} ?? '')` : inner;
|
|
3382
3441
|
if (node.slotId) {
|
|
3383
3442
|
const slotted = branchSlotsVar || node.joinArrayChild ? valueExpr : escapeTextSlotExpr(valueExpr);
|
|
3384
3443
|
return `<!--bf:${node.slotId}-->\${${slotted}}<!--/-->`;
|
|
3385
3444
|
}
|
|
3386
|
-
return `\${${valueExpr}}`;
|
|
3445
|
+
return `\${${bareSpliceExpr(node, valueExpr)}}`;
|
|
3387
3446
|
}
|
|
3388
3447
|
case "conditional": {
|
|
3389
3448
|
const trueBranch = recurse(node.whenTrue);
|
|
@@ -3476,7 +3535,7 @@ function buildLoopSkeletonTemplate(node, safe) {
|
|
|
3476
3535
|
if (a.name === "dangerouslySetInnerHTML")
|
|
3477
3536
|
return null;
|
|
3478
3537
|
if (a.name === "key") {
|
|
3479
|
-
attrParts.push(`${
|
|
3538
|
+
attrParts.push(`${keyAttrName2(0)}=""`);
|
|
3480
3539
|
continue;
|
|
3481
3540
|
}
|
|
3482
3541
|
const v = a.value;
|
|
@@ -3682,7 +3741,9 @@ function irToPlaceholderTemplate(node, restSpreadNames, loopDepth = 0, loopParam
|
|
|
3682
3741
|
switch (node.type) {
|
|
3683
3742
|
case "element": {
|
|
3684
3743
|
const attrParts = node.attrs.map((a) => {
|
|
3685
|
-
|
|
3744
|
+
if (a.clientOnly)
|
|
3745
|
+
return "";
|
|
3746
|
+
const attrName = a.name === "..." ? "..." : a.name === "key" ? keyAttrName2(loopDepth) : toHTMLAttrName(a.name);
|
|
3686
3747
|
return renderTemplateAttrPart(a, attrName, wrapExpr, restSpreadNames);
|
|
3687
3748
|
}).filter(Boolean);
|
|
3688
3749
|
if (node.slotId) {
|
|
@@ -3705,7 +3766,8 @@ function irToPlaceholderTemplate(node, restSpreadNames, loopDepth = 0, loopParam
|
|
|
3705
3766
|
if (node.slotId) {
|
|
3706
3767
|
return `<!--bf:${node.slotId}-->\${${node.joinArrayChild ? value : escapeTextSlotExpr(wrapped)}}<!--/-->`;
|
|
3707
3768
|
}
|
|
3708
|
-
|
|
3769
|
+
const spliced = bareSpliceExpr(node, value);
|
|
3770
|
+
return `\${${node.escapeInClientTemplate ? `escapeText(${spliced})` : spliced}}`;
|
|
3709
3771
|
}
|
|
3710
3772
|
case "conditional": {
|
|
3711
3773
|
const trueBranch = recurse(node.whenTrue);
|
|
@@ -3887,7 +3949,7 @@ function irToComponentTemplateWithOpts(node, opts) {
|
|
|
3887
3949
|
if (a.name === "key") {
|
|
3888
3950
|
if (loopDepth === 0)
|
|
3889
3951
|
return "";
|
|
3890
|
-
const keyName =
|
|
3952
|
+
const keyName = keyAttrName2(loopDepth);
|
|
3891
3953
|
switch (v.kind) {
|
|
3892
3954
|
case "expression":
|
|
3893
3955
|
return templateAttrExpr(keyName, transformExpr(v.expr, v.templateExpr), v.presenceOrUndefined);
|
|
@@ -3947,7 +4009,7 @@ function irToComponentTemplateWithOpts(node, opts) {
|
|
|
3947
4009
|
const isMarkup = opts.markupSlotIds?.has(node.slotId) ?? false;
|
|
3948
4010
|
return `<!--bf:${node.slotId}-->\${${node.joinArrayChild ? value : escapeTextSlotExpr(wrapped, isMarkup)}}<!--/-->`;
|
|
3949
4011
|
}
|
|
3950
|
-
return `\${${value}}`;
|
|
4012
|
+
return `\${${bareSpliceExpr(node, value)}}`;
|
|
3951
4013
|
}
|
|
3952
4014
|
case "conditional": {
|
|
3953
4015
|
if (node.clientOnly && node.slotId) {
|
|
@@ -4230,7 +4292,7 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
4230
4292
|
return "";
|
|
4231
4293
|
return `\${spreadAttrs(${transformExpr(v.expr, v.templateExpr)})}`;
|
|
4232
4294
|
}
|
|
4233
|
-
const attrName = a.name === "key" ?
|
|
4295
|
+
const attrName = a.name === "key" ? keyAttrName2(loopDepth) : toHTMLAttrName(a.name);
|
|
4234
4296
|
switch (v.kind) {
|
|
4235
4297
|
case "boolean-attr":
|
|
4236
4298
|
return attrName;
|
|
@@ -4278,7 +4340,7 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
4278
4340
|
const isMarkup = opts.markupSlotIds?.has(node.slotId) ?? false;
|
|
4279
4341
|
return `<!--bf:${node.slotId}-->\${${node.joinArrayChild ? value : escapeTextSlotExpr(expr, isMarkup)}}<!--/-->`;
|
|
4280
4342
|
}
|
|
4281
|
-
return `\${${value}}`;
|
|
4343
|
+
return `\${${bareSpliceExpr(node, value)}}`;
|
|
4282
4344
|
}
|
|
4283
4345
|
case "conditional": {
|
|
4284
4346
|
if (node.clientOnly && node.slotId) {
|
|
@@ -4586,6 +4648,19 @@ function buildPropAliasMap(params) {
|
|
|
4586
4648
|
}
|
|
4587
4649
|
return map;
|
|
4588
4650
|
}
|
|
4651
|
+
function resolveRestSpreadOriginCore(bindings, constantValues, name) {
|
|
4652
|
+
const visited = new Set;
|
|
4653
|
+
let current = name.trim();
|
|
4654
|
+
while (current !== undefined && !visited.has(current)) {
|
|
4655
|
+
if (bindings.restPropsName && current === bindings.restPropsName)
|
|
4656
|
+
return "rest";
|
|
4657
|
+
if (bindings.propsObjectName && current === bindings.propsObjectName)
|
|
4658
|
+
return "props";
|
|
4659
|
+
visited.add(current);
|
|
4660
|
+
current = constantValues.get(current)?.trim();
|
|
4661
|
+
}
|
|
4662
|
+
return null;
|
|
4663
|
+
}
|
|
4589
4664
|
|
|
4590
4665
|
// ../jsx/src/instrumentation.ts
|
|
4591
4666
|
var _enabled = false;
|
|
@@ -7744,6 +7819,16 @@ function importsBrowserOnlyClientApi(ctx) {
|
|
|
7744
7819
|
}
|
|
7745
7820
|
function listComponentFunctions(source, filePath) {
|
|
7746
7821
|
const sourceFile = ts9.createSourceFile(filePath, source, ts9.ScriptTarget.Latest, true, ts9.ScriptKind.TSX);
|
|
7822
|
+
return listComponentFunctionsFromSourceFile(sourceFile);
|
|
7823
|
+
}
|
|
7824
|
+
function scanComponentFile(source, filePath) {
|
|
7825
|
+
const sourceFile = ts9.createSourceFile(filePath, source, ts9.ScriptTarget.Latest, true, ts9.ScriptKind.TSX);
|
|
7826
|
+
return {
|
|
7827
|
+
exports: listComponentFunctionsFromSourceFile(sourceFile),
|
|
7828
|
+
referencedComponents: [...collectJsxComponentTags(sourceFile)]
|
|
7829
|
+
};
|
|
7830
|
+
}
|
|
7831
|
+
function listComponentFunctionsFromSourceFile(sourceFile) {
|
|
7747
7832
|
const componentNames = [];
|
|
7748
7833
|
const hasUseClient = sourceFile.statements.some((stmt) => ts9.isExpressionStatement(stmt) && ts9.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
|
|
7749
7834
|
const namedExports = collectNamedExports(sourceFile);
|
|
@@ -10110,10 +10195,44 @@ function attachParsedExpressions(node, analyzer, bound = EMPTY_BOUND) {
|
|
|
10110
10195
|
break;
|
|
10111
10196
|
}
|
|
10112
10197
|
}
|
|
10198
|
+
function resolveRootKeyAttr(node) {
|
|
10199
|
+
if (!node)
|
|
10200
|
+
return;
|
|
10201
|
+
switch (node.type) {
|
|
10202
|
+
case "element":
|
|
10203
|
+
if (node.needsScope && !node.keyAttr)
|
|
10204
|
+
node.keyAttr = { name: BF_KEY };
|
|
10205
|
+
for (const c of node.children)
|
|
10206
|
+
resolveRootKeyAttr(c);
|
|
10207
|
+
return;
|
|
10208
|
+
case "fragment":
|
|
10209
|
+
case "component":
|
|
10210
|
+
case "provider":
|
|
10211
|
+
case "loop":
|
|
10212
|
+
for (const c of node.children)
|
|
10213
|
+
resolveRootKeyAttr(c);
|
|
10214
|
+
return;
|
|
10215
|
+
case "async":
|
|
10216
|
+
resolveRootKeyAttr(node.fallback);
|
|
10217
|
+
for (const c of node.children)
|
|
10218
|
+
resolveRootKeyAttr(c);
|
|
10219
|
+
return;
|
|
10220
|
+
case "conditional":
|
|
10221
|
+
resolveRootKeyAttr(node.whenTrue);
|
|
10222
|
+
resolveRootKeyAttr(node.whenFalse);
|
|
10223
|
+
return;
|
|
10224
|
+
case "if-statement":
|
|
10225
|
+
resolveRootKeyAttr(node.consequent);
|
|
10226
|
+
resolveRootKeyAttr(node.alternate);
|
|
10227
|
+
return;
|
|
10228
|
+
}
|
|
10229
|
+
}
|
|
10113
10230
|
function jsxToIR(analyzer) {
|
|
10114
10231
|
const root = buildIRRoot(analyzer);
|
|
10115
|
-
if (root)
|
|
10232
|
+
if (root) {
|
|
10116
10233
|
attachParsedExpressions(root, analyzer);
|
|
10234
|
+
resolveRootKeyAttr(root);
|
|
10235
|
+
}
|
|
10117
10236
|
return root;
|
|
10118
10237
|
}
|
|
10119
10238
|
function buildIRRoot(analyzer) {
|
|
@@ -10302,6 +10421,7 @@ function lowerFormControlValueSsr(tagName, attrs, children) {
|
|
|
10302
10421
|
type: "expression",
|
|
10303
10422
|
expr,
|
|
10304
10423
|
templateExpr: `escapeText(${templateExpr ?? expr})`,
|
|
10424
|
+
escapeInClientTemplate: true,
|
|
10305
10425
|
typeInfo: null,
|
|
10306
10426
|
reactive: false,
|
|
10307
10427
|
slotId: null,
|
|
@@ -10339,7 +10459,7 @@ function transformHtmlElement(node, ctx, tagName) {
|
|
|
10339
10459
|
ctx.isRoot = false;
|
|
10340
10460
|
const children = transformChildren(node.children, ctx);
|
|
10341
10461
|
lowerFormControlValueSsr(tagName, attrs, children);
|
|
10342
|
-
const needsSlot = events.length > 0 || hasDynamicContent(children) || hasReactiveAttributes(attrs, ctx) || ref !== null;
|
|
10462
|
+
const needsSlot = events.length > 0 || hasDynamicContent(children) || hasReactiveAttributes(attrs, ctx) || ref !== null || forwardsCallerRestProps(attrs, ctx);
|
|
10343
10463
|
const slotId = needsSlot ? generateSlotId(ctx) : null;
|
|
10344
10464
|
if (slotId) {
|
|
10345
10465
|
propagateSlotIdToLoops(children, slotId);
|
|
@@ -10372,7 +10492,7 @@ function transformSelfClosingElement(node, ctx) {
|
|
|
10372
10492
|
const { attrs, events, ref } = processAttributes(node.attributes, ctx);
|
|
10373
10493
|
const selfClosingChildren = [];
|
|
10374
10494
|
lowerFormControlValueSsr(tagName, attrs, selfClosingChildren);
|
|
10375
|
-
const needsSlot = events.length > 0 || hasReactiveAttributes(attrs, ctx) || ref !== null;
|
|
10495
|
+
const needsSlot = events.length > 0 || hasReactiveAttributes(attrs, ctx) || ref !== null || forwardsCallerRestProps(attrs, ctx);
|
|
10376
10496
|
const slotId = needsSlot ? generateSlotId(ctx) : null;
|
|
10377
10497
|
const needsScope = ctx.isRoot;
|
|
10378
10498
|
ctx.isRoot = false;
|
|
@@ -10598,6 +10718,33 @@ function unwrapHoistedFragment(node) {
|
|
|
10598
10718
|
return node;
|
|
10599
10719
|
return { ...only, needsScope: true };
|
|
10600
10720
|
}
|
|
10721
|
+
function markDataKeyCarrier(children) {
|
|
10722
|
+
for (let i = 0;i < children.length; i++) {
|
|
10723
|
+
const marked = markCarrierIn(children[i]);
|
|
10724
|
+
if (!marked)
|
|
10725
|
+
continue;
|
|
10726
|
+
const out = children.slice();
|
|
10727
|
+
out[i] = marked;
|
|
10728
|
+
return out;
|
|
10729
|
+
}
|
|
10730
|
+
return children;
|
|
10731
|
+
}
|
|
10732
|
+
function markCarrierIn(node) {
|
|
10733
|
+
if (node.type === "element") {
|
|
10734
|
+
if (node.keyAttr)
|
|
10735
|
+
return null;
|
|
10736
|
+
return { ...node, keyAttr: { name: BF_KEY } };
|
|
10737
|
+
}
|
|
10738
|
+
if (node.type === "conditional") {
|
|
10739
|
+
const cond = node;
|
|
10740
|
+
const whenTrue = markCarrierIn(cond.whenTrue);
|
|
10741
|
+
const whenFalse = markCarrierIn(cond.whenFalse);
|
|
10742
|
+
if (!whenTrue && !whenFalse)
|
|
10743
|
+
return null;
|
|
10744
|
+
return { ...cond, whenTrue: whenTrue ?? cond.whenTrue, whenFalse: whenFalse ?? cond.whenFalse };
|
|
10745
|
+
}
|
|
10746
|
+
return null;
|
|
10747
|
+
}
|
|
10601
10748
|
function transformFragment(node, ctx) {
|
|
10602
10749
|
const isFragmentRoot = ctx.isRoot;
|
|
10603
10750
|
const isTransparent = isFragmentRoot && isTransparentFragment(node, ctx);
|
|
@@ -10608,7 +10755,7 @@ function transformFragment(node, ctx) {
|
|
|
10608
10755
|
const needsScopeComment = isFragmentRoot && !isTransparent || undefined;
|
|
10609
10756
|
return {
|
|
10610
10757
|
type: "fragment",
|
|
10611
|
-
children,
|
|
10758
|
+
children: needsScopeComment ? markDataKeyCarrier(children) : children,
|
|
10612
10759
|
transparent: isTransparent || undefined,
|
|
10613
10760
|
needsScopeComment,
|
|
10614
10761
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath)
|
|
@@ -10661,7 +10808,7 @@ function transformExpressionInner(expr, ctx, node, isClientOnly) {
|
|
|
10661
10808
|
if (isRenderNothingLiteral(expr, ctx)) {
|
|
10662
10809
|
return null;
|
|
10663
10810
|
}
|
|
10664
|
-
checkBareSignalOrMemoIdentifier(expr, ctx);
|
|
10811
|
+
checkBareSignalOrMemoIdentifier(expr, ctx, { descendNested: true });
|
|
10665
10812
|
if (ts13.isIdentifier(expr)) {
|
|
10666
10813
|
const jsxNode = ctx.analyzer.jsxConstants.get(expr.text);
|
|
10667
10814
|
if (jsxNode) {
|
|
@@ -11778,6 +11925,16 @@ function tagLoopItemRootComponents(nodes) {
|
|
|
11778
11925
|
}
|
|
11779
11926
|
}
|
|
11780
11927
|
}
|
|
11928
|
+
function applyLoopKeyAttr(node, name, value) {
|
|
11929
|
+
if (node.type === "element") {
|
|
11930
|
+
node.keyAttr = { name, value };
|
|
11931
|
+
return;
|
|
11932
|
+
}
|
|
11933
|
+
if (node.type === "conditional") {
|
|
11934
|
+
applyLoopKeyAttr(node.whenTrue, name, value);
|
|
11935
|
+
applyLoopKeyAttr(node.whenFalse, name, value);
|
|
11936
|
+
}
|
|
11937
|
+
}
|
|
11781
11938
|
function loopBodyItemConditional(children) {
|
|
11782
11939
|
const real = children.filter((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
|
|
11783
11940
|
if (real.length !== 1)
|
|
@@ -12160,6 +12317,14 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12160
12317
|
const itemConditional = children.length > 0 ? loopBodyItemConditional(children) : null;
|
|
12161
12318
|
const bodyIsItemConditional = itemConditional !== null;
|
|
12162
12319
|
const key = bodyIsItemConditional ? extractItemConditionalKey(itemConditional) : children.length > 0 ? extractLoopKey(children[0]) : null;
|
|
12320
|
+
if (key !== null) {
|
|
12321
|
+
const resolvedKeyAttrName = keyAttrName(depth);
|
|
12322
|
+
if (bodyIsItemConditional) {
|
|
12323
|
+
applyLoopKeyAttr(itemConditional, resolvedKeyAttrName, key);
|
|
12324
|
+
} else if (children.length > 0) {
|
|
12325
|
+
applyLoopKeyAttr(children[0], resolvedKeyAttrName, key);
|
|
12326
|
+
}
|
|
12327
|
+
}
|
|
12163
12328
|
const declaredNameSet = preamble && preamble.declaredNames.length > 0 ? new Set(preamble.declaredNames) : undefined;
|
|
12164
12329
|
if (key && declaredNameSet) {
|
|
12165
12330
|
const keyRefs = extractFreeIdentifiersFromText(key);
|
|
@@ -12850,7 +13015,7 @@ function getAttributeValue(attr, ctx) {
|
|
|
12850
13015
|
ctx.analyzer.errors.push(createError(ErrorCodes.STAGE_AWAIT_IN_TEMPLATE, getSourceLocation(expr, ctx.sourceFile, ctx.filePath)));
|
|
12851
13016
|
return AttrValueOf.expression("undefined");
|
|
12852
13017
|
}
|
|
12853
|
-
checkBareSignalOrMemoIdentifier(expr, ctx);
|
|
13018
|
+
checkBareSignalOrMemoIdentifier(expr, ctx, { descendNested: isRenderedElementAttribute(attr, ctx) });
|
|
12854
13019
|
if (attr.name.getText(ctx.sourceFile) === "style" && ts13.isObjectLiteralExpression(expr)) {
|
|
12855
13020
|
const cssString = tryStaticStyleObjectToCss(expr);
|
|
12856
13021
|
if (cssString !== null) {
|
|
@@ -13358,34 +13523,142 @@ function processComponentProps(attributes, ctx) {
|
|
|
13358
13523
|
}
|
|
13359
13524
|
return props;
|
|
13360
13525
|
}
|
|
13361
|
-
function
|
|
13362
|
-
|
|
13526
|
+
function isRenderedElementAttribute(attr, ctx) {
|
|
13527
|
+
const tagName = attr.parent.parent.tagName.getText(ctx.sourceFile);
|
|
13528
|
+
return !/^[A-Z]/.test(tagName);
|
|
13529
|
+
}
|
|
13530
|
+
function checkBareSignalOrMemoIdentifier(expr, ctx, options) {
|
|
13531
|
+
const reactiveNames = new Map;
|
|
13532
|
+
for (const signal of ctx.analyzer.signals)
|
|
13533
|
+
reactiveNames.set(signal.getter, "signal");
|
|
13534
|
+
for (const memo of ctx.analyzer.memos)
|
|
13535
|
+
reactiveNames.set(memo.name, "memo");
|
|
13536
|
+
if (reactiveNames.size === 0)
|
|
13363
13537
|
return;
|
|
13364
|
-
const
|
|
13365
|
-
|
|
13366
|
-
|
|
13367
|
-
|
|
13368
|
-
|
|
13369
|
-
|
|
13370
|
-
|
|
13371
|
-
|
|
13372
|
-
|
|
13373
|
-
|
|
13538
|
+
const report = (id, name, kind) => {
|
|
13539
|
+
const label = kind === "signal" ? "Signal" : "Memo";
|
|
13540
|
+
ctx.analyzer.errors.push(createError(ErrorCodes.SIGNAL_GETTER_NOT_CALLED, getSourceLocation(id, ctx.sourceFile, ctx.filePath), {
|
|
13541
|
+
message: `${label} getter '${name}' passed without calling it`,
|
|
13542
|
+
suggestion: {
|
|
13543
|
+
message: `${label} getters must be called to read the value. Use \`${name}()\` instead of \`${name}\`.`,
|
|
13544
|
+
replacement: `${name}()`
|
|
13545
|
+
}
|
|
13546
|
+
}));
|
|
13547
|
+
};
|
|
13548
|
+
if (ts13.isIdentifier(expr)) {
|
|
13549
|
+
const kind = reactiveNames.get(expr.text);
|
|
13550
|
+
if (kind && !ctx.scope.isBound(expr.text))
|
|
13551
|
+
report(expr, expr.text, kind);
|
|
13552
|
+
return;
|
|
13553
|
+
}
|
|
13554
|
+
if (!options?.descendNested)
|
|
13555
|
+
return;
|
|
13556
|
+
const boundStack = [];
|
|
13557
|
+
const isBound = (name) => {
|
|
13558
|
+
for (let i = boundStack.length - 1;i >= 0; i--) {
|
|
13559
|
+
if (boundStack[i].has(name))
|
|
13560
|
+
return true;
|
|
13561
|
+
}
|
|
13562
|
+
return ctx.scope.isBound(name);
|
|
13563
|
+
};
|
|
13564
|
+
const visitBindingDefaults = (name, bound) => {
|
|
13565
|
+
if (ts13.isIdentifier(name)) {
|
|
13566
|
+
bound.add(name.text);
|
|
13374
13567
|
return;
|
|
13375
13568
|
}
|
|
13376
|
-
|
|
13377
|
-
|
|
13378
|
-
|
|
13379
|
-
|
|
13380
|
-
|
|
13381
|
-
|
|
13382
|
-
|
|
13383
|
-
|
|
13384
|
-
|
|
13385
|
-
|
|
13569
|
+
for (const el of name.elements) {
|
|
13570
|
+
if (ts13.isOmittedExpression(el))
|
|
13571
|
+
continue;
|
|
13572
|
+
if (el.initializer)
|
|
13573
|
+
visit2(el.initializer);
|
|
13574
|
+
visitBindingDefaults(el.name, bound);
|
|
13575
|
+
}
|
|
13576
|
+
};
|
|
13577
|
+
const collectBindingNames3 = (name, out) => {
|
|
13578
|
+
if (ts13.isIdentifier(name))
|
|
13579
|
+
out.add(name.text);
|
|
13580
|
+
else if (ts13.isObjectBindingPattern(name)) {
|
|
13581
|
+
for (const el of name.elements)
|
|
13582
|
+
collectBindingNames3(el.name, out);
|
|
13583
|
+
} else if (ts13.isArrayBindingPattern(name)) {
|
|
13584
|
+
for (const el of name.elements) {
|
|
13585
|
+
if (!ts13.isOmittedExpression(el))
|
|
13586
|
+
collectBindingNames3(el.name, out);
|
|
13587
|
+
}
|
|
13588
|
+
}
|
|
13589
|
+
};
|
|
13590
|
+
const collectBlockDeclarations = (block, out) => {
|
|
13591
|
+
for (const stmt of block.statements) {
|
|
13592
|
+
if (ts13.isVariableStatement(stmt)) {
|
|
13593
|
+
for (const decl of stmt.declarationList.declarations)
|
|
13594
|
+
collectBindingNames3(decl.name, out);
|
|
13595
|
+
} else if (ts13.isFunctionDeclaration(stmt) && stmt.name) {
|
|
13596
|
+
out.add(stmt.name.text);
|
|
13597
|
+
}
|
|
13598
|
+
}
|
|
13599
|
+
};
|
|
13600
|
+
function visit2(node) {
|
|
13601
|
+
if (ts13.isJsxElement(node) || ts13.isJsxSelfClosingElement(node) || ts13.isJsxFragment(node)) {
|
|
13602
|
+
return;
|
|
13603
|
+
}
|
|
13604
|
+
if (ts13.isTypeNode(node))
|
|
13605
|
+
return;
|
|
13606
|
+
if (ts13.isCallExpression(node) && node.arguments.length === 0 && ts13.isIdentifier(node.expression)) {
|
|
13607
|
+
return;
|
|
13608
|
+
}
|
|
13609
|
+
if (ts13.isPropertyAccessExpression(node)) {
|
|
13610
|
+
visit2(node.expression);
|
|
13386
13611
|
return;
|
|
13387
13612
|
}
|
|
13613
|
+
if (ts13.isPropertyAssignment(node)) {
|
|
13614
|
+
if (ts13.isComputedPropertyName(node.name))
|
|
13615
|
+
visit2(node.name.expression);
|
|
13616
|
+
visit2(node.initializer);
|
|
13617
|
+
return;
|
|
13618
|
+
}
|
|
13619
|
+
if (ts13.isShorthandPropertyAssignment(node)) {
|
|
13620
|
+
if (ts13.isIdentifier(node.name) && !isBound(node.name.text)) {
|
|
13621
|
+
const kind = reactiveNames.get(node.name.text);
|
|
13622
|
+
if (kind)
|
|
13623
|
+
report(node.name, node.name.text, kind);
|
|
13624
|
+
}
|
|
13625
|
+
return;
|
|
13626
|
+
}
|
|
13627
|
+
if (ts13.isArrowFunction(node) || ts13.isFunctionExpression(node)) {
|
|
13628
|
+
const bound = new Set;
|
|
13629
|
+
boundStack.push(bound);
|
|
13630
|
+
for (const p of node.parameters) {
|
|
13631
|
+
if (p.initializer)
|
|
13632
|
+
visit2(p.initializer);
|
|
13633
|
+
visitBindingDefaults(p.name, bound);
|
|
13634
|
+
}
|
|
13635
|
+
if (node.body && ts13.isBlock(node.body))
|
|
13636
|
+
collectBlockDeclarations(node.body, bound);
|
|
13637
|
+
if (node.body)
|
|
13638
|
+
visit2(node.body);
|
|
13639
|
+
boundStack.pop();
|
|
13640
|
+
return;
|
|
13641
|
+
}
|
|
13642
|
+
if (ts13.isVariableDeclaration(node)) {
|
|
13643
|
+
if (node.initializer)
|
|
13644
|
+
visit2(node.initializer);
|
|
13645
|
+
const declared = new Set;
|
|
13646
|
+
boundStack.push(declared);
|
|
13647
|
+
visitBindingDefaults(node.name, declared);
|
|
13648
|
+
boundStack.pop();
|
|
13649
|
+
return;
|
|
13650
|
+
}
|
|
13651
|
+
if (ts13.isIdentifier(node)) {
|
|
13652
|
+
if (isBound(node.text))
|
|
13653
|
+
return;
|
|
13654
|
+
const kind = reactiveNames.get(node.text);
|
|
13655
|
+
if (kind)
|
|
13656
|
+
report(node, node.text, kind);
|
|
13657
|
+
return;
|
|
13658
|
+
}
|
|
13659
|
+
ts13.forEachChild(node, visit2);
|
|
13388
13660
|
}
|
|
13661
|
+
visit2(expr);
|
|
13389
13662
|
}
|
|
13390
13663
|
function isArrayExprDirectPropRef(arrayExpr, ctx) {
|
|
13391
13664
|
const propNames = new Set(ctx.patterns.props.map((p) => p.name));
|
|
@@ -13484,6 +13757,31 @@ function isPropsReference(expr, ctx, visited) {
|
|
|
13484
13757
|
}
|
|
13485
13758
|
return false;
|
|
13486
13759
|
}
|
|
13760
|
+
function forwardsCallerRestProps(attrs, ctx) {
|
|
13761
|
+
for (const attr of attrs) {
|
|
13762
|
+
if (attr.value.kind !== "spread")
|
|
13763
|
+
continue;
|
|
13764
|
+
const constants = restSpreadConstantValues(ctx);
|
|
13765
|
+
for (const name of new Set([attr.value.expr, attr.value.templateExpr])) {
|
|
13766
|
+
if (!name)
|
|
13767
|
+
continue;
|
|
13768
|
+
if (resolveRestSpreadOriginCore(ctx.analyzer, constants, name) !== null)
|
|
13769
|
+
return true;
|
|
13770
|
+
}
|
|
13771
|
+
}
|
|
13772
|
+
return false;
|
|
13773
|
+
}
|
|
13774
|
+
function restSpreadConstantValues(ctx) {
|
|
13775
|
+
if (ctx._restSpreadConstantValues)
|
|
13776
|
+
return ctx._restSpreadConstantValues;
|
|
13777
|
+
const byName = new Map;
|
|
13778
|
+
for (const constant of ctx.analyzer.localConstants) {
|
|
13779
|
+
if (!byName.has(constant.name))
|
|
13780
|
+
byName.set(constant.name, constant.value);
|
|
13781
|
+
}
|
|
13782
|
+
ctx._restSpreadConstantValues = byName;
|
|
13783
|
+
return byName;
|
|
13784
|
+
}
|
|
13487
13785
|
function hasReactiveAttributes(attrs, ctx) {
|
|
13488
13786
|
for (const attr of attrs) {
|
|
13489
13787
|
if (attr.name === "key")
|
|
@@ -13705,6 +14003,39 @@ function buildIfStatementChain(analyzer, ctx, opts) {
|
|
|
13705
14003
|
}
|
|
13706
14004
|
|
|
13707
14005
|
// ../jsx/src/ir-to-client-js/prop-handling.ts
|
|
14006
|
+
function resolveRestSpreadOrigin(ctx, name) {
|
|
14007
|
+
return resolveRestSpreadOriginCore(ctx, localConstantValues(ctx), name);
|
|
14008
|
+
}
|
|
14009
|
+
var _localConstantValuesCache = new WeakMap;
|
|
14010
|
+
function localConstantValues(ctx) {
|
|
14011
|
+
const cached = _localConstantValuesCache.get(ctx);
|
|
14012
|
+
if (cached)
|
|
14013
|
+
return cached;
|
|
14014
|
+
const byName = new Map;
|
|
14015
|
+
for (const constant of ctx.localConstants) {
|
|
14016
|
+
if (!byName.has(constant.name))
|
|
14017
|
+
byName.set(constant.name, constant.value);
|
|
14018
|
+
}
|
|
14019
|
+
_localConstantValuesCache.set(ctx, byName);
|
|
14020
|
+
return byName;
|
|
14021
|
+
}
|
|
14022
|
+
var _restSpreadNamesCache = new WeakMap;
|
|
14023
|
+
function resolveRestSpreadNames(ctx) {
|
|
14024
|
+
const cached = _restSpreadNamesCache.get(ctx);
|
|
14025
|
+
if (cached)
|
|
14026
|
+
return cached;
|
|
14027
|
+
const names = new Set;
|
|
14028
|
+
if (ctx.restPropsName)
|
|
14029
|
+
names.add(ctx.restPropsName);
|
|
14030
|
+
if (ctx.propsObjectName)
|
|
14031
|
+
names.add(ctx.propsObjectName);
|
|
14032
|
+
for (const constant of ctx.localConstants) {
|
|
14033
|
+
if (resolveRestSpreadOrigin(ctx, constant.name) !== null)
|
|
14034
|
+
names.add(constant.name);
|
|
14035
|
+
}
|
|
14036
|
+
_restSpreadNamesCache.set(ctx, names);
|
|
14037
|
+
return names;
|
|
14038
|
+
}
|
|
13708
14039
|
function expandDynamicPropValue(value, ctx, scope) {
|
|
13709
14040
|
const trimmedValue = value.trim();
|
|
13710
14041
|
if (scope?.isBound(trimmedValue))
|
|
@@ -13793,6 +14124,9 @@ function decideWrapForChildProp(expandedValue, ctx, prop) {
|
|
|
13793
14124
|
return decideWrapForAttr(expandedValue, ctx, prop);
|
|
13794
14125
|
}
|
|
13795
14126
|
function needsEffectWrapper(expr, ctx, freeIdentifiers2) {
|
|
14127
|
+
return needsEffectWrapperCore(expr, ctx, freeIdentifiers2, new Set);
|
|
14128
|
+
}
|
|
14129
|
+
function needsEffectWrapperCore(expr, ctx, freeIdentifiers2, visitedConstants) {
|
|
13796
14130
|
for (const signal of ctx.signals) {
|
|
13797
14131
|
if (identifierCallPattern(signal.getter).test(expr)) {
|
|
13798
14132
|
return true;
|
|
@@ -13815,6 +14149,19 @@ function needsEffectWrapper(expr, ctx, freeIdentifiers2) {
|
|
|
13815
14149
|
if (propsAccess.test(expr))
|
|
13816
14150
|
return true;
|
|
13817
14151
|
}
|
|
14152
|
+
for (const constant of ctx.localConstants) {
|
|
14153
|
+
if (visitedConstants.has(constant.name))
|
|
14154
|
+
continue;
|
|
14155
|
+
if (constant.value === undefined || constant.containsArrow)
|
|
14156
|
+
continue;
|
|
14157
|
+
const referenced = freeIdentifiers2 ? freeIdentifiers2.has(constant.name) : tokenContainsIdent(expr, constant.name);
|
|
14158
|
+
if (!referenced)
|
|
14159
|
+
continue;
|
|
14160
|
+
visitedConstants.add(constant.name);
|
|
14161
|
+
if (needsEffectWrapperCore(constant.value, ctx, constant.freeIdentifiers, visitedConstants)) {
|
|
14162
|
+
return true;
|
|
14163
|
+
}
|
|
14164
|
+
}
|
|
13818
14165
|
return false;
|
|
13819
14166
|
}
|
|
13820
14167
|
function classifyReactivity(expr, ctx, loopParam, loopParamBindings, freeIdentifiers2) {
|
|
@@ -14488,24 +14835,14 @@ function jsxChildrenContainComponent(nodes) {
|
|
|
14488
14835
|
function isSingleElementJsxChildren2(nodes) {
|
|
14489
14836
|
return nodes.length === 1 && nodes[0].type === "element";
|
|
14490
14837
|
}
|
|
14491
|
-
function buildRestSpreadNames(ctx) {
|
|
14492
|
-
const names = new Set;
|
|
14493
|
-
if (ctx.restPropsName)
|
|
14494
|
-
names.add(ctx.restPropsName);
|
|
14495
|
-
if (ctx.propsObjectName)
|
|
14496
|
-
names.add(ctx.propsObjectName);
|
|
14497
|
-
return names;
|
|
14498
|
-
}
|
|
14499
14838
|
function buildComponentPropsExpr(props, ctx) {
|
|
14500
|
-
const restName = ctx.restPropsName;
|
|
14501
|
-
const propsObjName = ctx.propsObjectName;
|
|
14502
14839
|
const knownSpreadProp = props.find((p) => {
|
|
14503
14840
|
if (p.name !== "..." && !p.name.startsWith("..."))
|
|
14504
14841
|
return false;
|
|
14505
14842
|
if (p.value.kind !== "spread" && p.value.kind !== "expression")
|
|
14506
14843
|
return false;
|
|
14507
14844
|
const expr = p.value.kind === "spread" ? p.value.expr : p.value.expr;
|
|
14508
|
-
return
|
|
14845
|
+
return resolveRestSpreadOrigin(ctx, expr) !== null;
|
|
14509
14846
|
});
|
|
14510
14847
|
const spreadSource = knownSpreadProp ? PROPS_PARAM : null;
|
|
14511
14848
|
const propsForInit = [];
|
|
@@ -14563,8 +14900,8 @@ function collectReactiveChildProps(node, ctx) {
|
|
|
14563
14900
|
continue;
|
|
14564
14901
|
if (prop.value.kind === "jsx-children")
|
|
14565
14902
|
continue;
|
|
14566
|
-
const
|
|
14567
|
-
if (
|
|
14903
|
+
const domKind = classifyDOMProp(prop.name).kind;
|
|
14904
|
+
if (domKind === "ref" || domKind === "event" || domKind === "skip")
|
|
14568
14905
|
continue;
|
|
14569
14906
|
if (prop.value.kind !== "expression" && prop.value.kind !== "template")
|
|
14570
14907
|
continue;
|
|
@@ -14653,13 +14990,13 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
|
|
|
14653
14990
|
if (l.childComponent) {
|
|
14654
14991
|
template = "";
|
|
14655
14992
|
if (l.isStaticArray && l.children[0]) {
|
|
14656
|
-
staticItemTemplate = irToHtmlTemplate(l.children[0],
|
|
14993
|
+
staticItemTemplate = irToHtmlTemplate(l.children[0], resolveRestSpreadNames(ctx), 0, undefined, undefined);
|
|
14657
14994
|
}
|
|
14658
14995
|
} else if (l.children[0] && !projectionInner) {
|
|
14659
14996
|
const loopParamSpec = [{ param: l.param, bindings: l.paramBindings }];
|
|
14660
|
-
template = useElementReconciliation ? irToPlaceholderTemplate(l.children[0],
|
|
14997
|
+
template = useElementReconciliation ? irToPlaceholderTemplate(l.children[0], resolveRestSpreadNames(ctx), 0, loopParamSpec) : irToHtmlTemplate(l.children[0], resolveRestSpreadNames(ctx), 0, loopParamSpec);
|
|
14661
14998
|
if (l.isStaticArray) {
|
|
14662
|
-
staticItemTemplate = useElementReconciliation ? irToPlaceholderTemplate(l.children[0],
|
|
14999
|
+
staticItemTemplate = useElementReconciliation ? irToPlaceholderTemplate(l.children[0], resolveRestSpreadNames(ctx), 0) : irToHtmlTemplate(l.children[0], resolveRestSpreadNames(ctx), 0);
|
|
14663
15000
|
} else if (!useElementReconciliation && !l.bodyIsMultiRoot && !l.bodyIsItemConditional) {
|
|
14664
15001
|
const skeletonSafeSlots = {
|
|
14665
15002
|
reactiveAttrKeys: new Set(bindings.reactiveAttrs.map((a) => `${a.childSlotId}::${a.attrName}`)),
|
|
@@ -14711,11 +15048,11 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
|
|
|
14711
15048
|
preambleRegions: l.preambleRegions,
|
|
14712
15049
|
flatMapClient: projectionInner ? {
|
|
14713
15050
|
params: l.index ? `(${l.param}, ${l.index})` : `(${l.param})`,
|
|
14714
|
-
body: renderFlatMapProjectionClientBody(projectionInner,
|
|
15051
|
+
body: renderFlatMapProjectionClientBody(projectionInner, resolveRestSpreadNames(ctx)),
|
|
14715
15052
|
keyed: projectionInner.key !== null
|
|
14716
15053
|
} : l.flatMapCallback ? {
|
|
14717
15054
|
params: l.flatMapCallback.params,
|
|
14718
|
-
body: renderFlatMapClientBody(l.flatMapCallback,
|
|
15055
|
+
body: renderFlatMapClientBody(l.flatMapCallback, resolveRestSpreadNames(ctx)),
|
|
14719
15056
|
keyed: flatMapCallbackHasKeyedLeaf(l.flatMapCallback)
|
|
14720
15057
|
} : undefined
|
|
14721
15058
|
});
|
|
@@ -14782,10 +15119,9 @@ function collectFromElement(element, ctx, insideConditional = false) {
|
|
|
14782
15119
|
for (const attr of element.attrs) {
|
|
14783
15120
|
if (attr.name === "..." && attr.value) {
|
|
14784
15121
|
const spreadVal = attrValueToString(attr.value) ?? "";
|
|
14785
|
-
const
|
|
14786
|
-
|
|
14787
|
-
|
|
14788
|
-
const consumedKeys = spreadVal === elemRestName ? ctx.propsParams.map((p) => p.sourceName ?? p.name) : [];
|
|
15122
|
+
const spreadOrigin = spreadVal ? resolveRestSpreadOrigin(ctx, spreadVal) : null;
|
|
15123
|
+
if (spreadOrigin !== null) {
|
|
15124
|
+
const consumedKeys = spreadOrigin === "rest" ? ctx.propsParams.map((p) => p.sourceName ?? p.name) : [];
|
|
14789
15125
|
const staticAttrKeys = element.attrs.filter((a) => a.name !== "...").map((a) => a.name);
|
|
14790
15126
|
const excludeKeys = [...new Set([...consumedKeys, ...staticAttrKeys])];
|
|
14791
15127
|
ctx.restAttrElements.push({
|
|
@@ -14864,7 +15200,7 @@ function collectBranchTextEffects(node) {
|
|
|
14864
15200
|
}
|
|
14865
15201
|
function collectBranchLoops(node, ctx, siblingOffsets) {
|
|
14866
15202
|
const loops = [];
|
|
14867
|
-
const restNames = ctx ?
|
|
15203
|
+
const restNames = ctx ? resolveRestSpreadNames(ctx) : undefined;
|
|
14868
15204
|
walkIR(node, null, {
|
|
14869
15205
|
...stopAt("conditional", "ifStatement"),
|
|
14870
15206
|
element: ({ node: el, scope: parentSlotId, descend }) => {
|
|
@@ -14932,7 +15268,7 @@ function collectBranchLoops(node, ctx, siblingOffsets) {
|
|
|
14932
15268
|
return loops;
|
|
14933
15269
|
}
|
|
14934
15270
|
function buildConditionalMetadata(node, ctx, siblingOffsets) {
|
|
14935
|
-
const restNames =
|
|
15271
|
+
const restNames = resolveRestSpreadNames(ctx);
|
|
14936
15272
|
return {
|
|
14937
15273
|
slotId: node.slotId,
|
|
14938
15274
|
condition: node.condition,
|
|
@@ -15482,6 +15818,9 @@ function propHasPropertyAccess(u) {
|
|
|
15482
15818
|
return u.accessKinds.has("property") || u.accessKinds.has("index");
|
|
15483
15819
|
}
|
|
15484
15820
|
|
|
15821
|
+
// ../jsx/src/ir-to-client-js/imports.ts
|
|
15822
|
+
import ts16 from "typescript";
|
|
15823
|
+
|
|
15485
15824
|
// ../jsx/src/value-references.ts
|
|
15486
15825
|
import ts15 from "typescript";
|
|
15487
15826
|
function isValueReferenceIdentifier(id) {
|
|
@@ -15588,6 +15927,7 @@ var RUNTIME_IMPORT_CANDIDATES = [
|
|
|
15588
15927
|
"escapeTextOrNode",
|
|
15589
15928
|
"bfMarkup",
|
|
15590
15929
|
"escapeTextOrMarkup",
|
|
15930
|
+
"markupOrEmpty",
|
|
15591
15931
|
"qsa",
|
|
15592
15932
|
"qsaItem",
|
|
15593
15933
|
"qsaChildScope",
|
|
@@ -15654,6 +15994,79 @@ function makeValueUsageTest(generatedCode) {
|
|
|
15654
15994
|
return generatedCode.includes(localName);
|
|
15655
15995
|
};
|
|
15656
15996
|
}
|
|
15997
|
+
function renderUsedImportLines(source, usedDefault, usedNamespace, usedNamed) {
|
|
15998
|
+
const lines = [];
|
|
15999
|
+
const defaultAndNamed = [
|
|
16000
|
+
usedDefault,
|
|
16001
|
+
usedNamed.length > 0 ? `{ ${usedNamed.join(", ")} }` : null
|
|
16002
|
+
].filter((part) => part !== null).join(", ");
|
|
16003
|
+
if (defaultAndNamed)
|
|
16004
|
+
lines.push(`import ${defaultAndNamed} from '${source}'`);
|
|
16005
|
+
if (usedNamespace)
|
|
16006
|
+
lines.push(`import * as ${usedNamespace} from '${source}'`);
|
|
16007
|
+
return lines;
|
|
16008
|
+
}
|
|
16009
|
+
function mergeCompiledClientJsImports(codeBlobs) {
|
|
16010
|
+
const sourceOrder = [];
|
|
16011
|
+
const namedBySource = new Map;
|
|
16012
|
+
const defaultBySource = new Map;
|
|
16013
|
+
const otherImports = [];
|
|
16014
|
+
const seenOther = new Set;
|
|
16015
|
+
const codeSections = [];
|
|
16016
|
+
const ensureSource = (source) => {
|
|
16017
|
+
if (!namedBySource.has(source)) {
|
|
16018
|
+
namedBySource.set(source, new Set);
|
|
16019
|
+
sourceOrder.push(source);
|
|
16020
|
+
}
|
|
16021
|
+
return namedBySource.get(source);
|
|
16022
|
+
};
|
|
16023
|
+
for (const content of codeBlobs) {
|
|
16024
|
+
const sourceFile = ts16.createSourceFile("combine.js", content, ts16.ScriptTarget.Latest, false, ts16.ScriptKind.JS);
|
|
16025
|
+
const importSpans = [];
|
|
16026
|
+
for (const stmt of sourceFile.statements) {
|
|
16027
|
+
if (!ts16.isImportDeclaration(stmt))
|
|
16028
|
+
continue;
|
|
16029
|
+
const start = stmt.getStart(sourceFile);
|
|
16030
|
+
const end = stmt.getEnd();
|
|
16031
|
+
importSpans.push([start, end]);
|
|
16032
|
+
const clause = stmt.importClause;
|
|
16033
|
+
const bindings = clause?.namedBindings;
|
|
16034
|
+
const specifier = ts16.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
|
|
16035
|
+
const isNamespace = !!bindings && ts16.isNamespaceImport(bindings);
|
|
16036
|
+
const isNamed = !!bindings && ts16.isNamedImports(bindings);
|
|
16037
|
+
if (!isNamespace && (clause?.name || isNamed)) {
|
|
16038
|
+
const set = ensureSource(specifier);
|
|
16039
|
+
if (clause?.name && !defaultBySource.has(specifier)) {
|
|
16040
|
+
defaultBySource.set(specifier, clause.name.text);
|
|
16041
|
+
}
|
|
16042
|
+
if (isNamed) {
|
|
16043
|
+
for (const el of bindings.elements) {
|
|
16044
|
+
set.add(el.propertyName ? `${el.propertyName.text} as ${el.name.text}` : el.name.text);
|
|
16045
|
+
}
|
|
16046
|
+
}
|
|
16047
|
+
} else {
|
|
16048
|
+
const stmtText = content.slice(start, end);
|
|
16049
|
+
if (!seenOther.has(stmtText)) {
|
|
16050
|
+
seenOther.add(stmtText);
|
|
16051
|
+
otherImports.push(stmtText);
|
|
16052
|
+
}
|
|
16053
|
+
}
|
|
16054
|
+
}
|
|
16055
|
+
let code = "";
|
|
16056
|
+
let cursor = 0;
|
|
16057
|
+
for (const [start, end] of importSpans) {
|
|
16058
|
+
code += content.slice(cursor, start);
|
|
16059
|
+
cursor = end;
|
|
16060
|
+
}
|
|
16061
|
+
code += content.slice(cursor);
|
|
16062
|
+
code = code.trim();
|
|
16063
|
+
if (code)
|
|
16064
|
+
codeSections.push(code);
|
|
16065
|
+
}
|
|
16066
|
+
const mergedImports = sourceOrder.flatMap((source) => renderUsedImportLines(source, defaultBySource.get(source) ?? null, null, [...namedBySource.get(source)]));
|
|
16067
|
+
return [...mergedImports, ...otherImports, "", ...codeSections].join(`
|
|
16068
|
+
`);
|
|
16069
|
+
}
|
|
15657
16070
|
function collectExternalImports(ir, generatedCode, localImportPrefixes) {
|
|
15658
16071
|
const componentNames = collectComponentNames(ir.root);
|
|
15659
16072
|
const importLines = [];
|
|
@@ -15669,23 +16082,31 @@ function collectExternalImports(ir, generatedCode, localImportPrefixes) {
|
|
|
15669
16082
|
importLines.push(`import '${imp.source}'`);
|
|
15670
16083
|
continue;
|
|
15671
16084
|
}
|
|
15672
|
-
const
|
|
16085
|
+
const usedNamed = [];
|
|
16086
|
+
let usedDefault = null;
|
|
16087
|
+
let usedNamespace = null;
|
|
15673
16088
|
for (const spec of imp.specifiers) {
|
|
15674
16089
|
if (spec.isTypeOnly)
|
|
15675
16090
|
continue;
|
|
15676
16091
|
const localName = spec.alias || spec.name;
|
|
15677
16092
|
if (componentNames.has(localName))
|
|
15678
16093
|
continue;
|
|
15679
|
-
if (isUsedAsValue(localName))
|
|
15680
|
-
|
|
16094
|
+
if (!isUsedAsValue(localName))
|
|
16095
|
+
continue;
|
|
16096
|
+
if (spec.isDefault) {
|
|
16097
|
+
usedDefault = localName;
|
|
16098
|
+
} else if (spec.isNamespace) {
|
|
16099
|
+
usedNamespace = localName;
|
|
16100
|
+
} else {
|
|
16101
|
+
usedNamed.push(spec.alias ? `${spec.name} as ${spec.alias}` : spec.name);
|
|
15681
16102
|
}
|
|
15682
16103
|
}
|
|
15683
|
-
if (
|
|
16104
|
+
if (usedDefault || usedNamespace || usedNamed.length > 0) {
|
|
15684
16105
|
let source = imp.source;
|
|
15685
16106
|
if (ir.metadata.clientSignalImportSources?.has(source)) {
|
|
15686
16107
|
source = source.replace(/\.tsx?$/, "") + ".client.js";
|
|
15687
16108
|
}
|
|
15688
|
-
importLines.push(
|
|
16109
|
+
importLines.push(...renderUsedImportLines(source, usedDefault, usedNamespace, usedNamed));
|
|
15689
16110
|
}
|
|
15690
16111
|
}
|
|
15691
16112
|
return importLines;
|
|
@@ -15715,7 +16136,7 @@ function collectComponentNames(node) {
|
|
|
15715
16136
|
}
|
|
15716
16137
|
|
|
15717
16138
|
// ../jsx/src/relocate.ts
|
|
15718
|
-
import
|
|
16139
|
+
import ts17 from "typescript";
|
|
15719
16140
|
|
|
15720
16141
|
// ../jsx/src/lowering-registry.ts
|
|
15721
16142
|
var plugins = [];
|
|
@@ -15743,19 +16164,19 @@ function classify(name, env) {
|
|
|
15743
16164
|
function collectFreeRefs(node) {
|
|
15744
16165
|
const refs = new Map;
|
|
15745
16166
|
function visit3(n, parent) {
|
|
15746
|
-
if (
|
|
15747
|
-
if (parent &&
|
|
16167
|
+
if (ts17.isIdentifier(n)) {
|
|
16168
|
+
if (parent && ts17.isPropertyAccessExpression(parent) && parent.name === n)
|
|
15748
16169
|
return;
|
|
15749
|
-
if (parent &&
|
|
16170
|
+
if (parent && ts17.isPropertyAssignment(parent) && parent.name === n)
|
|
15750
16171
|
return;
|
|
15751
|
-
if (parent &&
|
|
16172
|
+
if (parent && ts17.isShorthandPropertyAssignment(parent) && parent.name === n)
|
|
15752
16173
|
return;
|
|
15753
16174
|
const list = refs.get(n.text) ?? [];
|
|
15754
16175
|
list.push(n);
|
|
15755
16176
|
refs.set(n.text, list);
|
|
15756
16177
|
return;
|
|
15757
16178
|
}
|
|
15758
|
-
|
|
16179
|
+
ts17.forEachChild(n, (child) => visit3(child, n));
|
|
15759
16180
|
}
|
|
15760
16181
|
visit3(node);
|
|
15761
16182
|
return refs;
|
|
@@ -15859,11 +16280,11 @@ function isInlinableInTemplate(value, env) {
|
|
|
15859
16280
|
return { ok: true, rewrittenValue: r.text, decisions: r.decisions };
|
|
15860
16281
|
}
|
|
15861
16282
|
function getCalleeIdentifierPath(callee) {
|
|
15862
|
-
if (
|
|
16283
|
+
if (ts17.isParenthesizedExpression(callee))
|
|
15863
16284
|
return getCalleeIdentifierPath(callee.expression);
|
|
15864
|
-
if (
|
|
16285
|
+
if (ts17.isIdentifier(callee))
|
|
15865
16286
|
return callee.text;
|
|
15866
|
-
if (
|
|
16287
|
+
if (ts17.isPropertyAccessExpression(callee)) {
|
|
15867
16288
|
const left = getCalleeIdentifierPath(callee.expression);
|
|
15868
16289
|
if (left === null)
|
|
15869
16290
|
return null;
|
|
@@ -15872,11 +16293,11 @@ function getCalleeIdentifierPath(callee) {
|
|
|
15872
16293
|
return null;
|
|
15873
16294
|
}
|
|
15874
16295
|
function getCalleeLeftmostIdentifier(callee) {
|
|
15875
|
-
if (
|
|
16296
|
+
if (ts17.isParenthesizedExpression(callee))
|
|
15876
16297
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
15877
|
-
if (
|
|
16298
|
+
if (ts17.isIdentifier(callee))
|
|
15878
16299
|
return callee.text;
|
|
15879
|
-
if (
|
|
16300
|
+
if (ts17.isPropertyAccessExpression(callee)) {
|
|
15880
16301
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
15881
16302
|
}
|
|
15882
16303
|
return null;
|
|
@@ -15924,12 +16345,12 @@ function isCallAcceptedByAdapter(call, env) {
|
|
|
15924
16345
|
}
|
|
15925
16346
|
function parseExpressionNode(text) {
|
|
15926
16347
|
try {
|
|
15927
|
-
const sf =
|
|
16348
|
+
const sf = ts17.createSourceFile("__inline_check__.ts", `(${text});`, ts17.ScriptTarget.Latest, false, ts17.ScriptKind.TS);
|
|
15928
16349
|
const stmt = sf.statements[0];
|
|
15929
|
-
if (!stmt || !
|
|
16350
|
+
if (!stmt || !ts17.isExpressionStatement(stmt))
|
|
15930
16351
|
return null;
|
|
15931
16352
|
const inner = stmt.expression;
|
|
15932
|
-
return
|
|
16353
|
+
return ts17.isParenthesizedExpression(inner) ? inner.expression : inner;
|
|
15933
16354
|
} catch {
|
|
15934
16355
|
return null;
|
|
15935
16356
|
}
|
|
@@ -15946,8 +16367,8 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
15946
16367
|
function visit3(n) {
|
|
15947
16368
|
if (found)
|
|
15948
16369
|
return;
|
|
15949
|
-
if (
|
|
15950
|
-
const accepted =
|
|
16370
|
+
if (ts17.isCallExpression(n) || ts17.isNewExpression(n)) {
|
|
16371
|
+
const accepted = ts17.isCallExpression(n) && isCallAcceptedByAdapter(n, env);
|
|
15951
16372
|
if (!accepted) {
|
|
15952
16373
|
const args = n.arguments;
|
|
15953
16374
|
if (args) {
|
|
@@ -15960,7 +16381,7 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
15960
16381
|
}
|
|
15961
16382
|
}
|
|
15962
16383
|
}
|
|
15963
|
-
|
|
16384
|
+
ts17.forEachChild(n, visit3);
|
|
15964
16385
|
}
|
|
15965
16386
|
visit3(node);
|
|
15966
16387
|
return found;
|
|
@@ -15970,13 +16391,13 @@ function hasZeroArgCall(node, env) {
|
|
|
15970
16391
|
function visit3(n) {
|
|
15971
16392
|
if (found)
|
|
15972
16393
|
return;
|
|
15973
|
-
if (
|
|
16394
|
+
if (ts17.isCallExpression(n) && n.arguments.length === 0) {
|
|
15974
16395
|
if (!isCallAcceptedByAdapter(n, env)) {
|
|
15975
16396
|
found = true;
|
|
15976
16397
|
return;
|
|
15977
16398
|
}
|
|
15978
16399
|
}
|
|
15979
|
-
|
|
16400
|
+
ts17.forEachChild(n, visit3);
|
|
15980
16401
|
}
|
|
15981
16402
|
visit3(node);
|
|
15982
16403
|
return found;
|
|
@@ -15986,25 +16407,25 @@ function containsAnyIdentifier(node, names) {
|
|
|
15986
16407
|
function visit3(n) {
|
|
15987
16408
|
if (found)
|
|
15988
16409
|
return;
|
|
15989
|
-
if (
|
|
16410
|
+
if (ts17.isPropertyAccessExpression(n)) {
|
|
15990
16411
|
visit3(n.expression);
|
|
15991
16412
|
return;
|
|
15992
16413
|
}
|
|
15993
|
-
if (
|
|
16414
|
+
if (ts17.isPropertyAssignment(n)) {
|
|
15994
16415
|
visit3(n.initializer);
|
|
15995
16416
|
return;
|
|
15996
16417
|
}
|
|
15997
|
-
if (
|
|
15998
|
-
if (
|
|
16418
|
+
if (ts17.isShorthandPropertyAssignment(n)) {
|
|
16419
|
+
if (ts17.isIdentifier(n.name) && names.has(n.name.text)) {
|
|
15999
16420
|
found = true;
|
|
16000
16421
|
}
|
|
16001
16422
|
return;
|
|
16002
16423
|
}
|
|
16003
|
-
if (
|
|
16424
|
+
if (ts17.isIdentifier(n) && names.has(n.text)) {
|
|
16004
16425
|
found = true;
|
|
16005
16426
|
return;
|
|
16006
16427
|
}
|
|
16007
|
-
|
|
16428
|
+
ts17.forEachChild(n, visit3);
|
|
16008
16429
|
}
|
|
16009
16430
|
visit3(node);
|
|
16010
16431
|
return found;
|
|
@@ -16576,12 +16997,9 @@ function emitRegistrationAndHydration(lines, ctx, _ir, graph, inlinability) {
|
|
|
16576
16997
|
lines.push("");
|
|
16577
16998
|
const propNamesForStaticCheck = new Set(ctx.propsParams.map((p) => p.name));
|
|
16578
16999
|
const { inlinableConstants, unsafeLocalNames } = inlinability ?? buildInlinableConstants(ctx, graph, _ir.root);
|
|
16579
|
-
const restSpreadNames =
|
|
16580
|
-
|
|
16581
|
-
|
|
16582
|
-
if (ctx.propsObjectName)
|
|
16583
|
-
restSpreadNames.add(ctx.propsObjectName);
|
|
16584
|
-
const isCommentScope = _ir.root.type === "fragment" && _ir.root.needsScopeComment || _ir.root.type === "component";
|
|
17000
|
+
const restSpreadNames = resolveRestSpreadNames(ctx);
|
|
17001
|
+
const isFragmentRoot = _ir.root.type === "fragment" && !!_ir.root.needsScopeComment;
|
|
17002
|
+
const isCommentScope = isFragmentRoot || _ir.root.type === "component";
|
|
16585
17003
|
const defParts = [`init: init${name}`];
|
|
16586
17004
|
if (canGenerateStaticTemplate(_ir.root, propNamesForStaticCheck, inlinableConstants, unsafeLocalNames)) {
|
|
16587
17005
|
const markupSlotIds = new Set(ctx.dynamicElements.map((e) => e.slotId));
|
|
@@ -16599,6 +17017,9 @@ function emitRegistrationAndHydration(lines, ctx, _ir, graph, inlinability) {
|
|
|
16599
17017
|
if (isCommentScope) {
|
|
16600
17018
|
defParts.push("comment: true");
|
|
16601
17019
|
}
|
|
17020
|
+
if (isFragmentRoot) {
|
|
17021
|
+
defParts.push("fragmentRoot: true");
|
|
17022
|
+
}
|
|
16602
17023
|
const registryKey = nameForRegistryRef(name);
|
|
16603
17024
|
if (registryKey !== name) {
|
|
16604
17025
|
defParts.push(`name: '${name}'`);
|
|
@@ -17291,23 +17712,23 @@ function resolveFinalImports(generatedCode, ir, localImportPrefixes) {
|
|
|
17291
17712
|
}
|
|
17292
17713
|
|
|
17293
17714
|
// ../jsx/src/ir-to-client-js/prune-unused-prop-extractions.ts
|
|
17294
|
-
import
|
|
17715
|
+
import ts18 from "typescript";
|
|
17295
17716
|
function propExtractionName(stmt) {
|
|
17296
|
-
if (!
|
|
17717
|
+
if (!ts18.isVariableStatement(stmt))
|
|
17297
17718
|
return null;
|
|
17298
17719
|
const decls = stmt.declarationList.declarations;
|
|
17299
17720
|
if (decls.length !== 1)
|
|
17300
17721
|
return null;
|
|
17301
17722
|
const decl = decls[0];
|
|
17302
|
-
if (!
|
|
17723
|
+
if (!ts18.isIdentifier(decl.name) || !decl.initializer)
|
|
17303
17724
|
return null;
|
|
17304
17725
|
let core = decl.initializer;
|
|
17305
|
-
if (
|
|
17726
|
+
if (ts18.isBinaryExpression(core) && core.operatorToken.kind === ts18.SyntaxKind.QuestionQuestionToken) {
|
|
17306
17727
|
core = core.left;
|
|
17307
17728
|
}
|
|
17308
|
-
if (!
|
|
17729
|
+
if (!ts18.isPropertyAccessExpression(core))
|
|
17309
17730
|
return null;
|
|
17310
|
-
if (!
|
|
17731
|
+
if (!ts18.isIdentifier(core.expression) || core.expression.text !== PROPS_PARAM)
|
|
17311
17732
|
return null;
|
|
17312
17733
|
if (core.name.text !== decl.name.text)
|
|
17313
17734
|
return null;
|
|
@@ -17320,10 +17741,10 @@ function pruneUnusedPropExtractions(code) {
|
|
|
17320
17741
|
console.warn("[barefootjs] pruneUnusedPropExtractions: generated code did not parse; skipping prune");
|
|
17321
17742
|
return code;
|
|
17322
17743
|
}
|
|
17323
|
-
const sourceFile =
|
|
17744
|
+
const sourceFile = ts18.createSourceFile("generated.js", code, ts18.ScriptTarget.Latest, false, ts18.ScriptKind.JS);
|
|
17324
17745
|
const spans = [];
|
|
17325
17746
|
for (const stmt of sourceFile.statements) {
|
|
17326
|
-
if (!
|
|
17747
|
+
if (!ts18.isFunctionDeclaration(stmt) || !stmt.name?.text.startsWith("init") || !stmt.body)
|
|
17327
17748
|
continue;
|
|
17328
17749
|
for (const inner of stmt.body.statements) {
|
|
17329
17750
|
const name = propExtractionName(inner);
|
|
@@ -18782,7 +19203,7 @@ function analyzeLazyConditional(cond, indexParam, arms) {
|
|
|
18782
19203
|
}
|
|
18783
19204
|
|
|
18784
19205
|
// ../jsx/src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
|
|
18785
|
-
import
|
|
19206
|
+
import ts19 from "typescript";
|
|
18786
19207
|
var NO_PREAMBLE = {
|
|
18787
19208
|
lazySafe: true,
|
|
18788
19209
|
facts: { declaredNames: new Set, freeNames: new Set }
|
|
@@ -18802,12 +19223,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
|
|
|
18802
19223
|
if (text.trim().length === 0)
|
|
18803
19224
|
return NO_PREAMBLE;
|
|
18804
19225
|
const declaredNames = new Set;
|
|
18805
|
-
const sf =
|
|
19226
|
+
const sf = ts19.createSourceFile("__lazy_preamble__.ts", text, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
|
|
18806
19227
|
for (const stmt of sf.statements) {
|
|
18807
|
-
if (!
|
|
18808
|
-
return NO2(`map-callback preamble has a non-declaration statement (${
|
|
19228
|
+
if (!ts19.isVariableStatement(stmt)) {
|
|
19229
|
+
return NO2(`map-callback preamble has a non-declaration statement (${ts19.SyntaxKind[stmt.kind]})`);
|
|
18809
19230
|
}
|
|
18810
|
-
const isConst = (stmt.declarationList.flags &
|
|
19231
|
+
const isConst = (stmt.declarationList.flags & ts19.NodeFlags.Const) !== 0;
|
|
18811
19232
|
if (!isConst)
|
|
18812
19233
|
return NO2("map-callback preamble declares a mutable binding (let/var)");
|
|
18813
19234
|
for (const decl of stmt.declarationList.declarations) {
|
|
@@ -18836,12 +19257,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
|
|
|
18836
19257
|
return { lazySafe: true, facts: { declaredNames, freeNames } };
|
|
18837
19258
|
}
|
|
18838
19259
|
function collectBindingNames3(name, out) {
|
|
18839
|
-
if (
|
|
19260
|
+
if (ts19.isIdentifier(name)) {
|
|
18840
19261
|
out.add(name.text);
|
|
18841
19262
|
return;
|
|
18842
19263
|
}
|
|
18843
19264
|
for (const element of name.elements) {
|
|
18844
|
-
if (
|
|
19265
|
+
if (ts19.isOmittedExpression(element))
|
|
18845
19266
|
continue;
|
|
18846
19267
|
collectBindingNames3(element.name, out);
|
|
18847
19268
|
}
|
|
@@ -18851,56 +19272,56 @@ function findImpureNode(root, primableNames) {
|
|
|
18851
19272
|
const visit3 = (node) => {
|
|
18852
19273
|
if (found)
|
|
18853
19274
|
return;
|
|
18854
|
-
if (
|
|
19275
|
+
if (ts19.isCallExpression(node)) {
|
|
18855
19276
|
const callee = node.expression;
|
|
18856
|
-
const isSignalRead =
|
|
19277
|
+
const isSignalRead = ts19.isIdentifier(callee) && primableNames.has(callee.text) && node.arguments.length === 0 && node.questionDotToken === undefined;
|
|
18857
19278
|
if (!isSignalRead) {
|
|
18858
19279
|
found = `call to ${callee.getText(callee.getSourceFile())}`;
|
|
18859
19280
|
return;
|
|
18860
19281
|
}
|
|
18861
19282
|
}
|
|
18862
|
-
if (
|
|
19283
|
+
if (ts19.isNewExpression(node)) {
|
|
18863
19284
|
found = "new expression";
|
|
18864
19285
|
return;
|
|
18865
19286
|
}
|
|
18866
|
-
if (
|
|
19287
|
+
if (ts19.isTaggedTemplateExpression(node)) {
|
|
18867
19288
|
found = "tagged template";
|
|
18868
19289
|
return;
|
|
18869
19290
|
}
|
|
18870
|
-
if (
|
|
19291
|
+
if (ts19.isAwaitExpression(node)) {
|
|
18871
19292
|
found = "await";
|
|
18872
19293
|
return;
|
|
18873
19294
|
}
|
|
18874
|
-
if (
|
|
19295
|
+
if (ts19.isYieldExpression(node)) {
|
|
18875
19296
|
found = "yield";
|
|
18876
19297
|
return;
|
|
18877
19298
|
}
|
|
18878
|
-
if (
|
|
19299
|
+
if (ts19.isPrefixUnaryExpression(node) || ts19.isPostfixUnaryExpression(node)) {
|
|
18879
19300
|
const op = node.operator;
|
|
18880
|
-
if (op ===
|
|
19301
|
+
if (op === ts19.SyntaxKind.PlusPlusToken || op === ts19.SyntaxKind.MinusMinusToken) {
|
|
18881
19302
|
found = "increment/decrement";
|
|
18882
19303
|
return;
|
|
18883
19304
|
}
|
|
18884
19305
|
}
|
|
18885
|
-
if (
|
|
19306
|
+
if (ts19.isDeleteExpression(node)) {
|
|
18886
19307
|
found = "delete";
|
|
18887
19308
|
return;
|
|
18888
19309
|
}
|
|
18889
|
-
if (
|
|
19310
|
+
if (ts19.isFunctionExpression(node) || ts19.isArrowFunction(node) || ts19.isClassExpression(node)) {
|
|
18890
19311
|
found = "function or class expression";
|
|
18891
19312
|
return;
|
|
18892
19313
|
}
|
|
18893
|
-
if (
|
|
19314
|
+
if (ts19.isBinaryExpression(node) && isAssignmentOperator2(node.operatorToken.kind)) {
|
|
18894
19315
|
found = "assignment";
|
|
18895
19316
|
return;
|
|
18896
19317
|
}
|
|
18897
|
-
|
|
19318
|
+
ts19.forEachChild(node, visit3);
|
|
18898
19319
|
};
|
|
18899
19320
|
visit3(root);
|
|
18900
19321
|
return found;
|
|
18901
19322
|
}
|
|
18902
19323
|
function isAssignmentOperator2(kind) {
|
|
18903
|
-
return kind >=
|
|
19324
|
+
return kind >= ts19.SyntaxKind.FirstAssignment && kind <= ts19.SyntaxKind.LastAssignment;
|
|
18904
19325
|
}
|
|
18905
19326
|
|
|
18906
19327
|
// ../jsx/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts
|
|
@@ -19430,7 +19851,7 @@ function buildArmBody(branch, options) {
|
|
|
19430
19851
|
}
|
|
19431
19852
|
|
|
19432
19853
|
// ../jsx/src/ir-to-client-js/emit-reactive.ts
|
|
19433
|
-
import
|
|
19854
|
+
import ts20 from "typescript";
|
|
19434
19855
|
|
|
19435
19856
|
// ../jsx/src/ir-to-client-js/control-flow/stringify/claim-plan.ts
|
|
19436
19857
|
function slotSpecLiteral(slot) {
|
|
@@ -19542,20 +19963,20 @@ function lowerToLocaleCallsInReactiveExpr(expr, matcher) {
|
|
|
19542
19963
|
return expr;
|
|
19543
19964
|
let sourceFile;
|
|
19544
19965
|
try {
|
|
19545
|
-
sourceFile =
|
|
19966
|
+
sourceFile = ts20.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
|
|
19546
19967
|
} catch {
|
|
19547
19968
|
return expr;
|
|
19548
19969
|
}
|
|
19549
19970
|
const stmt = sourceFile.statements[0];
|
|
19550
|
-
if (!stmt || !
|
|
19971
|
+
if (!stmt || !ts20.isExpressionStatement(stmt))
|
|
19551
19972
|
return expr;
|
|
19552
|
-
const root =
|
|
19973
|
+
const root = ts20.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19553
19974
|
const candidates = [];
|
|
19554
19975
|
const visit3 = (n) => {
|
|
19555
|
-
if (
|
|
19976
|
+
if (ts20.isCallExpression(n) && n.arguments.length === 2 && ts20.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
|
|
19556
19977
|
candidates.push(n);
|
|
19557
19978
|
}
|
|
19558
|
-
|
|
19979
|
+
ts20.forEachChild(n, visit3);
|
|
19559
19980
|
};
|
|
19560
19981
|
visit3(root);
|
|
19561
19982
|
if (candidates.length === 0)
|
|
@@ -19591,20 +20012,20 @@ function lowerDateCallsInReactiveExpr(expr, matcher) {
|
|
|
19591
20012
|
return expr;
|
|
19592
20013
|
let sourceFile;
|
|
19593
20014
|
try {
|
|
19594
|
-
sourceFile =
|
|
20015
|
+
sourceFile = ts20.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
|
|
19595
20016
|
} catch {
|
|
19596
20017
|
return expr;
|
|
19597
20018
|
}
|
|
19598
20019
|
const stmt = sourceFile.statements[0];
|
|
19599
|
-
if (!stmt || !
|
|
20020
|
+
if (!stmt || !ts20.isExpressionStatement(stmt))
|
|
19600
20021
|
return expr;
|
|
19601
|
-
const root =
|
|
20022
|
+
const root = ts20.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19602
20023
|
const candidates = [];
|
|
19603
20024
|
const visit3 = (n) => {
|
|
19604
|
-
if (
|
|
20025
|
+
if (ts20.isCallExpression(n) && n.arguments.length === 0 && ts20.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
19605
20026
|
candidates.push(n);
|
|
19606
20027
|
}
|
|
19607
|
-
|
|
20028
|
+
ts20.forEachChild(n, visit3);
|
|
19608
20029
|
};
|
|
19609
20030
|
visit3(root);
|
|
19610
20031
|
if (candidates.length === 0)
|
|
@@ -19843,7 +20264,7 @@ function stringifyBranchInnerLoops(lines, plan, indent, pc) {
|
|
|
19843
20264
|
lines.push(`${indent} let __bel${uid} = __existing ?? (() => { const __t = document.createElement('template'); __t.innerHTML = \`${innerHtml}\`; return __t.content${childPath}.cloneNode(true) })()`);
|
|
19844
20265
|
}
|
|
19845
20266
|
if (inner.wrappedKey) {
|
|
19846
|
-
lines.push(`${indent} __bel${uid}.setAttribute('${
|
|
20267
|
+
lines.push(`${indent} __bel${uid}.setAttribute('${keyAttrName2(inner.keyDepth)}', String(${inner.wrappedKey}))`);
|
|
19847
20268
|
}
|
|
19848
20269
|
if (inner.legacyComponents.length > 0 || inner.legacyEvents.length > 0) {
|
|
19849
20270
|
emitComponentAndEventSetup(lines, `${indent} `, `__bel${uid}`, [...inner.legacyComponents], [...inner.legacyEvents], inner.outerLoopParam, inner.outerLoopParamBindings);
|
|
@@ -19866,7 +20287,7 @@ function stringifyBranchInnerLoops(lines, plan, indent, pc) {
|
|
|
19866
20287
|
stringifyLoopChildConditionals(lines, inner.nestedConditionals, `${indent} `, pc);
|
|
19867
20288
|
}
|
|
19868
20289
|
lines.push(`${indent} return __bel${uid}`);
|
|
19869
|
-
lines.push(`${indent}}, '${inner.markerId}'${profileBindingId(pc, inner.slotId)}) }`);
|
|
20290
|
+
lines.push(`${indent}}, '${inner.markerId}'${mapArrayKeyArgs(profileBindingId(pc, inner.slotId), !!inner.wrappedKey, inner.keyDepth)}) }`);
|
|
19870
20291
|
}
|
|
19871
20292
|
}
|
|
19872
20293
|
function stringifyLoopChildConditionals(lines, conditionals, indent, pc) {
|
|
@@ -20675,7 +21096,7 @@ function emitReactive(lines, inner, indent, pc) {
|
|
|
20675
21096
|
lines.push(`${indent} let __innerEl${uid} = __existing ?? (() => { const __t = document.createElement('template'); __t.innerHTML = \`${innerHtml}\`; return __t.content${childPath}.cloneNode(true) })()`);
|
|
20676
21097
|
}
|
|
20677
21098
|
if (emit.wrappedKey) {
|
|
20678
|
-
lines.push(`${indent} __innerEl${uid}.setAttribute('${
|
|
21099
|
+
lines.push(`${indent} __innerEl${uid}.setAttribute('${keyAttrName2(inner.keyDepth)}', String(${emit.wrappedKey}))`);
|
|
20679
21100
|
}
|
|
20680
21101
|
if (emit.components.length > 0 || emit.events.length > 0) {
|
|
20681
21102
|
emitComponentAndEventSetup(lines, `${indent} `, `__innerEl${uid}`, [...emit.components], [...emit.events], inner.outerLoopParam, inner.outerLoopParamBindings);
|
|
@@ -20715,7 +21136,7 @@ function emitReactive(lines, inner, indent, pc) {
|
|
|
20715
21136
|
bodyIsMultiRoot: emit.bodyIsMultiRoot
|
|
20716
21137
|
});
|
|
20717
21138
|
lines.push(`${indent} return __innerEl${uid}`);
|
|
20718
|
-
lines.push(`${indent}}, '${inner.markerId}'${profileBindingId(pc, inner.slotId)}) }`);
|
|
21139
|
+
lines.push(`${indent}}, '${inner.markerId}'${mapArrayKeyArgs(profileBindingId(pc, inner.slotId), !!emit.wrappedKey, inner.keyDepth)}) }`);
|
|
20719
21140
|
}
|
|
20720
21141
|
function emitStatic(lines, inner, indent, pc) {
|
|
20721
21142
|
const uid = inner.uidSuffix;
|
|
@@ -20731,7 +21152,7 @@ function emitStatic(lines, inner, indent, pc) {
|
|
|
20731
21152
|
lines.push(`${indent} ${stmt}`);
|
|
20732
21153
|
}
|
|
20733
21154
|
if (emit.rawKey) {
|
|
20734
|
-
lines.push(`${indent} __innerEl${uid}.setAttribute('${
|
|
21155
|
+
lines.push(`${indent} __innerEl${uid}.setAttribute('${keyAttrName2(inner.keyDepth)}', String(${emit.rawKey}))`);
|
|
20735
21156
|
}
|
|
20736
21157
|
emitComponentAndEventSetup(lines, `${indent} `, `__innerEl${uid}`, [...emit.components], [...emit.events], inner.outerLoopParam, inner.outerLoopParamBindings);
|
|
20737
21158
|
if (inner.childLevels.length > 0) {
|
|
@@ -20919,7 +21340,7 @@ function emitKeyedLookup(ls, ev, handlerCall, lookup) {
|
|
|
20919
21340
|
}
|
|
20920
21341
|
const evVar = varSlotId(ev.childSlotId);
|
|
20921
21342
|
for (const nested of ev.nestedLoops) {
|
|
20922
|
-
const dataAttr =
|
|
21343
|
+
const dataAttr = keyAttrName2(nested.depth);
|
|
20923
21344
|
ls.push(` const innerLi${nested.depth} = ${evVar}El.closest('[${dataAttr}]')`);
|
|
20924
21345
|
ls.push(` const innerKey${nested.depth} = innerLi${nested.depth}?.getAttribute('${dataAttr}')`);
|
|
20925
21346
|
}
|
|
@@ -21625,20 +22046,28 @@ var PHASES = [
|
|
|
21625
22046
|
];
|
|
21626
22047
|
|
|
21627
22048
|
// ../jsx/src/ir-to-client-js/rewrite-props-object.ts
|
|
21628
|
-
import
|
|
21629
|
-
function rewritePropsObjectRef(code, propsObjectName) {
|
|
21630
|
-
|
|
21631
|
-
|
|
21632
|
-
|
|
22049
|
+
import ts21 from "typescript";
|
|
22050
|
+
function rewritePropsObjectRef(code, propsObjectName, restPropsName = null) {
|
|
22051
|
+
let result = code;
|
|
22052
|
+
const seen = new Set;
|
|
22053
|
+
for (const srcPropsName of [propsObjectName ?? "props", restPropsName]) {
|
|
22054
|
+
if (srcPropsName === null || srcPropsName === PROPS_PARAM || seen.has(srcPropsName))
|
|
22055
|
+
continue;
|
|
22056
|
+
seen.add(srcPropsName);
|
|
22057
|
+
result = rewriteOneName(result, srcPropsName);
|
|
22058
|
+
}
|
|
22059
|
+
return result;
|
|
22060
|
+
}
|
|
22061
|
+
function rewriteOneName(code, srcPropsName) {
|
|
21633
22062
|
if (!identifierPattern(srcPropsName).test(code))
|
|
21634
22063
|
return code;
|
|
21635
|
-
const sourceFile =
|
|
22064
|
+
const sourceFile = ts21.createSourceFile("init-body.ts", code, ts21.ScriptTarget.Latest, true, ts21.ScriptKind.TS);
|
|
21636
22065
|
const spans = [];
|
|
21637
22066
|
function visit3(node) {
|
|
21638
|
-
if (
|
|
22067
|
+
if (ts21.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
|
|
21639
22068
|
spans.push([node.getStart(sourceFile), node.getEnd()]);
|
|
21640
22069
|
}
|
|
21641
|
-
|
|
22070
|
+
ts21.forEachChild(node, visit3);
|
|
21642
22071
|
}
|
|
21643
22072
|
visit3(sourceFile);
|
|
21644
22073
|
if (spans.length === 0)
|
|
@@ -21654,17 +22083,17 @@ function shouldRewrite(node) {
|
|
|
21654
22083
|
const parent = node.parent;
|
|
21655
22084
|
if (!parent)
|
|
21656
22085
|
return true;
|
|
21657
|
-
if (
|
|
22086
|
+
if (ts21.isPropertyAccessExpression(parent) && parent.name === node)
|
|
21658
22087
|
return false;
|
|
21659
|
-
if (
|
|
22088
|
+
if (ts21.isPropertyAssignment(parent) && parent.name === node)
|
|
21660
22089
|
return false;
|
|
21661
|
-
if (
|
|
22090
|
+
if (ts21.isShorthandPropertyAssignment(parent) && parent.name === node)
|
|
21662
22091
|
return false;
|
|
21663
|
-
if (
|
|
22092
|
+
if (ts21.isPropertySignature(parent) && parent.name === node)
|
|
21664
22093
|
return false;
|
|
21665
|
-
if (
|
|
22094
|
+
if (ts21.isPropertyDeclaration(parent) && parent.name === node)
|
|
21666
22095
|
return false;
|
|
21667
|
-
if (
|
|
22096
|
+
if (ts21.isBindingElement(parent) && parent.name === node)
|
|
21668
22097
|
return false;
|
|
21669
22098
|
return true;
|
|
21670
22099
|
}
|
|
@@ -21697,7 +22126,7 @@ function generateInitFunction(ir, ctx, siblingComponents, localImportPrefixes) {
|
|
|
21697
22126
|
runPhases(lines, phaseCtx, PHASES);
|
|
21698
22127
|
const hydrateLine = emitRegistrationAndHydration(lines, ctx, ir, graph, inlinability);
|
|
21699
22128
|
let generatedCode = rewritePropsObjectRef(lines.join(`
|
|
21700
|
-
`), ctx.propsObjectName);
|
|
22129
|
+
`), ctx.propsObjectName, ctx.restPropsName);
|
|
21701
22130
|
generatedCode += `
|
|
21702
22131
|
` + hydrateLine;
|
|
21703
22132
|
const moduleConstantsCode = emitModuleLevelDeclarations(classification.moduleLevelConstants, classification.moduleLevelFunctions, classification.moduleLevelSignals, classification.moduleLevelMemos);
|
|
@@ -21975,7 +22404,7 @@ function createContext(ir, scope, adapterCapabilities, profile) {
|
|
|
21975
22404
|
};
|
|
21976
22405
|
}
|
|
21977
22406
|
function needsClientJs(ctx) {
|
|
21978
|
-
if (ctx.signals.length > 0 || ctx.memos.length > 0 || ctx.effects.length > 0 || ctx.onMounts.length > 0 || ctx.initStatements.length > 0 || ctx.interactiveElements.length > 0 || ctx.dynamicElements.length > 0 || ctx.conditionalElements.length > 0 || ctx.loopElements.length > 0 || ctx.refElements.length > 0 || ctx.childInits.length > 0 || ctx.reactiveAttrs.length > 0 || ctx.clientOnlyElements.length > 0 || ctx.clientOnlyConditionals.length > 0 || ctx.providerSetups.length > 0)
|
|
22407
|
+
if (ctx.signals.length > 0 || ctx.memos.length > 0 || ctx.effects.length > 0 || ctx.onMounts.length > 0 || ctx.initStatements.length > 0 || ctx.interactiveElements.length > 0 || ctx.dynamicElements.length > 0 || ctx.conditionalElements.length > 0 || ctx.loopElements.length > 0 || ctx.refElements.length > 0 || ctx.restAttrElements.length > 0 || ctx.childInits.length > 0 || ctx.reactiveAttrs.length > 0 || ctx.clientOnlyElements.length > 0 || ctx.clientOnlyConditionals.length > 0 || ctx.providerSetups.length > 0)
|
|
21979
22408
|
return true;
|
|
21980
22409
|
return hasInitScopeOnlyConstant(ctx);
|
|
21981
22410
|
}
|
|
@@ -21997,11 +22426,7 @@ function generateTemplateOnlyMount(ir, ctx) {
|
|
|
21997
22426
|
const propNamesForStaticCheck = new Set(ctx.propsParams.map((p) => p.name));
|
|
21998
22427
|
const graph = buildReferencesGraph(ctx, ir.root);
|
|
21999
22428
|
const { inlinableConstants, unsafeLocalNames } = buildInlinableConstants(ctx, graph, ir.root);
|
|
22000
|
-
const restSpreadNames =
|
|
22001
|
-
if (ctx.restPropsName)
|
|
22002
|
-
restSpreadNames.add(ctx.restPropsName);
|
|
22003
|
-
if (ctx.propsObjectName)
|
|
22004
|
-
restSpreadNames.add(ctx.propsObjectName);
|
|
22429
|
+
const restSpreadNames = resolveRestSpreadNames(ctx);
|
|
22005
22430
|
let templateHtml;
|
|
22006
22431
|
if (canGenerateStaticTemplate(ir.root, propNamesForStaticCheck, inlinableConstants, unsafeLocalNames)) {
|
|
22007
22432
|
const markupSlotIds = new Set(ctx.dynamicElements.map((e) => e.slotId));
|
|
@@ -22317,7 +22742,7 @@ function walkIR2(node, visitor) {
|
|
|
22317
22742
|
}
|
|
22318
22743
|
|
|
22319
22744
|
// ../jsx/src/preprocess-inline-jsx-callbacks.ts
|
|
22320
|
-
import
|
|
22745
|
+
import ts22 from "typescript";
|
|
22321
22746
|
var SYNTHETIC_PREFIX = "BFInlineJsxCallback";
|
|
22322
22747
|
var MAX_FIXPOINT_ITERATIONS = 16;
|
|
22323
22748
|
function preprocessInlineJsxCallbacks(source, filePath) {
|
|
@@ -22339,8 +22764,8 @@ function preprocessInlineJsxCallbacks(source, filePath) {
|
|
|
22339
22764
|
return { source: current, errors, syntheticNames };
|
|
22340
22765
|
}
|
|
22341
22766
|
function runSinglePass(source, filePath, startingCounter) {
|
|
22342
|
-
const sourceFile =
|
|
22343
|
-
const hasUseClient = sourceFile.statements.some((stmt) =>
|
|
22767
|
+
const sourceFile = ts22.createSourceFile(filePath, source, ts22.ScriptTarget.Latest, true, ts22.ScriptKind.TSX);
|
|
22768
|
+
const hasUseClient = sourceFile.statements.some((stmt) => ts22.isExpressionStatement(stmt) && ts22.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
|
|
22344
22769
|
if (!hasUseClient) {
|
|
22345
22770
|
return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
|
|
22346
22771
|
}
|
|
@@ -22362,22 +22787,22 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22362
22787
|
}
|
|
22363
22788
|
}
|
|
22364
22789
|
function visit3(node) {
|
|
22365
|
-
if (
|
|
22790
|
+
if (ts22.isJsxAttribute(node) && node.initializer && ts22.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
22366
22791
|
if (tryHandleArrowValue(node.initializer.expression)) {
|
|
22367
22792
|
return;
|
|
22368
22793
|
}
|
|
22369
22794
|
}
|
|
22370
|
-
if (
|
|
22795
|
+
if (ts22.isPropertyAssignment(node) && node.initializer) {
|
|
22371
22796
|
if (tryHandleArrowValue(node.initializer))
|
|
22372
22797
|
return;
|
|
22373
22798
|
}
|
|
22374
|
-
|
|
22799
|
+
ts22.forEachChild(node, visit3);
|
|
22375
22800
|
}
|
|
22376
22801
|
function tryHandleArrowValue(initializer) {
|
|
22377
22802
|
let expr = initializer;
|
|
22378
|
-
while (
|
|
22803
|
+
while (ts22.isParenthesizedExpression(expr))
|
|
22379
22804
|
expr = expr.expression;
|
|
22380
|
-
if (
|
|
22805
|
+
if (ts22.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
|
|
22381
22806
|
return handleInlineArrow(expr);
|
|
22382
22807
|
}
|
|
22383
22808
|
return false;
|
|
@@ -22414,7 +22839,7 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22414
22839
|
replacements.push({ start: arrowStart, end: arrowEnd, text: name });
|
|
22415
22840
|
return true;
|
|
22416
22841
|
}
|
|
22417
|
-
|
|
22842
|
+
ts22.forEachChild(sourceFile, visit3);
|
|
22418
22843
|
if (replacements.length === 0) {
|
|
22419
22844
|
return { source, errors, syntheticNames, counterAfter: counter };
|
|
22420
22845
|
}
|
|
@@ -22437,11 +22862,11 @@ function errorMessageForCapture(captures) {
|
|
|
22437
22862
|
return `Inline JSX-returning arrow function captures non-module identifier(s): ` + `${captures.sort().join(", ")}. ` + `Extract the callback into a top-level '\\'use client\\'' component (e.g. ` + `\`function MyNode(n) { return <div/> }\` then \`renderNode={MyNode}\`) ` + `or pass captured values via component props.`;
|
|
22438
22863
|
}
|
|
22439
22864
|
function arrowBodyContainsJsx(arrow) {
|
|
22440
|
-
if (
|
|
22865
|
+
if (ts22.isBlock(arrow.body)) {
|
|
22441
22866
|
return blockReturnsJsx(arrow.body);
|
|
22442
22867
|
}
|
|
22443
22868
|
let body = arrow.body;
|
|
22444
|
-
while (
|
|
22869
|
+
while (ts22.isParenthesizedExpression(body))
|
|
22445
22870
|
body = body.expression;
|
|
22446
22871
|
return isJsxLike(body);
|
|
22447
22872
|
}
|
|
@@ -22450,24 +22875,24 @@ function blockReturnsJsx(block) {
|
|
|
22450
22875
|
function visit3(n) {
|
|
22451
22876
|
if (found)
|
|
22452
22877
|
return;
|
|
22453
|
-
if (
|
|
22878
|
+
if (ts22.isReturnStatement(n) && n.expression) {
|
|
22454
22879
|
let e = n.expression;
|
|
22455
|
-
while (
|
|
22880
|
+
while (ts22.isParenthesizedExpression(e))
|
|
22456
22881
|
e = e.expression;
|
|
22457
22882
|
if (isJsxLike(e)) {
|
|
22458
22883
|
found = true;
|
|
22459
22884
|
return;
|
|
22460
22885
|
}
|
|
22461
22886
|
}
|
|
22462
|
-
if (
|
|
22887
|
+
if (ts22.isArrowFunction(n) || ts22.isFunctionDeclaration(n) || ts22.isFunctionExpression(n))
|
|
22463
22888
|
return;
|
|
22464
|
-
|
|
22889
|
+
ts22.forEachChild(n, visit3);
|
|
22465
22890
|
}
|
|
22466
|
-
|
|
22891
|
+
ts22.forEachChild(block, visit3);
|
|
22467
22892
|
return found;
|
|
22468
22893
|
}
|
|
22469
22894
|
function isJsxLike(expr) {
|
|
22470
|
-
return
|
|
22895
|
+
return ts22.isJsxElement(expr) || ts22.isJsxSelfClosingElement(expr) || ts22.isJsxFragment(expr);
|
|
22471
22896
|
}
|
|
22472
22897
|
function collectArrowParamNames(arrow) {
|
|
22473
22898
|
const names = new Set;
|
|
@@ -22477,13 +22902,13 @@ function collectArrowParamNames(arrow) {
|
|
|
22477
22902
|
}
|
|
22478
22903
|
function collectBindingNames4(name, out) {
|
|
22479
22904
|
const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
|
|
22480
|
-
if (
|
|
22905
|
+
if (ts22.isIdentifier(name)) {
|
|
22481
22906
|
push(name.text);
|
|
22482
|
-
} else if (
|
|
22907
|
+
} else if (ts22.isObjectBindingPattern(name)) {
|
|
22483
22908
|
name.elements.forEach((el) => collectBindingNames4(el.name, out));
|
|
22484
|
-
} else if (
|
|
22909
|
+
} else if (ts22.isArrayBindingPattern(name)) {
|
|
22485
22910
|
name.elements.forEach((el) => {
|
|
22486
|
-
if (!
|
|
22911
|
+
if (!ts22.isOmittedExpression(el))
|
|
22487
22912
|
collectBindingNames4(el.name, out);
|
|
22488
22913
|
});
|
|
22489
22914
|
}
|
|
@@ -22510,48 +22935,48 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22510
22935
|
return bound.includes(name);
|
|
22511
22936
|
}
|
|
22512
22937
|
function visit3(node) {
|
|
22513
|
-
if (
|
|
22938
|
+
if (ts22.isIdentifier(node)) {
|
|
22514
22939
|
const parent = node.parent;
|
|
22515
|
-
if (parent &&
|
|
22940
|
+
if (parent && ts22.isPropertyAccessExpression(parent) && parent.name === node)
|
|
22516
22941
|
return;
|
|
22517
|
-
if (parent &&
|
|
22942
|
+
if (parent && ts22.isPropertyAssignment(parent) && parent.name === node)
|
|
22518
22943
|
return;
|
|
22519
|
-
if (parent &&
|
|
22944
|
+
if (parent && ts22.isPropertySignature(parent) && parent.name === node)
|
|
22520
22945
|
return;
|
|
22521
|
-
if (parent &&
|
|
22946
|
+
if (parent && ts22.isPropertyDeclaration(parent) && parent.name === node)
|
|
22522
22947
|
return;
|
|
22523
|
-
if (parent &&
|
|
22948
|
+
if (parent && ts22.isMethodDeclaration(parent) && parent.name === node)
|
|
22524
22949
|
return;
|
|
22525
|
-
if (parent &&
|
|
22950
|
+
if (parent && ts22.isMethodSignature(parent) && parent.name === node)
|
|
22526
22951
|
return;
|
|
22527
|
-
if (parent &&
|
|
22952
|
+
if (parent && ts22.isGetAccessorDeclaration(parent) && parent.name === node)
|
|
22528
22953
|
return;
|
|
22529
|
-
if (parent &&
|
|
22954
|
+
if (parent && ts22.isSetAccessorDeclaration(parent) && parent.name === node)
|
|
22530
22955
|
return;
|
|
22531
|
-
if (parent &&
|
|
22956
|
+
if (parent && ts22.isEnumMember(parent) && parent.name === node)
|
|
22532
22957
|
return;
|
|
22533
|
-
if (parent &&
|
|
22958
|
+
if (parent && ts22.isBindingElement(parent) && parent.propertyName === node)
|
|
22534
22959
|
return;
|
|
22535
|
-
if (parent &&
|
|
22960
|
+
if (parent && ts22.isShorthandPropertyAssignment(parent) && parent.name === node) {
|
|
22536
22961
|
if (!isBound(node.text))
|
|
22537
22962
|
ids.add(node.text);
|
|
22538
22963
|
return;
|
|
22539
22964
|
}
|
|
22540
|
-
if (parent &&
|
|
22965
|
+
if (parent && ts22.isParameter(parent) && parent.name === node)
|
|
22541
22966
|
return;
|
|
22542
|
-
if (parent &&
|
|
22967
|
+
if (parent && ts22.isVariableDeclaration(parent) && parent.name === node)
|
|
22543
22968
|
return;
|
|
22544
|
-
if (parent &&
|
|
22969
|
+
if (parent && ts22.isFunctionDeclaration(parent) && parent.name === node)
|
|
22545
22970
|
return;
|
|
22546
|
-
if (parent &&
|
|
22971
|
+
if (parent && ts22.isClassDeclaration(parent) && parent.name === node)
|
|
22547
22972
|
return;
|
|
22548
|
-
if (parent &&
|
|
22973
|
+
if (parent && ts22.isJsxAttribute(parent) && parent.name === node)
|
|
22549
22974
|
return;
|
|
22550
|
-
if (parent &&
|
|
22975
|
+
if (parent && ts22.isJsxOpeningElement(parent) && parent.tagName === node) {
|
|
22551
22976
|
if (/^[a-z]/.test(node.text))
|
|
22552
22977
|
return;
|
|
22553
22978
|
}
|
|
22554
|
-
if (parent &&
|
|
22979
|
+
if (parent && ts22.isJsxClosingElement(parent) && parent.tagName === node) {
|
|
22555
22980
|
if (/^[a-z]/.test(node.text))
|
|
22556
22981
|
return;
|
|
22557
22982
|
}
|
|
@@ -22560,43 +22985,43 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22560
22985
|
ids.add(node.text);
|
|
22561
22986
|
return;
|
|
22562
22987
|
}
|
|
22563
|
-
if (
|
|
22988
|
+
if (ts22.isVariableDeclaration(node)) {
|
|
22564
22989
|
const declared = pushBindings(node.name);
|
|
22565
22990
|
if (node.initializer)
|
|
22566
22991
|
visit3(node.initializer);
|
|
22567
22992
|
return;
|
|
22568
22993
|
}
|
|
22569
|
-
if (
|
|
22994
|
+
if (ts22.isFunctionDeclaration(node)) {
|
|
22570
22995
|
if (node.name)
|
|
22571
22996
|
bound.push(node.name.text);
|
|
22572
22997
|
visitInsideNewScope(node);
|
|
22573
22998
|
return;
|
|
22574
22999
|
}
|
|
22575
|
-
if (
|
|
23000
|
+
if (ts22.isClassDeclaration(node)) {
|
|
22576
23001
|
if (node.name)
|
|
22577
23002
|
bound.push(node.name.text);
|
|
22578
|
-
|
|
23003
|
+
ts22.forEachChild(node, visit3);
|
|
22579
23004
|
return;
|
|
22580
23005
|
}
|
|
22581
|
-
if (
|
|
23006
|
+
if (ts22.isArrowFunction(node) || ts22.isFunctionExpression(node)) {
|
|
22582
23007
|
visitInsideNewScope(node);
|
|
22583
23008
|
return;
|
|
22584
23009
|
}
|
|
22585
|
-
if (
|
|
23010
|
+
if (ts22.isCatchClause(node)) {
|
|
22586
23011
|
const before = bound.length;
|
|
22587
23012
|
if (node.variableDeclaration)
|
|
22588
23013
|
pushBindings(node.variableDeclaration.name);
|
|
22589
|
-
|
|
23014
|
+
ts22.forEachChild(node, visit3);
|
|
22590
23015
|
popN(bound.length - before);
|
|
22591
23016
|
return;
|
|
22592
23017
|
}
|
|
22593
|
-
if (
|
|
23018
|
+
if (ts22.isBlock(node)) {
|
|
22594
23019
|
const before = bound.length;
|
|
22595
|
-
|
|
23020
|
+
ts22.forEachChild(node, visit3);
|
|
22596
23021
|
popN(bound.length - before);
|
|
22597
23022
|
return;
|
|
22598
23023
|
}
|
|
22599
|
-
|
|
23024
|
+
ts22.forEachChild(node, visit3);
|
|
22600
23025
|
}
|
|
22601
23026
|
function visitInsideNewScope(fn) {
|
|
22602
23027
|
const before = bound.length;
|
|
@@ -22619,29 +23044,29 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22619
23044
|
function collectModuleScopeNames(sourceFile) {
|
|
22620
23045
|
const names = new Set;
|
|
22621
23046
|
for (const stmt of sourceFile.statements) {
|
|
22622
|
-
if (
|
|
23047
|
+
if (ts22.isFunctionDeclaration(stmt) && stmt.name)
|
|
22623
23048
|
names.add(stmt.name.text);
|
|
22624
|
-
else if (
|
|
23049
|
+
else if (ts22.isClassDeclaration(stmt) && stmt.name)
|
|
22625
23050
|
names.add(stmt.name.text);
|
|
22626
|
-
else if (
|
|
23051
|
+
else if (ts22.isVariableStatement(stmt)) {
|
|
22627
23052
|
for (const decl of stmt.declarationList.declarations)
|
|
22628
23053
|
collectBindingNames4(decl.name, names);
|
|
22629
|
-
} else if (
|
|
23054
|
+
} else if (ts22.isImportDeclaration(stmt) && stmt.importClause) {
|
|
22630
23055
|
const ic = stmt.importClause;
|
|
22631
23056
|
if (ic.name)
|
|
22632
23057
|
names.add(ic.name.text);
|
|
22633
23058
|
if (ic.namedBindings) {
|
|
22634
|
-
if (
|
|
23059
|
+
if (ts22.isNamespaceImport(ic.namedBindings))
|
|
22635
23060
|
names.add(ic.namedBindings.name.text);
|
|
22636
23061
|
else
|
|
22637
23062
|
for (const e of ic.namedBindings.elements)
|
|
22638
23063
|
names.add(e.name.text);
|
|
22639
23064
|
}
|
|
22640
|
-
} else if (
|
|
23065
|
+
} else if (ts22.isTypeAliasDeclaration(stmt))
|
|
22641
23066
|
names.add(stmt.name.text);
|
|
22642
|
-
else if (
|
|
23067
|
+
else if (ts22.isInterfaceDeclaration(stmt))
|
|
22643
23068
|
names.add(stmt.name.text);
|
|
22644
|
-
else if (
|
|
23069
|
+
else if (ts22.isEnumDeclaration(stmt))
|
|
22645
23070
|
names.add(stmt.name.text);
|
|
22646
23071
|
}
|
|
22647
23072
|
return names;
|
|
@@ -22649,7 +23074,7 @@ function collectModuleScopeNames(sourceFile) {
|
|
|
22649
23074
|
function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
22650
23075
|
const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
|
|
22651
23076
|
let bodyText;
|
|
22652
|
-
if (
|
|
23077
|
+
if (ts22.isBlock(arrow.body)) {
|
|
22653
23078
|
bodyText = arrow.body.getText(sourceFile);
|
|
22654
23079
|
} else {
|
|
22655
23080
|
const expr = arrow.body.getText(sourceFile);
|
|
@@ -22659,7 +23084,7 @@ function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
|
22659
23084
|
}
|
|
22660
23085
|
|
|
22661
23086
|
// ../jsx/src/ssr-defaults.ts
|
|
22662
|
-
import
|
|
23087
|
+
import ts23 from "typescript";
|
|
22663
23088
|
var UNRESOLVED = Symbol("unresolved");
|
|
22664
23089
|
var NO_RETURN = Symbol("no-return");
|
|
22665
23090
|
function extractSsrDefaults(metadata) {
|
|
@@ -22763,11 +23188,11 @@ function collectPropRefs(expr, propsObjectName, out) {
|
|
|
22763
23188
|
if (!node)
|
|
22764
23189
|
return;
|
|
22765
23190
|
const visit3 = (n) => {
|
|
22766
|
-
if (
|
|
23191
|
+
if (ts23.isPropertyAccessExpression(n) && ts23.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts23.isIdentifier(n.name)) {
|
|
22767
23192
|
out.add(n.name.text);
|
|
22768
23193
|
return;
|
|
22769
23194
|
}
|
|
22770
|
-
|
|
23195
|
+
ts23.forEachChild(n, visit3);
|
|
22771
23196
|
};
|
|
22772
23197
|
visit3(node);
|
|
22773
23198
|
}
|
|
@@ -22805,23 +23230,23 @@ function tryStaticEval(expr, ctx) {
|
|
|
22805
23230
|
}
|
|
22806
23231
|
function evalStatementsForReturn(statements, ctx) {
|
|
22807
23232
|
for (const stmt of statements) {
|
|
22808
|
-
if (
|
|
23233
|
+
if (ts23.isVariableStatement(stmt)) {
|
|
22809
23234
|
for (const d of stmt.declarationList.declarations) {
|
|
22810
|
-
if (!
|
|
23235
|
+
if (!ts23.isIdentifier(d.name) || !d.initializer)
|
|
22811
23236
|
continue;
|
|
22812
23237
|
const v = evalNode(d.initializer, ctx);
|
|
22813
23238
|
if (v !== UNRESOLVED)
|
|
22814
23239
|
ctx.bindings[d.name.text] = v;
|
|
22815
23240
|
}
|
|
22816
|
-
} else if (
|
|
23241
|
+
} else if (ts23.isReturnStatement(stmt)) {
|
|
22817
23242
|
return stmt.expression ? evalNode(stmt.expression, ctx) : UNRESOLVED;
|
|
22818
|
-
} else if (
|
|
23243
|
+
} else if (ts23.isIfStatement(stmt)) {
|
|
22819
23244
|
const cond = evalNode(stmt.expression, ctx);
|
|
22820
23245
|
if (cond === UNRESOLVED)
|
|
22821
23246
|
return UNRESOLVED;
|
|
22822
23247
|
const branch = cond ? stmt.thenStatement : stmt.elseStatement;
|
|
22823
23248
|
if (branch) {
|
|
22824
|
-
const taken = evalStatementsForReturn(
|
|
23249
|
+
const taken = evalStatementsForReturn(ts23.isBlock(branch) ? branch.statements : [branch], ctx);
|
|
22825
23250
|
if (taken !== NO_RETURN)
|
|
22826
23251
|
return taken;
|
|
22827
23252
|
}
|
|
@@ -22832,45 +23257,45 @@ function evalStatementsForReturn(statements, ctx) {
|
|
|
22832
23257
|
return NO_RETURN;
|
|
22833
23258
|
}
|
|
22834
23259
|
function parseExpression2(expr) {
|
|
22835
|
-
const sf =
|
|
23260
|
+
const sf = ts23.createSourceFile("__ssr_default__.ts", `(${expr})`, ts23.ScriptTarget.Latest, true, ts23.ScriptKind.TS);
|
|
22836
23261
|
const stmt = sf.statements[0];
|
|
22837
|
-
if (!stmt || !
|
|
23262
|
+
if (!stmt || !ts23.isExpressionStatement(stmt))
|
|
22838
23263
|
return null;
|
|
22839
|
-
const inner =
|
|
23264
|
+
const inner = ts23.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
22840
23265
|
return inner;
|
|
22841
23266
|
}
|
|
22842
23267
|
function evalNode(node, ctx) {
|
|
22843
|
-
if (
|
|
23268
|
+
if (ts23.isParenthesizedExpression(node))
|
|
22844
23269
|
return evalNode(node.expression, ctx);
|
|
22845
|
-
if (
|
|
23270
|
+
if (ts23.isAsExpression(node))
|
|
22846
23271
|
return evalNode(node.expression, ctx);
|
|
22847
|
-
if (
|
|
23272
|
+
if (ts23.isSatisfiesExpression(node))
|
|
22848
23273
|
return evalNode(node.expression, ctx);
|
|
22849
|
-
if (
|
|
23274
|
+
if (ts23.isTypeAssertionExpression(node))
|
|
22850
23275
|
return evalNode(node.expression, ctx);
|
|
22851
|
-
if (
|
|
23276
|
+
if (ts23.isNonNullExpression(node))
|
|
22852
23277
|
return evalNode(node.expression, ctx);
|
|
22853
|
-
if (
|
|
23278
|
+
if (ts23.isArrowFunction(node)) {
|
|
22854
23279
|
if (node.parameters.length !== 0)
|
|
22855
23280
|
return UNRESOLVED;
|
|
22856
|
-
if (!
|
|
23281
|
+
if (!ts23.isBlock(node.body))
|
|
22857
23282
|
return evalNode(node.body, ctx);
|
|
22858
23283
|
const localBindings = { ...ctx.bindings };
|
|
22859
23284
|
const localCtx = { ...ctx, bindings: localBindings };
|
|
22860
23285
|
const result = evalStatementsForReturn(node.body.statements, localCtx);
|
|
22861
23286
|
return result === NO_RETURN ? UNRESOLVED : result;
|
|
22862
23287
|
}
|
|
22863
|
-
if (
|
|
23288
|
+
if (ts23.isNumericLiteral(node))
|
|
22864
23289
|
return Number(node.text);
|
|
22865
|
-
if (
|
|
23290
|
+
if (ts23.isStringLiteralLike(node))
|
|
22866
23291
|
return node.text;
|
|
22867
|
-
if (node.kind ===
|
|
23292
|
+
if (node.kind === ts23.SyntaxKind.TrueKeyword)
|
|
22868
23293
|
return true;
|
|
22869
|
-
if (node.kind ===
|
|
23294
|
+
if (node.kind === ts23.SyntaxKind.FalseKeyword)
|
|
22870
23295
|
return false;
|
|
22871
|
-
if (node.kind ===
|
|
23296
|
+
if (node.kind === ts23.SyntaxKind.NullKeyword)
|
|
22872
23297
|
return null;
|
|
22873
|
-
if (
|
|
23298
|
+
if (ts23.isIdentifier(node)) {
|
|
22874
23299
|
if (node.text === "undefined")
|
|
22875
23300
|
return;
|
|
22876
23301
|
if (node.text in ctx.bindings)
|
|
@@ -22879,29 +23304,29 @@ function evalNode(node, ctx) {
|
|
|
22879
23304
|
return;
|
|
22880
23305
|
return UNRESOLVED;
|
|
22881
23306
|
}
|
|
22882
|
-
if (
|
|
23307
|
+
if (ts23.isPrefixUnaryExpression(node)) {
|
|
22883
23308
|
const arg = evalNode(node.operand, ctx);
|
|
22884
23309
|
if (arg === UNRESOLVED)
|
|
22885
23310
|
return UNRESOLVED;
|
|
22886
23311
|
switch (node.operator) {
|
|
22887
|
-
case
|
|
23312
|
+
case ts23.SyntaxKind.MinusToken:
|
|
22888
23313
|
return typeof arg === "number" ? -arg : UNRESOLVED;
|
|
22889
|
-
case
|
|
23314
|
+
case ts23.SyntaxKind.PlusToken:
|
|
22890
23315
|
return typeof arg === "number" ? +arg : UNRESOLVED;
|
|
22891
|
-
case
|
|
23316
|
+
case ts23.SyntaxKind.ExclamationToken:
|
|
22892
23317
|
return !arg;
|
|
22893
23318
|
}
|
|
22894
23319
|
return UNRESOLVED;
|
|
22895
23320
|
}
|
|
22896
|
-
if (
|
|
23321
|
+
if (ts23.isObjectLiteralExpression(node)) {
|
|
22897
23322
|
const obj = {};
|
|
22898
23323
|
for (const prop of node.properties) {
|
|
22899
|
-
if (!
|
|
23324
|
+
if (!ts23.isPropertyAssignment(prop))
|
|
22900
23325
|
return UNRESOLVED;
|
|
22901
23326
|
let key;
|
|
22902
|
-
if (
|
|
23327
|
+
if (ts23.isIdentifier(prop.name) || ts23.isStringLiteralLike(prop.name)) {
|
|
22903
23328
|
key = prop.name.text;
|
|
22904
|
-
} else if (
|
|
23329
|
+
} else if (ts23.isNumericLiteral(prop.name)) {
|
|
22905
23330
|
key = prop.name.text;
|
|
22906
23331
|
} else {
|
|
22907
23332
|
return UNRESOLVED;
|
|
@@ -22913,10 +23338,10 @@ function evalNode(node, ctx) {
|
|
|
22913
23338
|
}
|
|
22914
23339
|
return obj;
|
|
22915
23340
|
}
|
|
22916
|
-
if (
|
|
23341
|
+
if (ts23.isArrayLiteralExpression(node)) {
|
|
22917
23342
|
const arr = [];
|
|
22918
23343
|
for (const elem of node.elements) {
|
|
22919
|
-
if (
|
|
23344
|
+
if (ts23.isOmittedExpression(elem))
|
|
22920
23345
|
return UNRESOLVED;
|
|
22921
23346
|
const v = evalNode(elem, ctx);
|
|
22922
23347
|
if (v === UNRESOLVED)
|
|
@@ -22925,7 +23350,7 @@ function evalNode(node, ctx) {
|
|
|
22925
23350
|
}
|
|
22926
23351
|
return arr;
|
|
22927
23352
|
}
|
|
22928
|
-
if (
|
|
23353
|
+
if (ts23.isElementAccessExpression(node)) {
|
|
22929
23354
|
const base = evalNode(node.expression, ctx);
|
|
22930
23355
|
if (base === undefined)
|
|
22931
23356
|
return;
|
|
@@ -22939,7 +23364,7 @@ function evalNode(node, ctx) {
|
|
|
22939
23364
|
const k = String(key);
|
|
22940
23365
|
return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
|
|
22941
23366
|
}
|
|
22942
|
-
if (
|
|
23367
|
+
if (ts23.isPropertyAccessExpression(node)) {
|
|
22943
23368
|
const baseResult = evalNode(node.expression, ctx);
|
|
22944
23369
|
if (baseResult === undefined)
|
|
22945
23370
|
return;
|
|
@@ -22952,13 +23377,13 @@ function evalNode(node, ctx) {
|
|
|
22952
23377
|
const key = node.name.text;
|
|
22953
23378
|
return Object.prototype.hasOwnProperty.call(baseResult, key) ? baseResult[key] : undefined;
|
|
22954
23379
|
}
|
|
22955
|
-
if (
|
|
22956
|
-
if (node.arguments.length === 0 &&
|
|
23380
|
+
if (ts23.isCallExpression(node)) {
|
|
23381
|
+
if (node.arguments.length === 0 && ts23.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
|
|
22957
23382
|
return ctx.bindings[node.expression.text];
|
|
22958
23383
|
}
|
|
22959
|
-
if (
|
|
23384
|
+
if (ts23.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map" && node.arguments.length === 1) {
|
|
22960
23385
|
const arrow = node.arguments[0];
|
|
22961
|
-
if (
|
|
23386
|
+
if (ts23.isArrowFunction(arrow) && arrow.parameters.length === 1 && ts23.isIdentifier(arrow.parameters[0].name) && !ts23.isBlock(arrow.body)) {
|
|
22962
23387
|
const recv = evalNode(node.expression.expression, ctx);
|
|
22963
23388
|
if (Array.isArray(recv)) {
|
|
22964
23389
|
const paramName = arrow.parameters[0].name.text;
|
|
@@ -22975,7 +23400,7 @@ function evalNode(node, ctx) {
|
|
|
22975
23400
|
}
|
|
22976
23401
|
return UNRESOLVED;
|
|
22977
23402
|
}
|
|
22978
|
-
if (
|
|
23403
|
+
if (ts23.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
|
|
22979
23404
|
const recv = evalNode(node.expression.expression, ctx);
|
|
22980
23405
|
if (Array.isArray(recv)) {
|
|
22981
23406
|
let sep = ",";
|
|
@@ -22991,27 +23416,27 @@ function evalNode(node, ctx) {
|
|
|
22991
23416
|
}
|
|
22992
23417
|
return UNRESOLVED;
|
|
22993
23418
|
}
|
|
22994
|
-
if (
|
|
23419
|
+
if (ts23.isConditionalExpression(node)) {
|
|
22995
23420
|
const cond = evalNode(node.condition, ctx);
|
|
22996
23421
|
if (cond === UNRESOLVED)
|
|
22997
23422
|
return UNRESOLVED;
|
|
22998
23423
|
return cond ? evalNode(node.whenTrue, ctx) : evalNode(node.whenFalse, ctx);
|
|
22999
23424
|
}
|
|
23000
|
-
if (
|
|
23425
|
+
if (ts23.isBinaryExpression(node)) {
|
|
23001
23426
|
const op = node.operatorToken.kind;
|
|
23002
|
-
if (op ===
|
|
23427
|
+
if (op === ts23.SyntaxKind.QuestionQuestionToken) {
|
|
23003
23428
|
const l2 = evalNode(node.left, ctx);
|
|
23004
23429
|
if (l2 !== UNRESOLVED && l2 !== null && l2 !== undefined)
|
|
23005
23430
|
return l2;
|
|
23006
23431
|
return evalNode(node.right, ctx);
|
|
23007
23432
|
}
|
|
23008
|
-
if (op ===
|
|
23433
|
+
if (op === ts23.SyntaxKind.BarBarToken) {
|
|
23009
23434
|
const l2 = evalNode(node.left, ctx);
|
|
23010
23435
|
if (l2 !== UNRESOLVED && l2)
|
|
23011
23436
|
return l2;
|
|
23012
23437
|
return evalNode(node.right, ctx);
|
|
23013
23438
|
}
|
|
23014
|
-
if (op ===
|
|
23439
|
+
if (op === ts23.SyntaxKind.AmpersandAmpersandToken) {
|
|
23015
23440
|
const l2 = evalNode(node.left, ctx);
|
|
23016
23441
|
if (l2 === UNRESOLVED)
|
|
23017
23442
|
return UNRESOLVED;
|
|
@@ -23024,30 +23449,30 @@ function evalNode(node, ctx) {
|
|
|
23024
23449
|
if (l === UNRESOLVED || r === UNRESOLVED)
|
|
23025
23450
|
return UNRESOLVED;
|
|
23026
23451
|
switch (op) {
|
|
23027
|
-
case
|
|
23452
|
+
case ts23.SyntaxKind.PlusToken:
|
|
23028
23453
|
if (typeof l === "string" || typeof r === "string")
|
|
23029
23454
|
return `${l}${r}`;
|
|
23030
23455
|
if (typeof l === "number" && typeof r === "number")
|
|
23031
23456
|
return l + r;
|
|
23032
23457
|
return UNRESOLVED;
|
|
23033
|
-
case
|
|
23458
|
+
case ts23.SyntaxKind.MinusToken:
|
|
23034
23459
|
return typeof l === "number" && typeof r === "number" ? l - r : UNRESOLVED;
|
|
23035
|
-
case
|
|
23460
|
+
case ts23.SyntaxKind.AsteriskToken:
|
|
23036
23461
|
return typeof l === "number" && typeof r === "number" ? l * r : UNRESOLVED;
|
|
23037
|
-
case
|
|
23462
|
+
case ts23.SyntaxKind.SlashToken:
|
|
23038
23463
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l / r : UNRESOLVED;
|
|
23039
|
-
case
|
|
23464
|
+
case ts23.SyntaxKind.PercentToken:
|
|
23040
23465
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l % r : UNRESOLVED;
|
|
23041
|
-
case
|
|
23042
|
-
case
|
|
23466
|
+
case ts23.SyntaxKind.EqualsEqualsEqualsToken:
|
|
23467
|
+
case ts23.SyntaxKind.EqualsEqualsToken:
|
|
23043
23468
|
return l === r;
|
|
23044
|
-
case
|
|
23045
|
-
case
|
|
23469
|
+
case ts23.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
23470
|
+
case ts23.SyntaxKind.ExclamationEqualsToken:
|
|
23046
23471
|
return l !== r;
|
|
23047
23472
|
}
|
|
23048
23473
|
return UNRESOLVED;
|
|
23049
23474
|
}
|
|
23050
|
-
if (
|
|
23475
|
+
if (ts23.isTemplateExpression(node)) {
|
|
23051
23476
|
if (node.templateSpans.length === 0)
|
|
23052
23477
|
return node.head.text;
|
|
23053
23478
|
let acc = node.head.text;
|
|
@@ -23059,41 +23484,41 @@ function evalNode(node, ctx) {
|
|
|
23059
23484
|
}
|
|
23060
23485
|
return acc;
|
|
23061
23486
|
}
|
|
23062
|
-
if (
|
|
23487
|
+
if (ts23.isNoSubstitutionTemplateLiteral(node))
|
|
23063
23488
|
return node.text;
|
|
23064
23489
|
return UNRESOLVED;
|
|
23065
23490
|
}
|
|
23066
23491
|
|
|
23067
23492
|
// ../jsx/src/augment-inherited-props.ts
|
|
23068
|
-
import
|
|
23493
|
+
import ts24 from "typescript";
|
|
23069
23494
|
function parseStaticStringConst(source) {
|
|
23070
|
-
const sf =
|
|
23495
|
+
const sf = ts24.createSourceFile("__const.ts", `const __x = (${source});`, ts24.ScriptTarget.Latest, false);
|
|
23071
23496
|
const stmt = sf.statements[0];
|
|
23072
|
-
if (!stmt || !
|
|
23497
|
+
if (!stmt || !ts24.isVariableStatement(stmt))
|
|
23073
23498
|
return null;
|
|
23074
23499
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
23075
|
-
while (init &&
|
|
23500
|
+
while (init && ts24.isParenthesizedExpression(init))
|
|
23076
23501
|
init = init.expression;
|
|
23077
23502
|
if (!init)
|
|
23078
23503
|
return null;
|
|
23079
|
-
if (
|
|
23504
|
+
if (ts24.isStringLiteral(init) || ts24.isNoSubstitutionTemplateLiteral(init)) {
|
|
23080
23505
|
return init.text;
|
|
23081
23506
|
}
|
|
23082
23507
|
return evalStringArrayJoin(source);
|
|
23083
23508
|
}
|
|
23084
23509
|
function evalTemplateOfStringConsts(source, resolved) {
|
|
23085
|
-
const sf =
|
|
23510
|
+
const sf = ts24.createSourceFile("__const.ts", `const __x = (${source});`, ts24.ScriptTarget.Latest, false);
|
|
23086
23511
|
const stmt = sf.statements[0];
|
|
23087
|
-
if (!stmt || !
|
|
23512
|
+
if (!stmt || !ts24.isVariableStatement(stmt))
|
|
23088
23513
|
return null;
|
|
23089
23514
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
23090
|
-
while (init &&
|
|
23515
|
+
while (init && ts24.isParenthesizedExpression(init))
|
|
23091
23516
|
init = init.expression;
|
|
23092
|
-
if (!init || !
|
|
23517
|
+
if (!init || !ts24.isTemplateExpression(init))
|
|
23093
23518
|
return null;
|
|
23094
23519
|
let out = init.head.text;
|
|
23095
23520
|
for (const span of init.templateSpans) {
|
|
23096
|
-
if (!
|
|
23521
|
+
if (!ts24.isIdentifier(span.expression))
|
|
23097
23522
|
return null;
|
|
23098
23523
|
const value = resolved.get(span.expression.text);
|
|
23099
23524
|
if (value === undefined)
|
|
@@ -23121,28 +23546,28 @@ function collectModuleStringConsts(constants) {
|
|
|
23121
23546
|
return map;
|
|
23122
23547
|
}
|
|
23123
23548
|
function evalStringArrayJoin(source) {
|
|
23124
|
-
const sf =
|
|
23549
|
+
const sf = ts24.createSourceFile("__join.ts", `const __x = (${source});`, ts24.ScriptTarget.Latest, false);
|
|
23125
23550
|
const stmt = sf.statements[0];
|
|
23126
|
-
if (!stmt || !
|
|
23551
|
+
if (!stmt || !ts24.isVariableStatement(stmt))
|
|
23127
23552
|
return null;
|
|
23128
23553
|
let node = stmt.declarationList.declarations[0]?.initializer;
|
|
23129
|
-
while (node &&
|
|
23554
|
+
while (node && ts24.isParenthesizedExpression(node))
|
|
23130
23555
|
node = node.expression;
|
|
23131
|
-
if (!node || !
|
|
23556
|
+
if (!node || !ts24.isCallExpression(node))
|
|
23132
23557
|
return null;
|
|
23133
23558
|
const callee = node.expression;
|
|
23134
|
-
if (!
|
|
23559
|
+
if (!ts24.isPropertyAccessExpression(callee))
|
|
23135
23560
|
return null;
|
|
23136
23561
|
if (callee.name.text !== "join")
|
|
23137
23562
|
return null;
|
|
23138
23563
|
let recv = callee.expression;
|
|
23139
|
-
while (
|
|
23564
|
+
while (ts24.isParenthesizedExpression(recv))
|
|
23140
23565
|
recv = recv.expression;
|
|
23141
|
-
if (!
|
|
23566
|
+
if (!ts24.isArrayLiteralExpression(recv))
|
|
23142
23567
|
return null;
|
|
23143
23568
|
const parts = [];
|
|
23144
23569
|
for (const el of recv.elements) {
|
|
23145
|
-
if (
|
|
23570
|
+
if (ts24.isStringLiteral(el) || ts24.isNoSubstitutionTemplateLiteral(el)) {
|
|
23146
23571
|
parts.push(el.text);
|
|
23147
23572
|
} else {
|
|
23148
23573
|
return null;
|
|
@@ -23151,7 +23576,7 @@ function evalStringArrayJoin(source) {
|
|
|
23151
23576
|
let sep = ",";
|
|
23152
23577
|
if (node.arguments.length >= 1) {
|
|
23153
23578
|
const arg = node.arguments[0];
|
|
23154
|
-
if (
|
|
23579
|
+
if (ts24.isStringLiteral(arg) || ts24.isNoSubstitutionTemplateLiteral(arg))
|
|
23155
23580
|
sep = arg.text;
|
|
23156
23581
|
else
|
|
23157
23582
|
return null;
|
|
@@ -23511,31 +23936,54 @@ function walkNode2(node, meta, bindings, matchers, errors, seen) {
|
|
|
23511
23936
|
function mergeTemplateImports(lines) {
|
|
23512
23937
|
const result = [];
|
|
23513
23938
|
const valueIdx = new Map;
|
|
23939
|
+
const valueDefault = new Map;
|
|
23514
23940
|
const valueNames = new Map;
|
|
23515
23941
|
const typeIdx = new Map;
|
|
23516
23942
|
const typeNames = new Map;
|
|
23517
23943
|
const seenOther = new Set;
|
|
23518
|
-
const
|
|
23519
|
-
if (!
|
|
23520
|
-
|
|
23521
|
-
|
|
23944
|
+
const foldType = (src, rawNames) => {
|
|
23945
|
+
if (!typeIdx.has(src)) {
|
|
23946
|
+
typeIdx.set(src, result.length);
|
|
23947
|
+
typeNames.set(src, new Set);
|
|
23522
23948
|
result.push("");
|
|
23523
23949
|
}
|
|
23524
|
-
const set =
|
|
23950
|
+
const set = typeNames.get(src);
|
|
23525
23951
|
for (const n of rawNames.split(",").map((s) => s.trim()).filter(Boolean))
|
|
23526
23952
|
set.add(n);
|
|
23527
|
-
result[
|
|
23953
|
+
result[typeIdx.get(src)] = `import type { ${[...set].join(", ")} } from '${src}'`;
|
|
23954
|
+
};
|
|
23955
|
+
const foldValue = (src, defaultName, rawNames) => {
|
|
23956
|
+
if (!valueIdx.has(src)) {
|
|
23957
|
+
valueIdx.set(src, result.length);
|
|
23958
|
+
valueNames.set(src, new Set);
|
|
23959
|
+
result.push("");
|
|
23960
|
+
}
|
|
23961
|
+
if (defaultName && !valueDefault.has(src))
|
|
23962
|
+
valueDefault.set(src, defaultName);
|
|
23963
|
+
if (rawNames) {
|
|
23964
|
+
const set = valueNames.get(src);
|
|
23965
|
+
for (const n of rawNames.split(",").map((s) => s.trim()).filter(Boolean))
|
|
23966
|
+
set.add(n);
|
|
23967
|
+
}
|
|
23968
|
+
result[valueIdx.get(src)] = renderUsedImportLines(src, valueDefault.get(src) ?? null, null, [...valueNames.get(src)]).join(`
|
|
23969
|
+
`);
|
|
23528
23970
|
};
|
|
23529
23971
|
for (const raw of lines) {
|
|
23530
23972
|
const line = raw.trim();
|
|
23531
23973
|
if (!line)
|
|
23532
23974
|
continue;
|
|
23533
23975
|
const typeMatch = line.match(/^import\s+type\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]\s*;?$/);
|
|
23534
|
-
const
|
|
23535
|
-
|
|
23536
|
-
|
|
23537
|
-
|
|
23538
|
-
|
|
23976
|
+
const namedMatch = line.match(/^import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]\s*;?$/);
|
|
23977
|
+
const defaultNamedMatch = line.match(/^import\s+([A-Za-z_$][\w$]*)\s*,\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]\s*;?$/);
|
|
23978
|
+
const defaultOnlyMatch = line.match(/^import\s+([A-Za-z_$][\w$]*)\s*from\s*['"]([^'"]+)['"]\s*;?$/);
|
|
23979
|
+
if (typeMatch) {
|
|
23980
|
+
foldType(typeMatch[2], typeMatch[1]);
|
|
23981
|
+
} else if (namedMatch) {
|
|
23982
|
+
foldValue(namedMatch[2], null, namedMatch[1]);
|
|
23983
|
+
} else if (defaultNamedMatch) {
|
|
23984
|
+
foldValue(defaultNamedMatch[3], defaultNamedMatch[1], defaultNamedMatch[2]);
|
|
23985
|
+
} else if (defaultOnlyMatch) {
|
|
23986
|
+
foldValue(defaultOnlyMatch[2], defaultOnlyMatch[1], null);
|
|
23539
23987
|
} else if (!seenOther.has(line)) {
|
|
23540
23988
|
seenOther.add(line);
|
|
23541
23989
|
result.push(line);
|
|
@@ -23577,13 +24025,13 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23577
24025
|
if (entries.some((e) => e.componentIR.metadata.isClientComponent)) {
|
|
23578
24026
|
const topLevelNames = new Set;
|
|
23579
24027
|
{
|
|
23580
|
-
const sf =
|
|
24028
|
+
const sf = ts25.createSourceFile(filePath, source, ts25.ScriptTarget.Latest, true, ts25.ScriptKind.TSX);
|
|
23581
24029
|
for (const stmt of sf.statements) {
|
|
23582
|
-
if (
|
|
24030
|
+
if (ts25.isFunctionDeclaration(stmt) && stmt.name)
|
|
23583
24031
|
topLevelNames.add(stmt.name.text);
|
|
23584
|
-
else if (
|
|
24032
|
+
else if (ts25.isVariableStatement(stmt)) {
|
|
23585
24033
|
for (const d of stmt.declarationList.declarations) {
|
|
23586
|
-
if (
|
|
24034
|
+
if (ts25.isIdentifier(d.name))
|
|
23587
24035
|
topLevelNames.add(d.name.text);
|
|
23588
24036
|
}
|
|
23589
24037
|
}
|
|
@@ -23642,7 +24090,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23642
24090
|
const moduleStatementSeen = new Set;
|
|
23643
24091
|
const moduleStatementsOrdered = [];
|
|
23644
24092
|
const collectModuleStatements = (block) => {
|
|
23645
|
-
const sf =
|
|
24093
|
+
const sf = ts25.createSourceFile("__bf_module_decls.tsx", block, ts25.ScriptTarget.Latest, false, ts25.ScriptKind.TSX);
|
|
23646
24094
|
for (const stmt of sf.statements) {
|
|
23647
24095
|
const text = stmt.getText(sf);
|
|
23648
24096
|
if (moduleStatementSeen.has(text))
|
|
@@ -23731,32 +24179,9 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23731
24179
|
}
|
|
23732
24180
|
const clientJsOutputs2 = allOutputs.map((o) => o.clientJs).filter(Boolean);
|
|
23733
24181
|
if (clientJsOutputs2.length > 0) {
|
|
23734
|
-
const importsBySource = new Map;
|
|
23735
|
-
const otherImports = [];
|
|
23736
|
-
const allCode = [];
|
|
23737
|
-
for (const js of clientJsOutputs2) {
|
|
23738
|
-
for (const line of js.split(`
|
|
23739
|
-
`)) {
|
|
23740
|
-
if (line.startsWith("import ")) {
|
|
23741
|
-
const match = line.match(/^import \{ ([^}]+) \} from ['"]([^'"]+)['"]$/);
|
|
23742
|
-
if (match) {
|
|
23743
|
-
const source2 = match[2];
|
|
23744
|
-
if (!importsBySource.has(source2))
|
|
23745
|
-
importsBySource.set(source2, new Set);
|
|
23746
|
-
for (const n of match[1].split(",").map((n2) => n2.trim()))
|
|
23747
|
-
importsBySource.get(source2).add(n);
|
|
23748
|
-
} else if (!otherImports.includes(line)) {
|
|
23749
|
-
otherImports.push(line);
|
|
23750
|
-
}
|
|
23751
|
-
}
|
|
23752
|
-
}
|
|
23753
|
-
allCode.push(js.replace(/^import .+\n/gm, "").trim());
|
|
23754
|
-
}
|
|
23755
|
-
const mergedClientImports = [...importsBySource].map(([src, names]) => `import { ${[...names].sort().join(", ")} } from '${src}'`);
|
|
23756
24182
|
files.push({
|
|
23757
24183
|
path: filePath.replace(/\.tsx?$/, ".client.js"),
|
|
23758
|
-
content:
|
|
23759
|
-
`),
|
|
24184
|
+
content: mergeCompiledClientJsImports(clientJsOutputs2),
|
|
23760
24185
|
type: "clientJs"
|
|
23761
24186
|
});
|
|
23762
24187
|
}
|
|
@@ -23827,53 +24252,9 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23827
24252
|
}
|
|
23828
24253
|
const clientJsOutputs = allOutputs.map((o) => o.clientJs).filter(Boolean);
|
|
23829
24254
|
if (clientJsOutputs.length > 0) {
|
|
23830
|
-
const importsBySource = new Map;
|
|
23831
|
-
const otherImports = [];
|
|
23832
|
-
const allCode = [];
|
|
23833
|
-
for (const js of clientJsOutputs) {
|
|
23834
|
-
const lines = js.split(`
|
|
23835
|
-
`);
|
|
23836
|
-
const codeLines = [];
|
|
23837
|
-
for (const line of lines) {
|
|
23838
|
-
if (line.startsWith("import ")) {
|
|
23839
|
-
const match = line.match(/^import \{ ([^}]+) \} from ['"]([^'"]+)['"]$/);
|
|
23840
|
-
if (match) {
|
|
23841
|
-
const names = match[1].split(",").map((n) => n.trim());
|
|
23842
|
-
const source2 = match[2];
|
|
23843
|
-
if (!importsBySource.has(source2)) {
|
|
23844
|
-
importsBySource.set(source2, new Set);
|
|
23845
|
-
}
|
|
23846
|
-
const set = importsBySource.get(source2);
|
|
23847
|
-
for (const name of names) {
|
|
23848
|
-
set.add(name);
|
|
23849
|
-
}
|
|
23850
|
-
} else {
|
|
23851
|
-
if (!otherImports.includes(line)) {
|
|
23852
|
-
otherImports.push(line);
|
|
23853
|
-
}
|
|
23854
|
-
}
|
|
23855
|
-
} else {
|
|
23856
|
-
codeLines.push(line);
|
|
23857
|
-
}
|
|
23858
|
-
}
|
|
23859
|
-
allCode.push(codeLines.join(`
|
|
23860
|
-
`).trim());
|
|
23861
|
-
}
|
|
23862
|
-
const mergedImports2 = [];
|
|
23863
|
-
for (const [source2, names] of importsBySource) {
|
|
23864
|
-
const sortedNames = [...names].sort();
|
|
23865
|
-
mergedImports2.push(`import { ${sortedNames.join(", ")} } from '${source2}'`);
|
|
23866
|
-
}
|
|
23867
|
-
const combinedClientJs = [
|
|
23868
|
-
...mergedImports2,
|
|
23869
|
-
...otherImports,
|
|
23870
|
-
"",
|
|
23871
|
-
...allCode.filter(Boolean)
|
|
23872
|
-
].join(`
|
|
23873
|
-
`);
|
|
23874
24255
|
files.push({
|
|
23875
24256
|
path: filePath.replace(/\.tsx?$/, ".client.js"),
|
|
23876
|
-
content:
|
|
24257
|
+
content: mergeCompiledClientJsImports(clientJsOutputs),
|
|
23877
24258
|
type: "clientJs"
|
|
23878
24259
|
});
|
|
23879
24260
|
}
|
|
@@ -23946,10 +24327,24 @@ function compileJSX(source, filePath, options) {
|
|
|
23946
24327
|
externalImportLines.push(`import '${imp.source}'`);
|
|
23947
24328
|
continue;
|
|
23948
24329
|
}
|
|
23949
|
-
const
|
|
23950
|
-
|
|
23951
|
-
|
|
24330
|
+
const usedNamed = [];
|
|
24331
|
+
let usedDefault = null;
|
|
24332
|
+
let usedNamespace = null;
|
|
24333
|
+
for (const s2 of imp.specifiers) {
|
|
24334
|
+
if (s2.isTypeOnly)
|
|
24335
|
+
continue;
|
|
24336
|
+
const localName = s2.alias || s2.name;
|
|
24337
|
+
if (!isUsedAsValue(localName))
|
|
24338
|
+
continue;
|
|
24339
|
+
if (s2.isDefault) {
|
|
24340
|
+
usedDefault = localName;
|
|
24341
|
+
} else if (s2.isNamespace) {
|
|
24342
|
+
usedNamespace = localName;
|
|
24343
|
+
} else {
|
|
24344
|
+
usedNamed.push(s2.alias ? `${s2.name} as ${s2.alias}` : s2.name);
|
|
24345
|
+
}
|
|
23952
24346
|
}
|
|
24347
|
+
externalImportLines.push(...renderUsedImportLines(imp.source, usedDefault, usedNamespace, usedNamed));
|
|
23953
24348
|
}
|
|
23954
24349
|
const allImports = [runtimeImportLine, ...externalImportLines].filter(Boolean).join(`
|
|
23955
24350
|
`);
|
|
@@ -24085,7 +24480,7 @@ function compileJSX(source, filePath, options) {
|
|
|
24085
24480
|
return { files, errors };
|
|
24086
24481
|
}
|
|
24087
24482
|
// ../jsx/src/shared-program.ts
|
|
24088
|
-
import
|
|
24483
|
+
import ts26 from "typescript";
|
|
24089
24484
|
import path3 from "node:path";
|
|
24090
24485
|
function commonParent(paths) {
|
|
24091
24486
|
if (paths.length === 0)
|
|
@@ -24107,10 +24502,10 @@ function commonParent(paths) {
|
|
|
24107
24502
|
function createProgramForCorpus(files, options = {}) {
|
|
24108
24503
|
const baseUrl = options.baseUrl ?? commonParent(files);
|
|
24109
24504
|
const compilerOptions = {
|
|
24110
|
-
target:
|
|
24111
|
-
module:
|
|
24112
|
-
moduleResolution:
|
|
24113
|
-
jsx:
|
|
24505
|
+
target: ts26.ScriptTarget.Latest,
|
|
24506
|
+
module: ts26.ModuleKind.ESNext,
|
|
24507
|
+
moduleResolution: ts26.ModuleResolutionKind.Bundler,
|
|
24508
|
+
jsx: ts26.JsxEmit.ReactJSX,
|
|
24114
24509
|
strict: true,
|
|
24115
24510
|
skipLibCheck: true,
|
|
24116
24511
|
noEmit: true,
|
|
@@ -24120,7 +24515,7 @@ function createProgramForCorpus(files, options = {}) {
|
|
|
24120
24515
|
...options.compilerOptions
|
|
24121
24516
|
};
|
|
24122
24517
|
const absolute = files.map((f) => path3.resolve(f));
|
|
24123
|
-
return
|
|
24518
|
+
return ts26.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
|
|
24124
24519
|
}
|
|
24125
24520
|
// ../jsx/src/adapters/interface.ts
|
|
24126
24521
|
class BaseAdapter {
|
|
@@ -24403,7 +24798,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
24403
24798
|
}
|
|
24404
24799
|
|
|
24405
24800
|
// ../jsx/src/adapters/template-imports.ts
|
|
24406
|
-
import
|
|
24801
|
+
import ts27 from "typescript";
|
|
24407
24802
|
var CLIENT_PACKAGE_SOURCES = new Set([
|
|
24408
24803
|
"@barefootjs/client",
|
|
24409
24804
|
"@barefootjs/client/runtime"
|
|
@@ -24796,11 +25191,11 @@ function registerBuiltinLoweringPlugins() {
|
|
|
24796
25191
|
registerLoweringPlugin(plugin);
|
|
24797
25192
|
}
|
|
24798
25193
|
// ../jsx/src/combine-client-js.ts
|
|
24799
|
-
import ts27 from "typescript";
|
|
24800
|
-
// ../jsx/src/debug.ts
|
|
24801
25194
|
import ts28 from "typescript";
|
|
24802
|
-
// ../jsx/src/
|
|
25195
|
+
// ../jsx/src/debug.ts
|
|
24803
25196
|
import ts29 from "typescript";
|
|
25197
|
+
// ../jsx/src/profiler.ts
|
|
25198
|
+
import ts30 from "typescript";
|
|
24804
25199
|
|
|
24805
25200
|
// ../jsx/src/index.ts
|
|
24806
25201
|
registerBuiltinLoweringPlugins();
|
|
@@ -24939,21 +25334,24 @@ async function discoverComponents(entries, readFile) {
|
|
|
24939
25334
|
seen.add(absPath);
|
|
24940
25335
|
const content = await readFile(absPath);
|
|
24941
25336
|
const isClient = hasUseClientDirective(content);
|
|
25337
|
+
const scan = scanComponentFile(content, absPath);
|
|
24942
25338
|
out.push({
|
|
24943
25339
|
absPath,
|
|
24944
25340
|
content,
|
|
24945
25341
|
isClient,
|
|
24946
|
-
exportedComponents:
|
|
25342
|
+
exportedComponents: scan.exports,
|
|
25343
|
+
referencedComponents: scan.referencedComponents,
|
|
24947
25344
|
cssLayerPrefix: entry.cssLayerPrefix
|
|
24948
25345
|
});
|
|
24949
25346
|
}
|
|
24950
25347
|
}
|
|
24951
|
-
|
|
25348
|
+
const clientEntryPaths = computeClientEntryPaths(out);
|
|
25349
|
+
return out.map((row) => ({ ...row, needsClientEntry: clientEntryPaths.has(row.absPath) }));
|
|
24952
25350
|
}
|
|
24953
|
-
function
|
|
25351
|
+
function nameIndexOver(rows, include) {
|
|
24954
25352
|
const index = new Map;
|
|
24955
|
-
for (const c of
|
|
24956
|
-
if (!c
|
|
25353
|
+
for (const c of rows) {
|
|
25354
|
+
if (!include(c))
|
|
24957
25355
|
continue;
|
|
24958
25356
|
const names = c.exportedComponents.length > 0 ? c.exportedComponents : [basename(c.absPath).replace(/\.tsx?$/, "")];
|
|
24959
25357
|
for (const name of names) {
|
|
@@ -24963,6 +25361,44 @@ function buildChildNameIndex(discovered) {
|
|
|
24963
25361
|
}
|
|
24964
25362
|
return index;
|
|
24965
25363
|
}
|
|
25364
|
+
function computeClientEntryPaths(rows) {
|
|
25365
|
+
const nameToPath = nameIndexOver(rows, () => true);
|
|
25366
|
+
const referencers = new Map;
|
|
25367
|
+
for (const row of rows) {
|
|
25368
|
+
for (const name of row.referencedComponents) {
|
|
25369
|
+
const target = nameToPath.get(name);
|
|
25370
|
+
if (!target || target === row.absPath)
|
|
25371
|
+
continue;
|
|
25372
|
+
let set = referencers.get(target);
|
|
25373
|
+
if (!set) {
|
|
25374
|
+
set = new Set;
|
|
25375
|
+
referencers.set(target, set);
|
|
25376
|
+
}
|
|
25377
|
+
set.add(row.absPath);
|
|
25378
|
+
}
|
|
25379
|
+
}
|
|
25380
|
+
const visited = new Set;
|
|
25381
|
+
const queue = [];
|
|
25382
|
+
for (const row of rows) {
|
|
25383
|
+
if (row.isClient && !visited.has(row.absPath)) {
|
|
25384
|
+
visited.add(row.absPath);
|
|
25385
|
+
queue.push(row.absPath);
|
|
25386
|
+
}
|
|
25387
|
+
}
|
|
25388
|
+
while (queue.length > 0) {
|
|
25389
|
+
const current = queue.shift();
|
|
25390
|
+
for (const referencer of referencers.get(current) ?? []) {
|
|
25391
|
+
if (visited.has(referencer))
|
|
25392
|
+
continue;
|
|
25393
|
+
visited.add(referencer);
|
|
25394
|
+
queue.push(referencer);
|
|
25395
|
+
}
|
|
25396
|
+
}
|
|
25397
|
+
return visited;
|
|
25398
|
+
}
|
|
25399
|
+
function buildChildNameIndex(discovered) {
|
|
25400
|
+
return nameIndexOver(discovered, (c) => c.needsClientEntry);
|
|
25401
|
+
}
|
|
24966
25402
|
|
|
24967
25403
|
// src/resolve-client-js.ts
|
|
24968
25404
|
import { existsSync } from "node:fs";
|
|
@@ -25297,7 +25733,7 @@ function barefoot(options) {
|
|
|
25297
25733
|
const canonical = compileCanonical(component.absPath, content);
|
|
25298
25734
|
reportErrors(canonical, content, projectDir);
|
|
25299
25735
|
let result = canonical;
|
|
25300
|
-
if (component.
|
|
25736
|
+
if (component.needsClientEntry) {
|
|
25301
25737
|
const { scriptAssets, preloadAssets } = resolveAssetsFor(component);
|
|
25302
25738
|
if (scriptAssets.length > 0) {
|
|
25303
25739
|
result = compileJSX(content, component.absPath, {
|
|
@@ -25383,7 +25819,7 @@ function barefoot(options) {
|
|
|
25383
25819
|
const found = await discoverComponents(guessedEntries, (absPath) => readFile2(absPath, "utf8"));
|
|
25384
25820
|
const input = {};
|
|
25385
25821
|
for (const c of found) {
|
|
25386
|
-
if (!c.
|
|
25822
|
+
if (!c.needsClientEntry)
|
|
25387
25823
|
continue;
|
|
25388
25824
|
input[safeRollupEntryName(guessedRoot, c.absPath, dirs)] = c.absPath;
|
|
25389
25825
|
}
|