@barefootjs/vite 0.33.2 → 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 +742 -384
- 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;
|
|
@@ -10611,7 +10731,9 @@ function markDataKeyCarrier(children) {
|
|
|
10611
10731
|
}
|
|
10612
10732
|
function markCarrierIn(node) {
|
|
10613
10733
|
if (node.type === "element") {
|
|
10614
|
-
|
|
10734
|
+
if (node.keyAttr)
|
|
10735
|
+
return null;
|
|
10736
|
+
return { ...node, keyAttr: { name: BF_KEY } };
|
|
10615
10737
|
}
|
|
10616
10738
|
if (node.type === "conditional") {
|
|
10617
10739
|
const cond = node;
|
|
@@ -10686,7 +10808,7 @@ function transformExpressionInner(expr, ctx, node, isClientOnly) {
|
|
|
10686
10808
|
if (isRenderNothingLiteral(expr, ctx)) {
|
|
10687
10809
|
return null;
|
|
10688
10810
|
}
|
|
10689
|
-
checkBareSignalOrMemoIdentifier(expr, ctx);
|
|
10811
|
+
checkBareSignalOrMemoIdentifier(expr, ctx, { descendNested: true });
|
|
10690
10812
|
if (ts13.isIdentifier(expr)) {
|
|
10691
10813
|
const jsxNode = ctx.analyzer.jsxConstants.get(expr.text);
|
|
10692
10814
|
if (jsxNode) {
|
|
@@ -11803,6 +11925,16 @@ function tagLoopItemRootComponents(nodes) {
|
|
|
11803
11925
|
}
|
|
11804
11926
|
}
|
|
11805
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
|
+
}
|
|
11806
11938
|
function loopBodyItemConditional(children) {
|
|
11807
11939
|
const real = children.filter((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
|
|
11808
11940
|
if (real.length !== 1)
|
|
@@ -12185,6 +12317,14 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12185
12317
|
const itemConditional = children.length > 0 ? loopBodyItemConditional(children) : null;
|
|
12186
12318
|
const bodyIsItemConditional = itemConditional !== null;
|
|
12187
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
|
+
}
|
|
12188
12328
|
const declaredNameSet = preamble && preamble.declaredNames.length > 0 ? new Set(preamble.declaredNames) : undefined;
|
|
12189
12329
|
if (key && declaredNameSet) {
|
|
12190
12330
|
const keyRefs = extractFreeIdentifiersFromText(key);
|
|
@@ -12875,7 +13015,7 @@ function getAttributeValue(attr, ctx) {
|
|
|
12875
13015
|
ctx.analyzer.errors.push(createError(ErrorCodes.STAGE_AWAIT_IN_TEMPLATE, getSourceLocation(expr, ctx.sourceFile, ctx.filePath)));
|
|
12876
13016
|
return AttrValueOf.expression("undefined");
|
|
12877
13017
|
}
|
|
12878
|
-
checkBareSignalOrMemoIdentifier(expr, ctx);
|
|
13018
|
+
checkBareSignalOrMemoIdentifier(expr, ctx, { descendNested: isRenderedElementAttribute(attr, ctx) });
|
|
12879
13019
|
if (attr.name.getText(ctx.sourceFile) === "style" && ts13.isObjectLiteralExpression(expr)) {
|
|
12880
13020
|
const cssString = tryStaticStyleObjectToCss(expr);
|
|
12881
13021
|
if (cssString !== null) {
|
|
@@ -13383,34 +13523,142 @@ function processComponentProps(attributes, ctx) {
|
|
|
13383
13523
|
}
|
|
13384
13524
|
return props;
|
|
13385
13525
|
}
|
|
13386
|
-
function
|
|
13387
|
-
|
|
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)
|
|
13388
13537
|
return;
|
|
13389
|
-
const
|
|
13390
|
-
|
|
13391
|
-
|
|
13392
|
-
|
|
13393
|
-
|
|
13394
|
-
|
|
13395
|
-
|
|
13396
|
-
|
|
13397
|
-
|
|
13398
|
-
|
|
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);
|
|
13399
13567
|
return;
|
|
13400
13568
|
}
|
|
13401
|
-
|
|
13402
|
-
|
|
13403
|
-
|
|
13404
|
-
|
|
13405
|
-
|
|
13406
|
-
|
|
13407
|
-
|
|
13408
|
-
|
|
13409
|
-
|
|
13410
|
-
|
|
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);
|
|
13611
|
+
return;
|
|
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();
|
|
13411
13640
|
return;
|
|
13412
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);
|
|
13413
13660
|
}
|
|
13661
|
+
visit2(expr);
|
|
13414
13662
|
}
|
|
13415
13663
|
function isArrayExprDirectPropRef(arrayExpr, ctx) {
|
|
13416
13664
|
const propNames = new Set(ctx.patterns.props.map((p) => p.name));
|
|
@@ -13509,6 +13757,31 @@ function isPropsReference(expr, ctx, visited) {
|
|
|
13509
13757
|
}
|
|
13510
13758
|
return false;
|
|
13511
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
|
+
}
|
|
13512
13785
|
function hasReactiveAttributes(attrs, ctx) {
|
|
13513
13786
|
for (const attr of attrs) {
|
|
13514
13787
|
if (attr.name === "key")
|
|
@@ -13731,18 +14004,7 @@ function buildIfStatementChain(analyzer, ctx, opts) {
|
|
|
13731
14004
|
|
|
13732
14005
|
// ../jsx/src/ir-to-client-js/prop-handling.ts
|
|
13733
14006
|
function resolveRestSpreadOrigin(ctx, name) {
|
|
13734
|
-
|
|
13735
|
-
const visited = new Set;
|
|
13736
|
-
let current = name.trim();
|
|
13737
|
-
while (current !== undefined && !visited.has(current)) {
|
|
13738
|
-
if (ctx.restPropsName && current === ctx.restPropsName)
|
|
13739
|
-
return "rest";
|
|
13740
|
-
if (ctx.propsObjectName && current === ctx.propsObjectName)
|
|
13741
|
-
return "props";
|
|
13742
|
-
visited.add(current);
|
|
13743
|
-
current = byName.get(current)?.trim();
|
|
13744
|
-
}
|
|
13745
|
-
return null;
|
|
14007
|
+
return resolveRestSpreadOriginCore(ctx, localConstantValues(ctx), name);
|
|
13746
14008
|
}
|
|
13747
14009
|
var _localConstantValuesCache = new WeakMap;
|
|
13748
14010
|
function localConstantValues(ctx) {
|
|
@@ -14638,8 +14900,8 @@ function collectReactiveChildProps(node, ctx) {
|
|
|
14638
14900
|
continue;
|
|
14639
14901
|
if (prop.value.kind === "jsx-children")
|
|
14640
14902
|
continue;
|
|
14641
|
-
const
|
|
14642
|
-
if (
|
|
14903
|
+
const domKind = classifyDOMProp(prop.name).kind;
|
|
14904
|
+
if (domKind === "ref" || domKind === "event" || domKind === "skip")
|
|
14643
14905
|
continue;
|
|
14644
14906
|
if (prop.value.kind !== "expression" && prop.value.kind !== "template")
|
|
14645
14907
|
continue;
|
|
@@ -15556,6 +15818,9 @@ function propHasPropertyAccess(u) {
|
|
|
15556
15818
|
return u.accessKinds.has("property") || u.accessKinds.has("index");
|
|
15557
15819
|
}
|
|
15558
15820
|
|
|
15821
|
+
// ../jsx/src/ir-to-client-js/imports.ts
|
|
15822
|
+
import ts16 from "typescript";
|
|
15823
|
+
|
|
15559
15824
|
// ../jsx/src/value-references.ts
|
|
15560
15825
|
import ts15 from "typescript";
|
|
15561
15826
|
function isValueReferenceIdentifier(id) {
|
|
@@ -15662,6 +15927,7 @@ var RUNTIME_IMPORT_CANDIDATES = [
|
|
|
15662
15927
|
"escapeTextOrNode",
|
|
15663
15928
|
"bfMarkup",
|
|
15664
15929
|
"escapeTextOrMarkup",
|
|
15930
|
+
"markupOrEmpty",
|
|
15665
15931
|
"qsa",
|
|
15666
15932
|
"qsaItem",
|
|
15667
15933
|
"qsaChildScope",
|
|
@@ -15728,6 +15994,79 @@ function makeValueUsageTest(generatedCode) {
|
|
|
15728
15994
|
return generatedCode.includes(localName);
|
|
15729
15995
|
};
|
|
15730
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
|
+
}
|
|
15731
16070
|
function collectExternalImports(ir, generatedCode, localImportPrefixes) {
|
|
15732
16071
|
const componentNames = collectComponentNames(ir.root);
|
|
15733
16072
|
const importLines = [];
|
|
@@ -15743,23 +16082,31 @@ function collectExternalImports(ir, generatedCode, localImportPrefixes) {
|
|
|
15743
16082
|
importLines.push(`import '${imp.source}'`);
|
|
15744
16083
|
continue;
|
|
15745
16084
|
}
|
|
15746
|
-
const
|
|
16085
|
+
const usedNamed = [];
|
|
16086
|
+
let usedDefault = null;
|
|
16087
|
+
let usedNamespace = null;
|
|
15747
16088
|
for (const spec of imp.specifiers) {
|
|
15748
16089
|
if (spec.isTypeOnly)
|
|
15749
16090
|
continue;
|
|
15750
16091
|
const localName = spec.alias || spec.name;
|
|
15751
16092
|
if (componentNames.has(localName))
|
|
15752
16093
|
continue;
|
|
15753
|
-
if (isUsedAsValue(localName))
|
|
15754
|
-
|
|
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);
|
|
15755
16102
|
}
|
|
15756
16103
|
}
|
|
15757
|
-
if (
|
|
16104
|
+
if (usedDefault || usedNamespace || usedNamed.length > 0) {
|
|
15758
16105
|
let source = imp.source;
|
|
15759
16106
|
if (ir.metadata.clientSignalImportSources?.has(source)) {
|
|
15760
16107
|
source = source.replace(/\.tsx?$/, "") + ".client.js";
|
|
15761
16108
|
}
|
|
15762
|
-
importLines.push(
|
|
16109
|
+
importLines.push(...renderUsedImportLines(source, usedDefault, usedNamespace, usedNamed));
|
|
15763
16110
|
}
|
|
15764
16111
|
}
|
|
15765
16112
|
return importLines;
|
|
@@ -15789,7 +16136,7 @@ function collectComponentNames(node) {
|
|
|
15789
16136
|
}
|
|
15790
16137
|
|
|
15791
16138
|
// ../jsx/src/relocate.ts
|
|
15792
|
-
import
|
|
16139
|
+
import ts17 from "typescript";
|
|
15793
16140
|
|
|
15794
16141
|
// ../jsx/src/lowering-registry.ts
|
|
15795
16142
|
var plugins = [];
|
|
@@ -15817,19 +16164,19 @@ function classify(name, env) {
|
|
|
15817
16164
|
function collectFreeRefs(node) {
|
|
15818
16165
|
const refs = new Map;
|
|
15819
16166
|
function visit3(n, parent) {
|
|
15820
|
-
if (
|
|
15821
|
-
if (parent &&
|
|
16167
|
+
if (ts17.isIdentifier(n)) {
|
|
16168
|
+
if (parent && ts17.isPropertyAccessExpression(parent) && parent.name === n)
|
|
15822
16169
|
return;
|
|
15823
|
-
if (parent &&
|
|
16170
|
+
if (parent && ts17.isPropertyAssignment(parent) && parent.name === n)
|
|
15824
16171
|
return;
|
|
15825
|
-
if (parent &&
|
|
16172
|
+
if (parent && ts17.isShorthandPropertyAssignment(parent) && parent.name === n)
|
|
15826
16173
|
return;
|
|
15827
16174
|
const list = refs.get(n.text) ?? [];
|
|
15828
16175
|
list.push(n);
|
|
15829
16176
|
refs.set(n.text, list);
|
|
15830
16177
|
return;
|
|
15831
16178
|
}
|
|
15832
|
-
|
|
16179
|
+
ts17.forEachChild(n, (child) => visit3(child, n));
|
|
15833
16180
|
}
|
|
15834
16181
|
visit3(node);
|
|
15835
16182
|
return refs;
|
|
@@ -15933,11 +16280,11 @@ function isInlinableInTemplate(value, env) {
|
|
|
15933
16280
|
return { ok: true, rewrittenValue: r.text, decisions: r.decisions };
|
|
15934
16281
|
}
|
|
15935
16282
|
function getCalleeIdentifierPath(callee) {
|
|
15936
|
-
if (
|
|
16283
|
+
if (ts17.isParenthesizedExpression(callee))
|
|
15937
16284
|
return getCalleeIdentifierPath(callee.expression);
|
|
15938
|
-
if (
|
|
16285
|
+
if (ts17.isIdentifier(callee))
|
|
15939
16286
|
return callee.text;
|
|
15940
|
-
if (
|
|
16287
|
+
if (ts17.isPropertyAccessExpression(callee)) {
|
|
15941
16288
|
const left = getCalleeIdentifierPath(callee.expression);
|
|
15942
16289
|
if (left === null)
|
|
15943
16290
|
return null;
|
|
@@ -15946,11 +16293,11 @@ function getCalleeIdentifierPath(callee) {
|
|
|
15946
16293
|
return null;
|
|
15947
16294
|
}
|
|
15948
16295
|
function getCalleeLeftmostIdentifier(callee) {
|
|
15949
|
-
if (
|
|
16296
|
+
if (ts17.isParenthesizedExpression(callee))
|
|
15950
16297
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
15951
|
-
if (
|
|
16298
|
+
if (ts17.isIdentifier(callee))
|
|
15952
16299
|
return callee.text;
|
|
15953
|
-
if (
|
|
16300
|
+
if (ts17.isPropertyAccessExpression(callee)) {
|
|
15954
16301
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
15955
16302
|
}
|
|
15956
16303
|
return null;
|
|
@@ -15998,12 +16345,12 @@ function isCallAcceptedByAdapter(call, env) {
|
|
|
15998
16345
|
}
|
|
15999
16346
|
function parseExpressionNode(text) {
|
|
16000
16347
|
try {
|
|
16001
|
-
const sf =
|
|
16348
|
+
const sf = ts17.createSourceFile("__inline_check__.ts", `(${text});`, ts17.ScriptTarget.Latest, false, ts17.ScriptKind.TS);
|
|
16002
16349
|
const stmt = sf.statements[0];
|
|
16003
|
-
if (!stmt || !
|
|
16350
|
+
if (!stmt || !ts17.isExpressionStatement(stmt))
|
|
16004
16351
|
return null;
|
|
16005
16352
|
const inner = stmt.expression;
|
|
16006
|
-
return
|
|
16353
|
+
return ts17.isParenthesizedExpression(inner) ? inner.expression : inner;
|
|
16007
16354
|
} catch {
|
|
16008
16355
|
return null;
|
|
16009
16356
|
}
|
|
@@ -16020,8 +16367,8 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
16020
16367
|
function visit3(n) {
|
|
16021
16368
|
if (found)
|
|
16022
16369
|
return;
|
|
16023
|
-
if (
|
|
16024
|
-
const accepted =
|
|
16370
|
+
if (ts17.isCallExpression(n) || ts17.isNewExpression(n)) {
|
|
16371
|
+
const accepted = ts17.isCallExpression(n) && isCallAcceptedByAdapter(n, env);
|
|
16025
16372
|
if (!accepted) {
|
|
16026
16373
|
const args = n.arguments;
|
|
16027
16374
|
if (args) {
|
|
@@ -16034,7 +16381,7 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
16034
16381
|
}
|
|
16035
16382
|
}
|
|
16036
16383
|
}
|
|
16037
|
-
|
|
16384
|
+
ts17.forEachChild(n, visit3);
|
|
16038
16385
|
}
|
|
16039
16386
|
visit3(node);
|
|
16040
16387
|
return found;
|
|
@@ -16044,13 +16391,13 @@ function hasZeroArgCall(node, env) {
|
|
|
16044
16391
|
function visit3(n) {
|
|
16045
16392
|
if (found)
|
|
16046
16393
|
return;
|
|
16047
|
-
if (
|
|
16394
|
+
if (ts17.isCallExpression(n) && n.arguments.length === 0) {
|
|
16048
16395
|
if (!isCallAcceptedByAdapter(n, env)) {
|
|
16049
16396
|
found = true;
|
|
16050
16397
|
return;
|
|
16051
16398
|
}
|
|
16052
16399
|
}
|
|
16053
|
-
|
|
16400
|
+
ts17.forEachChild(n, visit3);
|
|
16054
16401
|
}
|
|
16055
16402
|
visit3(node);
|
|
16056
16403
|
return found;
|
|
@@ -16060,25 +16407,25 @@ function containsAnyIdentifier(node, names) {
|
|
|
16060
16407
|
function visit3(n) {
|
|
16061
16408
|
if (found)
|
|
16062
16409
|
return;
|
|
16063
|
-
if (
|
|
16410
|
+
if (ts17.isPropertyAccessExpression(n)) {
|
|
16064
16411
|
visit3(n.expression);
|
|
16065
16412
|
return;
|
|
16066
16413
|
}
|
|
16067
|
-
if (
|
|
16414
|
+
if (ts17.isPropertyAssignment(n)) {
|
|
16068
16415
|
visit3(n.initializer);
|
|
16069
16416
|
return;
|
|
16070
16417
|
}
|
|
16071
|
-
if (
|
|
16072
|
-
if (
|
|
16418
|
+
if (ts17.isShorthandPropertyAssignment(n)) {
|
|
16419
|
+
if (ts17.isIdentifier(n.name) && names.has(n.name.text)) {
|
|
16073
16420
|
found = true;
|
|
16074
16421
|
}
|
|
16075
16422
|
return;
|
|
16076
16423
|
}
|
|
16077
|
-
if (
|
|
16424
|
+
if (ts17.isIdentifier(n) && names.has(n.text)) {
|
|
16078
16425
|
found = true;
|
|
16079
16426
|
return;
|
|
16080
16427
|
}
|
|
16081
|
-
|
|
16428
|
+
ts17.forEachChild(n, visit3);
|
|
16082
16429
|
}
|
|
16083
16430
|
visit3(node);
|
|
16084
16431
|
return found;
|
|
@@ -17365,23 +17712,23 @@ function resolveFinalImports(generatedCode, ir, localImportPrefixes) {
|
|
|
17365
17712
|
}
|
|
17366
17713
|
|
|
17367
17714
|
// ../jsx/src/ir-to-client-js/prune-unused-prop-extractions.ts
|
|
17368
|
-
import
|
|
17715
|
+
import ts18 from "typescript";
|
|
17369
17716
|
function propExtractionName(stmt) {
|
|
17370
|
-
if (!
|
|
17717
|
+
if (!ts18.isVariableStatement(stmt))
|
|
17371
17718
|
return null;
|
|
17372
17719
|
const decls = stmt.declarationList.declarations;
|
|
17373
17720
|
if (decls.length !== 1)
|
|
17374
17721
|
return null;
|
|
17375
17722
|
const decl = decls[0];
|
|
17376
|
-
if (!
|
|
17723
|
+
if (!ts18.isIdentifier(decl.name) || !decl.initializer)
|
|
17377
17724
|
return null;
|
|
17378
17725
|
let core = decl.initializer;
|
|
17379
|
-
if (
|
|
17726
|
+
if (ts18.isBinaryExpression(core) && core.operatorToken.kind === ts18.SyntaxKind.QuestionQuestionToken) {
|
|
17380
17727
|
core = core.left;
|
|
17381
17728
|
}
|
|
17382
|
-
if (!
|
|
17729
|
+
if (!ts18.isPropertyAccessExpression(core))
|
|
17383
17730
|
return null;
|
|
17384
|
-
if (!
|
|
17731
|
+
if (!ts18.isIdentifier(core.expression) || core.expression.text !== PROPS_PARAM)
|
|
17385
17732
|
return null;
|
|
17386
17733
|
if (core.name.text !== decl.name.text)
|
|
17387
17734
|
return null;
|
|
@@ -17394,10 +17741,10 @@ function pruneUnusedPropExtractions(code) {
|
|
|
17394
17741
|
console.warn("[barefootjs] pruneUnusedPropExtractions: generated code did not parse; skipping prune");
|
|
17395
17742
|
return code;
|
|
17396
17743
|
}
|
|
17397
|
-
const sourceFile =
|
|
17744
|
+
const sourceFile = ts18.createSourceFile("generated.js", code, ts18.ScriptTarget.Latest, false, ts18.ScriptKind.JS);
|
|
17398
17745
|
const spans = [];
|
|
17399
17746
|
for (const stmt of sourceFile.statements) {
|
|
17400
|
-
if (!
|
|
17747
|
+
if (!ts18.isFunctionDeclaration(stmt) || !stmt.name?.text.startsWith("init") || !stmt.body)
|
|
17401
17748
|
continue;
|
|
17402
17749
|
for (const inner of stmt.body.statements) {
|
|
17403
17750
|
const name = propExtractionName(inner);
|
|
@@ -18856,7 +19203,7 @@ function analyzeLazyConditional(cond, indexParam, arms) {
|
|
|
18856
19203
|
}
|
|
18857
19204
|
|
|
18858
19205
|
// ../jsx/src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
|
|
18859
|
-
import
|
|
19206
|
+
import ts19 from "typescript";
|
|
18860
19207
|
var NO_PREAMBLE = {
|
|
18861
19208
|
lazySafe: true,
|
|
18862
19209
|
facts: { declaredNames: new Set, freeNames: new Set }
|
|
@@ -18876,12 +19223,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
|
|
|
18876
19223
|
if (text.trim().length === 0)
|
|
18877
19224
|
return NO_PREAMBLE;
|
|
18878
19225
|
const declaredNames = new Set;
|
|
18879
|
-
const sf =
|
|
19226
|
+
const sf = ts19.createSourceFile("__lazy_preamble__.ts", text, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
|
|
18880
19227
|
for (const stmt of sf.statements) {
|
|
18881
|
-
if (!
|
|
18882
|
-
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]})`);
|
|
18883
19230
|
}
|
|
18884
|
-
const isConst = (stmt.declarationList.flags &
|
|
19231
|
+
const isConst = (stmt.declarationList.flags & ts19.NodeFlags.Const) !== 0;
|
|
18885
19232
|
if (!isConst)
|
|
18886
19233
|
return NO2("map-callback preamble declares a mutable binding (let/var)");
|
|
18887
19234
|
for (const decl of stmt.declarationList.declarations) {
|
|
@@ -18910,12 +19257,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
|
|
|
18910
19257
|
return { lazySafe: true, facts: { declaredNames, freeNames } };
|
|
18911
19258
|
}
|
|
18912
19259
|
function collectBindingNames3(name, out) {
|
|
18913
|
-
if (
|
|
19260
|
+
if (ts19.isIdentifier(name)) {
|
|
18914
19261
|
out.add(name.text);
|
|
18915
19262
|
return;
|
|
18916
19263
|
}
|
|
18917
19264
|
for (const element of name.elements) {
|
|
18918
|
-
if (
|
|
19265
|
+
if (ts19.isOmittedExpression(element))
|
|
18919
19266
|
continue;
|
|
18920
19267
|
collectBindingNames3(element.name, out);
|
|
18921
19268
|
}
|
|
@@ -18925,56 +19272,56 @@ function findImpureNode(root, primableNames) {
|
|
|
18925
19272
|
const visit3 = (node) => {
|
|
18926
19273
|
if (found)
|
|
18927
19274
|
return;
|
|
18928
|
-
if (
|
|
19275
|
+
if (ts19.isCallExpression(node)) {
|
|
18929
19276
|
const callee = node.expression;
|
|
18930
|
-
const isSignalRead =
|
|
19277
|
+
const isSignalRead = ts19.isIdentifier(callee) && primableNames.has(callee.text) && node.arguments.length === 0 && node.questionDotToken === undefined;
|
|
18931
19278
|
if (!isSignalRead) {
|
|
18932
19279
|
found = `call to ${callee.getText(callee.getSourceFile())}`;
|
|
18933
19280
|
return;
|
|
18934
19281
|
}
|
|
18935
19282
|
}
|
|
18936
|
-
if (
|
|
19283
|
+
if (ts19.isNewExpression(node)) {
|
|
18937
19284
|
found = "new expression";
|
|
18938
19285
|
return;
|
|
18939
19286
|
}
|
|
18940
|
-
if (
|
|
19287
|
+
if (ts19.isTaggedTemplateExpression(node)) {
|
|
18941
19288
|
found = "tagged template";
|
|
18942
19289
|
return;
|
|
18943
19290
|
}
|
|
18944
|
-
if (
|
|
19291
|
+
if (ts19.isAwaitExpression(node)) {
|
|
18945
19292
|
found = "await";
|
|
18946
19293
|
return;
|
|
18947
19294
|
}
|
|
18948
|
-
if (
|
|
19295
|
+
if (ts19.isYieldExpression(node)) {
|
|
18949
19296
|
found = "yield";
|
|
18950
19297
|
return;
|
|
18951
19298
|
}
|
|
18952
|
-
if (
|
|
19299
|
+
if (ts19.isPrefixUnaryExpression(node) || ts19.isPostfixUnaryExpression(node)) {
|
|
18953
19300
|
const op = node.operator;
|
|
18954
|
-
if (op ===
|
|
19301
|
+
if (op === ts19.SyntaxKind.PlusPlusToken || op === ts19.SyntaxKind.MinusMinusToken) {
|
|
18955
19302
|
found = "increment/decrement";
|
|
18956
19303
|
return;
|
|
18957
19304
|
}
|
|
18958
19305
|
}
|
|
18959
|
-
if (
|
|
19306
|
+
if (ts19.isDeleteExpression(node)) {
|
|
18960
19307
|
found = "delete";
|
|
18961
19308
|
return;
|
|
18962
19309
|
}
|
|
18963
|
-
if (
|
|
19310
|
+
if (ts19.isFunctionExpression(node) || ts19.isArrowFunction(node) || ts19.isClassExpression(node)) {
|
|
18964
19311
|
found = "function or class expression";
|
|
18965
19312
|
return;
|
|
18966
19313
|
}
|
|
18967
|
-
if (
|
|
19314
|
+
if (ts19.isBinaryExpression(node) && isAssignmentOperator2(node.operatorToken.kind)) {
|
|
18968
19315
|
found = "assignment";
|
|
18969
19316
|
return;
|
|
18970
19317
|
}
|
|
18971
|
-
|
|
19318
|
+
ts19.forEachChild(node, visit3);
|
|
18972
19319
|
};
|
|
18973
19320
|
visit3(root);
|
|
18974
19321
|
return found;
|
|
18975
19322
|
}
|
|
18976
19323
|
function isAssignmentOperator2(kind) {
|
|
18977
|
-
return kind >=
|
|
19324
|
+
return kind >= ts19.SyntaxKind.FirstAssignment && kind <= ts19.SyntaxKind.LastAssignment;
|
|
18978
19325
|
}
|
|
18979
19326
|
|
|
18980
19327
|
// ../jsx/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts
|
|
@@ -19504,7 +19851,7 @@ function buildArmBody(branch, options) {
|
|
|
19504
19851
|
}
|
|
19505
19852
|
|
|
19506
19853
|
// ../jsx/src/ir-to-client-js/emit-reactive.ts
|
|
19507
|
-
import
|
|
19854
|
+
import ts20 from "typescript";
|
|
19508
19855
|
|
|
19509
19856
|
// ../jsx/src/ir-to-client-js/control-flow/stringify/claim-plan.ts
|
|
19510
19857
|
function slotSpecLiteral(slot) {
|
|
@@ -19616,20 +19963,20 @@ function lowerToLocaleCallsInReactiveExpr(expr, matcher) {
|
|
|
19616
19963
|
return expr;
|
|
19617
19964
|
let sourceFile;
|
|
19618
19965
|
try {
|
|
19619
|
-
sourceFile =
|
|
19966
|
+
sourceFile = ts20.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
|
|
19620
19967
|
} catch {
|
|
19621
19968
|
return expr;
|
|
19622
19969
|
}
|
|
19623
19970
|
const stmt = sourceFile.statements[0];
|
|
19624
|
-
if (!stmt || !
|
|
19971
|
+
if (!stmt || !ts20.isExpressionStatement(stmt))
|
|
19625
19972
|
return expr;
|
|
19626
|
-
const root =
|
|
19973
|
+
const root = ts20.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19627
19974
|
const candidates = [];
|
|
19628
19975
|
const visit3 = (n) => {
|
|
19629
|
-
if (
|
|
19976
|
+
if (ts20.isCallExpression(n) && n.arguments.length === 2 && ts20.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
|
|
19630
19977
|
candidates.push(n);
|
|
19631
19978
|
}
|
|
19632
|
-
|
|
19979
|
+
ts20.forEachChild(n, visit3);
|
|
19633
19980
|
};
|
|
19634
19981
|
visit3(root);
|
|
19635
19982
|
if (candidates.length === 0)
|
|
@@ -19665,20 +20012,20 @@ function lowerDateCallsInReactiveExpr(expr, matcher) {
|
|
|
19665
20012
|
return expr;
|
|
19666
20013
|
let sourceFile;
|
|
19667
20014
|
try {
|
|
19668
|
-
sourceFile =
|
|
20015
|
+
sourceFile = ts20.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
|
|
19669
20016
|
} catch {
|
|
19670
20017
|
return expr;
|
|
19671
20018
|
}
|
|
19672
20019
|
const stmt = sourceFile.statements[0];
|
|
19673
|
-
if (!stmt || !
|
|
20020
|
+
if (!stmt || !ts20.isExpressionStatement(stmt))
|
|
19674
20021
|
return expr;
|
|
19675
|
-
const root =
|
|
20022
|
+
const root = ts20.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19676
20023
|
const candidates = [];
|
|
19677
20024
|
const visit3 = (n) => {
|
|
19678
|
-
if (
|
|
20025
|
+
if (ts20.isCallExpression(n) && n.arguments.length === 0 && ts20.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
19679
20026
|
candidates.push(n);
|
|
19680
20027
|
}
|
|
19681
|
-
|
|
20028
|
+
ts20.forEachChild(n, visit3);
|
|
19682
20029
|
};
|
|
19683
20030
|
visit3(root);
|
|
19684
20031
|
if (candidates.length === 0)
|
|
@@ -19917,7 +20264,7 @@ function stringifyBranchInnerLoops(lines, plan, indent, pc) {
|
|
|
19917
20264
|
lines.push(`${indent} let __bel${uid} = __existing ?? (() => { const __t = document.createElement('template'); __t.innerHTML = \`${innerHtml}\`; return __t.content${childPath}.cloneNode(true) })()`);
|
|
19918
20265
|
}
|
|
19919
20266
|
if (inner.wrappedKey) {
|
|
19920
|
-
lines.push(`${indent} __bel${uid}.setAttribute('${
|
|
20267
|
+
lines.push(`${indent} __bel${uid}.setAttribute('${keyAttrName2(inner.keyDepth)}', String(${inner.wrappedKey}))`);
|
|
19921
20268
|
}
|
|
19922
20269
|
if (inner.legacyComponents.length > 0 || inner.legacyEvents.length > 0) {
|
|
19923
20270
|
emitComponentAndEventSetup(lines, `${indent} `, `__bel${uid}`, [...inner.legacyComponents], [...inner.legacyEvents], inner.outerLoopParam, inner.outerLoopParamBindings);
|
|
@@ -19940,7 +20287,7 @@ function stringifyBranchInnerLoops(lines, plan, indent, pc) {
|
|
|
19940
20287
|
stringifyLoopChildConditionals(lines, inner.nestedConditionals, `${indent} `, pc);
|
|
19941
20288
|
}
|
|
19942
20289
|
lines.push(`${indent} return __bel${uid}`);
|
|
19943
|
-
lines.push(`${indent}}, '${inner.markerId}'${profileBindingId(pc, inner.slotId)}) }`);
|
|
20290
|
+
lines.push(`${indent}}, '${inner.markerId}'${mapArrayKeyArgs(profileBindingId(pc, inner.slotId), !!inner.wrappedKey, inner.keyDepth)}) }`);
|
|
19944
20291
|
}
|
|
19945
20292
|
}
|
|
19946
20293
|
function stringifyLoopChildConditionals(lines, conditionals, indent, pc) {
|
|
@@ -20749,7 +21096,7 @@ function emitReactive(lines, inner, indent, pc) {
|
|
|
20749
21096
|
lines.push(`${indent} let __innerEl${uid} = __existing ?? (() => { const __t = document.createElement('template'); __t.innerHTML = \`${innerHtml}\`; return __t.content${childPath}.cloneNode(true) })()`);
|
|
20750
21097
|
}
|
|
20751
21098
|
if (emit.wrappedKey) {
|
|
20752
|
-
lines.push(`${indent} __innerEl${uid}.setAttribute('${
|
|
21099
|
+
lines.push(`${indent} __innerEl${uid}.setAttribute('${keyAttrName2(inner.keyDepth)}', String(${emit.wrappedKey}))`);
|
|
20753
21100
|
}
|
|
20754
21101
|
if (emit.components.length > 0 || emit.events.length > 0) {
|
|
20755
21102
|
emitComponentAndEventSetup(lines, `${indent} `, `__innerEl${uid}`, [...emit.components], [...emit.events], inner.outerLoopParam, inner.outerLoopParamBindings);
|
|
@@ -20789,7 +21136,7 @@ function emitReactive(lines, inner, indent, pc) {
|
|
|
20789
21136
|
bodyIsMultiRoot: emit.bodyIsMultiRoot
|
|
20790
21137
|
});
|
|
20791
21138
|
lines.push(`${indent} return __innerEl${uid}`);
|
|
20792
|
-
lines.push(`${indent}}, '${inner.markerId}'${profileBindingId(pc, inner.slotId)}) }`);
|
|
21139
|
+
lines.push(`${indent}}, '${inner.markerId}'${mapArrayKeyArgs(profileBindingId(pc, inner.slotId), !!emit.wrappedKey, inner.keyDepth)}) }`);
|
|
20793
21140
|
}
|
|
20794
21141
|
function emitStatic(lines, inner, indent, pc) {
|
|
20795
21142
|
const uid = inner.uidSuffix;
|
|
@@ -20805,7 +21152,7 @@ function emitStatic(lines, inner, indent, pc) {
|
|
|
20805
21152
|
lines.push(`${indent} ${stmt}`);
|
|
20806
21153
|
}
|
|
20807
21154
|
if (emit.rawKey) {
|
|
20808
|
-
lines.push(`${indent} __innerEl${uid}.setAttribute('${
|
|
21155
|
+
lines.push(`${indent} __innerEl${uid}.setAttribute('${keyAttrName2(inner.keyDepth)}', String(${emit.rawKey}))`);
|
|
20809
21156
|
}
|
|
20810
21157
|
emitComponentAndEventSetup(lines, `${indent} `, `__innerEl${uid}`, [...emit.components], [...emit.events], inner.outerLoopParam, inner.outerLoopParamBindings);
|
|
20811
21158
|
if (inner.childLevels.length > 0) {
|
|
@@ -20993,7 +21340,7 @@ function emitKeyedLookup(ls, ev, handlerCall, lookup) {
|
|
|
20993
21340
|
}
|
|
20994
21341
|
const evVar = varSlotId(ev.childSlotId);
|
|
20995
21342
|
for (const nested of ev.nestedLoops) {
|
|
20996
|
-
const dataAttr =
|
|
21343
|
+
const dataAttr = keyAttrName2(nested.depth);
|
|
20997
21344
|
ls.push(` const innerLi${nested.depth} = ${evVar}El.closest('[${dataAttr}]')`);
|
|
20998
21345
|
ls.push(` const innerKey${nested.depth} = innerLi${nested.depth}?.getAttribute('${dataAttr}')`);
|
|
20999
21346
|
}
|
|
@@ -21699,7 +22046,7 @@ var PHASES = [
|
|
|
21699
22046
|
];
|
|
21700
22047
|
|
|
21701
22048
|
// ../jsx/src/ir-to-client-js/rewrite-props-object.ts
|
|
21702
|
-
import
|
|
22049
|
+
import ts21 from "typescript";
|
|
21703
22050
|
function rewritePropsObjectRef(code, propsObjectName, restPropsName = null) {
|
|
21704
22051
|
let result = code;
|
|
21705
22052
|
const seen = new Set;
|
|
@@ -21714,13 +22061,13 @@ function rewritePropsObjectRef(code, propsObjectName, restPropsName = null) {
|
|
|
21714
22061
|
function rewriteOneName(code, srcPropsName) {
|
|
21715
22062
|
if (!identifierPattern(srcPropsName).test(code))
|
|
21716
22063
|
return code;
|
|
21717
|
-
const sourceFile =
|
|
22064
|
+
const sourceFile = ts21.createSourceFile("init-body.ts", code, ts21.ScriptTarget.Latest, true, ts21.ScriptKind.TS);
|
|
21718
22065
|
const spans = [];
|
|
21719
22066
|
function visit3(node) {
|
|
21720
|
-
if (
|
|
22067
|
+
if (ts21.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
|
|
21721
22068
|
spans.push([node.getStart(sourceFile), node.getEnd()]);
|
|
21722
22069
|
}
|
|
21723
|
-
|
|
22070
|
+
ts21.forEachChild(node, visit3);
|
|
21724
22071
|
}
|
|
21725
22072
|
visit3(sourceFile);
|
|
21726
22073
|
if (spans.length === 0)
|
|
@@ -21736,17 +22083,17 @@ function shouldRewrite(node) {
|
|
|
21736
22083
|
const parent = node.parent;
|
|
21737
22084
|
if (!parent)
|
|
21738
22085
|
return true;
|
|
21739
|
-
if (
|
|
22086
|
+
if (ts21.isPropertyAccessExpression(parent) && parent.name === node)
|
|
21740
22087
|
return false;
|
|
21741
|
-
if (
|
|
22088
|
+
if (ts21.isPropertyAssignment(parent) && parent.name === node)
|
|
21742
22089
|
return false;
|
|
21743
|
-
if (
|
|
22090
|
+
if (ts21.isShorthandPropertyAssignment(parent) && parent.name === node)
|
|
21744
22091
|
return false;
|
|
21745
|
-
if (
|
|
22092
|
+
if (ts21.isPropertySignature(parent) && parent.name === node)
|
|
21746
22093
|
return false;
|
|
21747
|
-
if (
|
|
22094
|
+
if (ts21.isPropertyDeclaration(parent) && parent.name === node)
|
|
21748
22095
|
return false;
|
|
21749
|
-
if (
|
|
22096
|
+
if (ts21.isBindingElement(parent) && parent.name === node)
|
|
21750
22097
|
return false;
|
|
21751
22098
|
return true;
|
|
21752
22099
|
}
|
|
@@ -22057,7 +22404,7 @@ function createContext(ir, scope, adapterCapabilities, profile) {
|
|
|
22057
22404
|
};
|
|
22058
22405
|
}
|
|
22059
22406
|
function needsClientJs(ctx) {
|
|
22060
|
-
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)
|
|
22061
22408
|
return true;
|
|
22062
22409
|
return hasInitScopeOnlyConstant(ctx);
|
|
22063
22410
|
}
|
|
@@ -22395,7 +22742,7 @@ function walkIR2(node, visitor) {
|
|
|
22395
22742
|
}
|
|
22396
22743
|
|
|
22397
22744
|
// ../jsx/src/preprocess-inline-jsx-callbacks.ts
|
|
22398
|
-
import
|
|
22745
|
+
import ts22 from "typescript";
|
|
22399
22746
|
var SYNTHETIC_PREFIX = "BFInlineJsxCallback";
|
|
22400
22747
|
var MAX_FIXPOINT_ITERATIONS = 16;
|
|
22401
22748
|
function preprocessInlineJsxCallbacks(source, filePath) {
|
|
@@ -22417,8 +22764,8 @@ function preprocessInlineJsxCallbacks(source, filePath) {
|
|
|
22417
22764
|
return { source: current, errors, syntheticNames };
|
|
22418
22765
|
}
|
|
22419
22766
|
function runSinglePass(source, filePath, startingCounter) {
|
|
22420
|
-
const sourceFile =
|
|
22421
|
-
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'"));
|
|
22422
22769
|
if (!hasUseClient) {
|
|
22423
22770
|
return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
|
|
22424
22771
|
}
|
|
@@ -22440,22 +22787,22 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22440
22787
|
}
|
|
22441
22788
|
}
|
|
22442
22789
|
function visit3(node) {
|
|
22443
|
-
if (
|
|
22790
|
+
if (ts22.isJsxAttribute(node) && node.initializer && ts22.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
22444
22791
|
if (tryHandleArrowValue(node.initializer.expression)) {
|
|
22445
22792
|
return;
|
|
22446
22793
|
}
|
|
22447
22794
|
}
|
|
22448
|
-
if (
|
|
22795
|
+
if (ts22.isPropertyAssignment(node) && node.initializer) {
|
|
22449
22796
|
if (tryHandleArrowValue(node.initializer))
|
|
22450
22797
|
return;
|
|
22451
22798
|
}
|
|
22452
|
-
|
|
22799
|
+
ts22.forEachChild(node, visit3);
|
|
22453
22800
|
}
|
|
22454
22801
|
function tryHandleArrowValue(initializer) {
|
|
22455
22802
|
let expr = initializer;
|
|
22456
|
-
while (
|
|
22803
|
+
while (ts22.isParenthesizedExpression(expr))
|
|
22457
22804
|
expr = expr.expression;
|
|
22458
|
-
if (
|
|
22805
|
+
if (ts22.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
|
|
22459
22806
|
return handleInlineArrow(expr);
|
|
22460
22807
|
}
|
|
22461
22808
|
return false;
|
|
@@ -22492,7 +22839,7 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22492
22839
|
replacements.push({ start: arrowStart, end: arrowEnd, text: name });
|
|
22493
22840
|
return true;
|
|
22494
22841
|
}
|
|
22495
|
-
|
|
22842
|
+
ts22.forEachChild(sourceFile, visit3);
|
|
22496
22843
|
if (replacements.length === 0) {
|
|
22497
22844
|
return { source, errors, syntheticNames, counterAfter: counter };
|
|
22498
22845
|
}
|
|
@@ -22515,11 +22862,11 @@ function errorMessageForCapture(captures) {
|
|
|
22515
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.`;
|
|
22516
22863
|
}
|
|
22517
22864
|
function arrowBodyContainsJsx(arrow) {
|
|
22518
|
-
if (
|
|
22865
|
+
if (ts22.isBlock(arrow.body)) {
|
|
22519
22866
|
return blockReturnsJsx(arrow.body);
|
|
22520
22867
|
}
|
|
22521
22868
|
let body = arrow.body;
|
|
22522
|
-
while (
|
|
22869
|
+
while (ts22.isParenthesizedExpression(body))
|
|
22523
22870
|
body = body.expression;
|
|
22524
22871
|
return isJsxLike(body);
|
|
22525
22872
|
}
|
|
@@ -22528,24 +22875,24 @@ function blockReturnsJsx(block) {
|
|
|
22528
22875
|
function visit3(n) {
|
|
22529
22876
|
if (found)
|
|
22530
22877
|
return;
|
|
22531
|
-
if (
|
|
22878
|
+
if (ts22.isReturnStatement(n) && n.expression) {
|
|
22532
22879
|
let e = n.expression;
|
|
22533
|
-
while (
|
|
22880
|
+
while (ts22.isParenthesizedExpression(e))
|
|
22534
22881
|
e = e.expression;
|
|
22535
22882
|
if (isJsxLike(e)) {
|
|
22536
22883
|
found = true;
|
|
22537
22884
|
return;
|
|
22538
22885
|
}
|
|
22539
22886
|
}
|
|
22540
|
-
if (
|
|
22887
|
+
if (ts22.isArrowFunction(n) || ts22.isFunctionDeclaration(n) || ts22.isFunctionExpression(n))
|
|
22541
22888
|
return;
|
|
22542
|
-
|
|
22889
|
+
ts22.forEachChild(n, visit3);
|
|
22543
22890
|
}
|
|
22544
|
-
|
|
22891
|
+
ts22.forEachChild(block, visit3);
|
|
22545
22892
|
return found;
|
|
22546
22893
|
}
|
|
22547
22894
|
function isJsxLike(expr) {
|
|
22548
|
-
return
|
|
22895
|
+
return ts22.isJsxElement(expr) || ts22.isJsxSelfClosingElement(expr) || ts22.isJsxFragment(expr);
|
|
22549
22896
|
}
|
|
22550
22897
|
function collectArrowParamNames(arrow) {
|
|
22551
22898
|
const names = new Set;
|
|
@@ -22555,13 +22902,13 @@ function collectArrowParamNames(arrow) {
|
|
|
22555
22902
|
}
|
|
22556
22903
|
function collectBindingNames4(name, out) {
|
|
22557
22904
|
const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
|
|
22558
|
-
if (
|
|
22905
|
+
if (ts22.isIdentifier(name)) {
|
|
22559
22906
|
push(name.text);
|
|
22560
|
-
} else if (
|
|
22907
|
+
} else if (ts22.isObjectBindingPattern(name)) {
|
|
22561
22908
|
name.elements.forEach((el) => collectBindingNames4(el.name, out));
|
|
22562
|
-
} else if (
|
|
22909
|
+
} else if (ts22.isArrayBindingPattern(name)) {
|
|
22563
22910
|
name.elements.forEach((el) => {
|
|
22564
|
-
if (!
|
|
22911
|
+
if (!ts22.isOmittedExpression(el))
|
|
22565
22912
|
collectBindingNames4(el.name, out);
|
|
22566
22913
|
});
|
|
22567
22914
|
}
|
|
@@ -22588,48 +22935,48 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22588
22935
|
return bound.includes(name);
|
|
22589
22936
|
}
|
|
22590
22937
|
function visit3(node) {
|
|
22591
|
-
if (
|
|
22938
|
+
if (ts22.isIdentifier(node)) {
|
|
22592
22939
|
const parent = node.parent;
|
|
22593
|
-
if (parent &&
|
|
22940
|
+
if (parent && ts22.isPropertyAccessExpression(parent) && parent.name === node)
|
|
22594
22941
|
return;
|
|
22595
|
-
if (parent &&
|
|
22942
|
+
if (parent && ts22.isPropertyAssignment(parent) && parent.name === node)
|
|
22596
22943
|
return;
|
|
22597
|
-
if (parent &&
|
|
22944
|
+
if (parent && ts22.isPropertySignature(parent) && parent.name === node)
|
|
22598
22945
|
return;
|
|
22599
|
-
if (parent &&
|
|
22946
|
+
if (parent && ts22.isPropertyDeclaration(parent) && parent.name === node)
|
|
22600
22947
|
return;
|
|
22601
|
-
if (parent &&
|
|
22948
|
+
if (parent && ts22.isMethodDeclaration(parent) && parent.name === node)
|
|
22602
22949
|
return;
|
|
22603
|
-
if (parent &&
|
|
22950
|
+
if (parent && ts22.isMethodSignature(parent) && parent.name === node)
|
|
22604
22951
|
return;
|
|
22605
|
-
if (parent &&
|
|
22952
|
+
if (parent && ts22.isGetAccessorDeclaration(parent) && parent.name === node)
|
|
22606
22953
|
return;
|
|
22607
|
-
if (parent &&
|
|
22954
|
+
if (parent && ts22.isSetAccessorDeclaration(parent) && parent.name === node)
|
|
22608
22955
|
return;
|
|
22609
|
-
if (parent &&
|
|
22956
|
+
if (parent && ts22.isEnumMember(parent) && parent.name === node)
|
|
22610
22957
|
return;
|
|
22611
|
-
if (parent &&
|
|
22958
|
+
if (parent && ts22.isBindingElement(parent) && parent.propertyName === node)
|
|
22612
22959
|
return;
|
|
22613
|
-
if (parent &&
|
|
22960
|
+
if (parent && ts22.isShorthandPropertyAssignment(parent) && parent.name === node) {
|
|
22614
22961
|
if (!isBound(node.text))
|
|
22615
22962
|
ids.add(node.text);
|
|
22616
22963
|
return;
|
|
22617
22964
|
}
|
|
22618
|
-
if (parent &&
|
|
22965
|
+
if (parent && ts22.isParameter(parent) && parent.name === node)
|
|
22619
22966
|
return;
|
|
22620
|
-
if (parent &&
|
|
22967
|
+
if (parent && ts22.isVariableDeclaration(parent) && parent.name === node)
|
|
22621
22968
|
return;
|
|
22622
|
-
if (parent &&
|
|
22969
|
+
if (parent && ts22.isFunctionDeclaration(parent) && parent.name === node)
|
|
22623
22970
|
return;
|
|
22624
|
-
if (parent &&
|
|
22971
|
+
if (parent && ts22.isClassDeclaration(parent) && parent.name === node)
|
|
22625
22972
|
return;
|
|
22626
|
-
if (parent &&
|
|
22973
|
+
if (parent && ts22.isJsxAttribute(parent) && parent.name === node)
|
|
22627
22974
|
return;
|
|
22628
|
-
if (parent &&
|
|
22975
|
+
if (parent && ts22.isJsxOpeningElement(parent) && parent.tagName === node) {
|
|
22629
22976
|
if (/^[a-z]/.test(node.text))
|
|
22630
22977
|
return;
|
|
22631
22978
|
}
|
|
22632
|
-
if (parent &&
|
|
22979
|
+
if (parent && ts22.isJsxClosingElement(parent) && parent.tagName === node) {
|
|
22633
22980
|
if (/^[a-z]/.test(node.text))
|
|
22634
22981
|
return;
|
|
22635
22982
|
}
|
|
@@ -22638,43 +22985,43 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22638
22985
|
ids.add(node.text);
|
|
22639
22986
|
return;
|
|
22640
22987
|
}
|
|
22641
|
-
if (
|
|
22988
|
+
if (ts22.isVariableDeclaration(node)) {
|
|
22642
22989
|
const declared = pushBindings(node.name);
|
|
22643
22990
|
if (node.initializer)
|
|
22644
22991
|
visit3(node.initializer);
|
|
22645
22992
|
return;
|
|
22646
22993
|
}
|
|
22647
|
-
if (
|
|
22994
|
+
if (ts22.isFunctionDeclaration(node)) {
|
|
22648
22995
|
if (node.name)
|
|
22649
22996
|
bound.push(node.name.text);
|
|
22650
22997
|
visitInsideNewScope(node);
|
|
22651
22998
|
return;
|
|
22652
22999
|
}
|
|
22653
|
-
if (
|
|
23000
|
+
if (ts22.isClassDeclaration(node)) {
|
|
22654
23001
|
if (node.name)
|
|
22655
23002
|
bound.push(node.name.text);
|
|
22656
|
-
|
|
23003
|
+
ts22.forEachChild(node, visit3);
|
|
22657
23004
|
return;
|
|
22658
23005
|
}
|
|
22659
|
-
if (
|
|
23006
|
+
if (ts22.isArrowFunction(node) || ts22.isFunctionExpression(node)) {
|
|
22660
23007
|
visitInsideNewScope(node);
|
|
22661
23008
|
return;
|
|
22662
23009
|
}
|
|
22663
|
-
if (
|
|
23010
|
+
if (ts22.isCatchClause(node)) {
|
|
22664
23011
|
const before = bound.length;
|
|
22665
23012
|
if (node.variableDeclaration)
|
|
22666
23013
|
pushBindings(node.variableDeclaration.name);
|
|
22667
|
-
|
|
23014
|
+
ts22.forEachChild(node, visit3);
|
|
22668
23015
|
popN(bound.length - before);
|
|
22669
23016
|
return;
|
|
22670
23017
|
}
|
|
22671
|
-
if (
|
|
23018
|
+
if (ts22.isBlock(node)) {
|
|
22672
23019
|
const before = bound.length;
|
|
22673
|
-
|
|
23020
|
+
ts22.forEachChild(node, visit3);
|
|
22674
23021
|
popN(bound.length - before);
|
|
22675
23022
|
return;
|
|
22676
23023
|
}
|
|
22677
|
-
|
|
23024
|
+
ts22.forEachChild(node, visit3);
|
|
22678
23025
|
}
|
|
22679
23026
|
function visitInsideNewScope(fn) {
|
|
22680
23027
|
const before = bound.length;
|
|
@@ -22697,29 +23044,29 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22697
23044
|
function collectModuleScopeNames(sourceFile) {
|
|
22698
23045
|
const names = new Set;
|
|
22699
23046
|
for (const stmt of sourceFile.statements) {
|
|
22700
|
-
if (
|
|
23047
|
+
if (ts22.isFunctionDeclaration(stmt) && stmt.name)
|
|
22701
23048
|
names.add(stmt.name.text);
|
|
22702
|
-
else if (
|
|
23049
|
+
else if (ts22.isClassDeclaration(stmt) && stmt.name)
|
|
22703
23050
|
names.add(stmt.name.text);
|
|
22704
|
-
else if (
|
|
23051
|
+
else if (ts22.isVariableStatement(stmt)) {
|
|
22705
23052
|
for (const decl of stmt.declarationList.declarations)
|
|
22706
23053
|
collectBindingNames4(decl.name, names);
|
|
22707
|
-
} else if (
|
|
23054
|
+
} else if (ts22.isImportDeclaration(stmt) && stmt.importClause) {
|
|
22708
23055
|
const ic = stmt.importClause;
|
|
22709
23056
|
if (ic.name)
|
|
22710
23057
|
names.add(ic.name.text);
|
|
22711
23058
|
if (ic.namedBindings) {
|
|
22712
|
-
if (
|
|
23059
|
+
if (ts22.isNamespaceImport(ic.namedBindings))
|
|
22713
23060
|
names.add(ic.namedBindings.name.text);
|
|
22714
23061
|
else
|
|
22715
23062
|
for (const e of ic.namedBindings.elements)
|
|
22716
23063
|
names.add(e.name.text);
|
|
22717
23064
|
}
|
|
22718
|
-
} else if (
|
|
23065
|
+
} else if (ts22.isTypeAliasDeclaration(stmt))
|
|
22719
23066
|
names.add(stmt.name.text);
|
|
22720
|
-
else if (
|
|
23067
|
+
else if (ts22.isInterfaceDeclaration(stmt))
|
|
22721
23068
|
names.add(stmt.name.text);
|
|
22722
|
-
else if (
|
|
23069
|
+
else if (ts22.isEnumDeclaration(stmt))
|
|
22723
23070
|
names.add(stmt.name.text);
|
|
22724
23071
|
}
|
|
22725
23072
|
return names;
|
|
@@ -22727,7 +23074,7 @@ function collectModuleScopeNames(sourceFile) {
|
|
|
22727
23074
|
function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
22728
23075
|
const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
|
|
22729
23076
|
let bodyText;
|
|
22730
|
-
if (
|
|
23077
|
+
if (ts22.isBlock(arrow.body)) {
|
|
22731
23078
|
bodyText = arrow.body.getText(sourceFile);
|
|
22732
23079
|
} else {
|
|
22733
23080
|
const expr = arrow.body.getText(sourceFile);
|
|
@@ -22737,7 +23084,7 @@ function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
|
22737
23084
|
}
|
|
22738
23085
|
|
|
22739
23086
|
// ../jsx/src/ssr-defaults.ts
|
|
22740
|
-
import
|
|
23087
|
+
import ts23 from "typescript";
|
|
22741
23088
|
var UNRESOLVED = Symbol("unresolved");
|
|
22742
23089
|
var NO_RETURN = Symbol("no-return");
|
|
22743
23090
|
function extractSsrDefaults(metadata) {
|
|
@@ -22841,11 +23188,11 @@ function collectPropRefs(expr, propsObjectName, out) {
|
|
|
22841
23188
|
if (!node)
|
|
22842
23189
|
return;
|
|
22843
23190
|
const visit3 = (n) => {
|
|
22844
|
-
if (
|
|
23191
|
+
if (ts23.isPropertyAccessExpression(n) && ts23.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts23.isIdentifier(n.name)) {
|
|
22845
23192
|
out.add(n.name.text);
|
|
22846
23193
|
return;
|
|
22847
23194
|
}
|
|
22848
|
-
|
|
23195
|
+
ts23.forEachChild(n, visit3);
|
|
22849
23196
|
};
|
|
22850
23197
|
visit3(node);
|
|
22851
23198
|
}
|
|
@@ -22883,23 +23230,23 @@ function tryStaticEval(expr, ctx) {
|
|
|
22883
23230
|
}
|
|
22884
23231
|
function evalStatementsForReturn(statements, ctx) {
|
|
22885
23232
|
for (const stmt of statements) {
|
|
22886
|
-
if (
|
|
23233
|
+
if (ts23.isVariableStatement(stmt)) {
|
|
22887
23234
|
for (const d of stmt.declarationList.declarations) {
|
|
22888
|
-
if (!
|
|
23235
|
+
if (!ts23.isIdentifier(d.name) || !d.initializer)
|
|
22889
23236
|
continue;
|
|
22890
23237
|
const v = evalNode(d.initializer, ctx);
|
|
22891
23238
|
if (v !== UNRESOLVED)
|
|
22892
23239
|
ctx.bindings[d.name.text] = v;
|
|
22893
23240
|
}
|
|
22894
|
-
} else if (
|
|
23241
|
+
} else if (ts23.isReturnStatement(stmt)) {
|
|
22895
23242
|
return stmt.expression ? evalNode(stmt.expression, ctx) : UNRESOLVED;
|
|
22896
|
-
} else if (
|
|
23243
|
+
} else if (ts23.isIfStatement(stmt)) {
|
|
22897
23244
|
const cond = evalNode(stmt.expression, ctx);
|
|
22898
23245
|
if (cond === UNRESOLVED)
|
|
22899
23246
|
return UNRESOLVED;
|
|
22900
23247
|
const branch = cond ? stmt.thenStatement : stmt.elseStatement;
|
|
22901
23248
|
if (branch) {
|
|
22902
|
-
const taken = evalStatementsForReturn(
|
|
23249
|
+
const taken = evalStatementsForReturn(ts23.isBlock(branch) ? branch.statements : [branch], ctx);
|
|
22903
23250
|
if (taken !== NO_RETURN)
|
|
22904
23251
|
return taken;
|
|
22905
23252
|
}
|
|
@@ -22910,45 +23257,45 @@ function evalStatementsForReturn(statements, ctx) {
|
|
|
22910
23257
|
return NO_RETURN;
|
|
22911
23258
|
}
|
|
22912
23259
|
function parseExpression2(expr) {
|
|
22913
|
-
const sf =
|
|
23260
|
+
const sf = ts23.createSourceFile("__ssr_default__.ts", `(${expr})`, ts23.ScriptTarget.Latest, true, ts23.ScriptKind.TS);
|
|
22914
23261
|
const stmt = sf.statements[0];
|
|
22915
|
-
if (!stmt || !
|
|
23262
|
+
if (!stmt || !ts23.isExpressionStatement(stmt))
|
|
22916
23263
|
return null;
|
|
22917
|
-
const inner =
|
|
23264
|
+
const inner = ts23.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
22918
23265
|
return inner;
|
|
22919
23266
|
}
|
|
22920
23267
|
function evalNode(node, ctx) {
|
|
22921
|
-
if (
|
|
23268
|
+
if (ts23.isParenthesizedExpression(node))
|
|
22922
23269
|
return evalNode(node.expression, ctx);
|
|
22923
|
-
if (
|
|
23270
|
+
if (ts23.isAsExpression(node))
|
|
22924
23271
|
return evalNode(node.expression, ctx);
|
|
22925
|
-
if (
|
|
23272
|
+
if (ts23.isSatisfiesExpression(node))
|
|
22926
23273
|
return evalNode(node.expression, ctx);
|
|
22927
|
-
if (
|
|
23274
|
+
if (ts23.isTypeAssertionExpression(node))
|
|
22928
23275
|
return evalNode(node.expression, ctx);
|
|
22929
|
-
if (
|
|
23276
|
+
if (ts23.isNonNullExpression(node))
|
|
22930
23277
|
return evalNode(node.expression, ctx);
|
|
22931
|
-
if (
|
|
23278
|
+
if (ts23.isArrowFunction(node)) {
|
|
22932
23279
|
if (node.parameters.length !== 0)
|
|
22933
23280
|
return UNRESOLVED;
|
|
22934
|
-
if (!
|
|
23281
|
+
if (!ts23.isBlock(node.body))
|
|
22935
23282
|
return evalNode(node.body, ctx);
|
|
22936
23283
|
const localBindings = { ...ctx.bindings };
|
|
22937
23284
|
const localCtx = { ...ctx, bindings: localBindings };
|
|
22938
23285
|
const result = evalStatementsForReturn(node.body.statements, localCtx);
|
|
22939
23286
|
return result === NO_RETURN ? UNRESOLVED : result;
|
|
22940
23287
|
}
|
|
22941
|
-
if (
|
|
23288
|
+
if (ts23.isNumericLiteral(node))
|
|
22942
23289
|
return Number(node.text);
|
|
22943
|
-
if (
|
|
23290
|
+
if (ts23.isStringLiteralLike(node))
|
|
22944
23291
|
return node.text;
|
|
22945
|
-
if (node.kind ===
|
|
23292
|
+
if (node.kind === ts23.SyntaxKind.TrueKeyword)
|
|
22946
23293
|
return true;
|
|
22947
|
-
if (node.kind ===
|
|
23294
|
+
if (node.kind === ts23.SyntaxKind.FalseKeyword)
|
|
22948
23295
|
return false;
|
|
22949
|
-
if (node.kind ===
|
|
23296
|
+
if (node.kind === ts23.SyntaxKind.NullKeyword)
|
|
22950
23297
|
return null;
|
|
22951
|
-
if (
|
|
23298
|
+
if (ts23.isIdentifier(node)) {
|
|
22952
23299
|
if (node.text === "undefined")
|
|
22953
23300
|
return;
|
|
22954
23301
|
if (node.text in ctx.bindings)
|
|
@@ -22957,29 +23304,29 @@ function evalNode(node, ctx) {
|
|
|
22957
23304
|
return;
|
|
22958
23305
|
return UNRESOLVED;
|
|
22959
23306
|
}
|
|
22960
|
-
if (
|
|
23307
|
+
if (ts23.isPrefixUnaryExpression(node)) {
|
|
22961
23308
|
const arg = evalNode(node.operand, ctx);
|
|
22962
23309
|
if (arg === UNRESOLVED)
|
|
22963
23310
|
return UNRESOLVED;
|
|
22964
23311
|
switch (node.operator) {
|
|
22965
|
-
case
|
|
23312
|
+
case ts23.SyntaxKind.MinusToken:
|
|
22966
23313
|
return typeof arg === "number" ? -arg : UNRESOLVED;
|
|
22967
|
-
case
|
|
23314
|
+
case ts23.SyntaxKind.PlusToken:
|
|
22968
23315
|
return typeof arg === "number" ? +arg : UNRESOLVED;
|
|
22969
|
-
case
|
|
23316
|
+
case ts23.SyntaxKind.ExclamationToken:
|
|
22970
23317
|
return !arg;
|
|
22971
23318
|
}
|
|
22972
23319
|
return UNRESOLVED;
|
|
22973
23320
|
}
|
|
22974
|
-
if (
|
|
23321
|
+
if (ts23.isObjectLiteralExpression(node)) {
|
|
22975
23322
|
const obj = {};
|
|
22976
23323
|
for (const prop of node.properties) {
|
|
22977
|
-
if (!
|
|
23324
|
+
if (!ts23.isPropertyAssignment(prop))
|
|
22978
23325
|
return UNRESOLVED;
|
|
22979
23326
|
let key;
|
|
22980
|
-
if (
|
|
23327
|
+
if (ts23.isIdentifier(prop.name) || ts23.isStringLiteralLike(prop.name)) {
|
|
22981
23328
|
key = prop.name.text;
|
|
22982
|
-
} else if (
|
|
23329
|
+
} else if (ts23.isNumericLiteral(prop.name)) {
|
|
22983
23330
|
key = prop.name.text;
|
|
22984
23331
|
} else {
|
|
22985
23332
|
return UNRESOLVED;
|
|
@@ -22991,10 +23338,10 @@ function evalNode(node, ctx) {
|
|
|
22991
23338
|
}
|
|
22992
23339
|
return obj;
|
|
22993
23340
|
}
|
|
22994
|
-
if (
|
|
23341
|
+
if (ts23.isArrayLiteralExpression(node)) {
|
|
22995
23342
|
const arr = [];
|
|
22996
23343
|
for (const elem of node.elements) {
|
|
22997
|
-
if (
|
|
23344
|
+
if (ts23.isOmittedExpression(elem))
|
|
22998
23345
|
return UNRESOLVED;
|
|
22999
23346
|
const v = evalNode(elem, ctx);
|
|
23000
23347
|
if (v === UNRESOLVED)
|
|
@@ -23003,7 +23350,7 @@ function evalNode(node, ctx) {
|
|
|
23003
23350
|
}
|
|
23004
23351
|
return arr;
|
|
23005
23352
|
}
|
|
23006
|
-
if (
|
|
23353
|
+
if (ts23.isElementAccessExpression(node)) {
|
|
23007
23354
|
const base = evalNode(node.expression, ctx);
|
|
23008
23355
|
if (base === undefined)
|
|
23009
23356
|
return;
|
|
@@ -23017,7 +23364,7 @@ function evalNode(node, ctx) {
|
|
|
23017
23364
|
const k = String(key);
|
|
23018
23365
|
return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
|
|
23019
23366
|
}
|
|
23020
|
-
if (
|
|
23367
|
+
if (ts23.isPropertyAccessExpression(node)) {
|
|
23021
23368
|
const baseResult = evalNode(node.expression, ctx);
|
|
23022
23369
|
if (baseResult === undefined)
|
|
23023
23370
|
return;
|
|
@@ -23030,13 +23377,13 @@ function evalNode(node, ctx) {
|
|
|
23030
23377
|
const key = node.name.text;
|
|
23031
23378
|
return Object.prototype.hasOwnProperty.call(baseResult, key) ? baseResult[key] : undefined;
|
|
23032
23379
|
}
|
|
23033
|
-
if (
|
|
23034
|
-
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) {
|
|
23035
23382
|
return ctx.bindings[node.expression.text];
|
|
23036
23383
|
}
|
|
23037
|
-
if (
|
|
23384
|
+
if (ts23.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map" && node.arguments.length === 1) {
|
|
23038
23385
|
const arrow = node.arguments[0];
|
|
23039
|
-
if (
|
|
23386
|
+
if (ts23.isArrowFunction(arrow) && arrow.parameters.length === 1 && ts23.isIdentifier(arrow.parameters[0].name) && !ts23.isBlock(arrow.body)) {
|
|
23040
23387
|
const recv = evalNode(node.expression.expression, ctx);
|
|
23041
23388
|
if (Array.isArray(recv)) {
|
|
23042
23389
|
const paramName = arrow.parameters[0].name.text;
|
|
@@ -23053,7 +23400,7 @@ function evalNode(node, ctx) {
|
|
|
23053
23400
|
}
|
|
23054
23401
|
return UNRESOLVED;
|
|
23055
23402
|
}
|
|
23056
|
-
if (
|
|
23403
|
+
if (ts23.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
|
|
23057
23404
|
const recv = evalNode(node.expression.expression, ctx);
|
|
23058
23405
|
if (Array.isArray(recv)) {
|
|
23059
23406
|
let sep = ",";
|
|
@@ -23069,27 +23416,27 @@ function evalNode(node, ctx) {
|
|
|
23069
23416
|
}
|
|
23070
23417
|
return UNRESOLVED;
|
|
23071
23418
|
}
|
|
23072
|
-
if (
|
|
23419
|
+
if (ts23.isConditionalExpression(node)) {
|
|
23073
23420
|
const cond = evalNode(node.condition, ctx);
|
|
23074
23421
|
if (cond === UNRESOLVED)
|
|
23075
23422
|
return UNRESOLVED;
|
|
23076
23423
|
return cond ? evalNode(node.whenTrue, ctx) : evalNode(node.whenFalse, ctx);
|
|
23077
23424
|
}
|
|
23078
|
-
if (
|
|
23425
|
+
if (ts23.isBinaryExpression(node)) {
|
|
23079
23426
|
const op = node.operatorToken.kind;
|
|
23080
|
-
if (op ===
|
|
23427
|
+
if (op === ts23.SyntaxKind.QuestionQuestionToken) {
|
|
23081
23428
|
const l2 = evalNode(node.left, ctx);
|
|
23082
23429
|
if (l2 !== UNRESOLVED && l2 !== null && l2 !== undefined)
|
|
23083
23430
|
return l2;
|
|
23084
23431
|
return evalNode(node.right, ctx);
|
|
23085
23432
|
}
|
|
23086
|
-
if (op ===
|
|
23433
|
+
if (op === ts23.SyntaxKind.BarBarToken) {
|
|
23087
23434
|
const l2 = evalNode(node.left, ctx);
|
|
23088
23435
|
if (l2 !== UNRESOLVED && l2)
|
|
23089
23436
|
return l2;
|
|
23090
23437
|
return evalNode(node.right, ctx);
|
|
23091
23438
|
}
|
|
23092
|
-
if (op ===
|
|
23439
|
+
if (op === ts23.SyntaxKind.AmpersandAmpersandToken) {
|
|
23093
23440
|
const l2 = evalNode(node.left, ctx);
|
|
23094
23441
|
if (l2 === UNRESOLVED)
|
|
23095
23442
|
return UNRESOLVED;
|
|
@@ -23102,30 +23449,30 @@ function evalNode(node, ctx) {
|
|
|
23102
23449
|
if (l === UNRESOLVED || r === UNRESOLVED)
|
|
23103
23450
|
return UNRESOLVED;
|
|
23104
23451
|
switch (op) {
|
|
23105
|
-
case
|
|
23452
|
+
case ts23.SyntaxKind.PlusToken:
|
|
23106
23453
|
if (typeof l === "string" || typeof r === "string")
|
|
23107
23454
|
return `${l}${r}`;
|
|
23108
23455
|
if (typeof l === "number" && typeof r === "number")
|
|
23109
23456
|
return l + r;
|
|
23110
23457
|
return UNRESOLVED;
|
|
23111
|
-
case
|
|
23458
|
+
case ts23.SyntaxKind.MinusToken:
|
|
23112
23459
|
return typeof l === "number" && typeof r === "number" ? l - r : UNRESOLVED;
|
|
23113
|
-
case
|
|
23460
|
+
case ts23.SyntaxKind.AsteriskToken:
|
|
23114
23461
|
return typeof l === "number" && typeof r === "number" ? l * r : UNRESOLVED;
|
|
23115
|
-
case
|
|
23462
|
+
case ts23.SyntaxKind.SlashToken:
|
|
23116
23463
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l / r : UNRESOLVED;
|
|
23117
|
-
case
|
|
23464
|
+
case ts23.SyntaxKind.PercentToken:
|
|
23118
23465
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l % r : UNRESOLVED;
|
|
23119
|
-
case
|
|
23120
|
-
case
|
|
23466
|
+
case ts23.SyntaxKind.EqualsEqualsEqualsToken:
|
|
23467
|
+
case ts23.SyntaxKind.EqualsEqualsToken:
|
|
23121
23468
|
return l === r;
|
|
23122
|
-
case
|
|
23123
|
-
case
|
|
23469
|
+
case ts23.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
23470
|
+
case ts23.SyntaxKind.ExclamationEqualsToken:
|
|
23124
23471
|
return l !== r;
|
|
23125
23472
|
}
|
|
23126
23473
|
return UNRESOLVED;
|
|
23127
23474
|
}
|
|
23128
|
-
if (
|
|
23475
|
+
if (ts23.isTemplateExpression(node)) {
|
|
23129
23476
|
if (node.templateSpans.length === 0)
|
|
23130
23477
|
return node.head.text;
|
|
23131
23478
|
let acc = node.head.text;
|
|
@@ -23137,41 +23484,41 @@ function evalNode(node, ctx) {
|
|
|
23137
23484
|
}
|
|
23138
23485
|
return acc;
|
|
23139
23486
|
}
|
|
23140
|
-
if (
|
|
23487
|
+
if (ts23.isNoSubstitutionTemplateLiteral(node))
|
|
23141
23488
|
return node.text;
|
|
23142
23489
|
return UNRESOLVED;
|
|
23143
23490
|
}
|
|
23144
23491
|
|
|
23145
23492
|
// ../jsx/src/augment-inherited-props.ts
|
|
23146
|
-
import
|
|
23493
|
+
import ts24 from "typescript";
|
|
23147
23494
|
function parseStaticStringConst(source) {
|
|
23148
|
-
const sf =
|
|
23495
|
+
const sf = ts24.createSourceFile("__const.ts", `const __x = (${source});`, ts24.ScriptTarget.Latest, false);
|
|
23149
23496
|
const stmt = sf.statements[0];
|
|
23150
|
-
if (!stmt || !
|
|
23497
|
+
if (!stmt || !ts24.isVariableStatement(stmt))
|
|
23151
23498
|
return null;
|
|
23152
23499
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
23153
|
-
while (init &&
|
|
23500
|
+
while (init && ts24.isParenthesizedExpression(init))
|
|
23154
23501
|
init = init.expression;
|
|
23155
23502
|
if (!init)
|
|
23156
23503
|
return null;
|
|
23157
|
-
if (
|
|
23504
|
+
if (ts24.isStringLiteral(init) || ts24.isNoSubstitutionTemplateLiteral(init)) {
|
|
23158
23505
|
return init.text;
|
|
23159
23506
|
}
|
|
23160
23507
|
return evalStringArrayJoin(source);
|
|
23161
23508
|
}
|
|
23162
23509
|
function evalTemplateOfStringConsts(source, resolved) {
|
|
23163
|
-
const sf =
|
|
23510
|
+
const sf = ts24.createSourceFile("__const.ts", `const __x = (${source});`, ts24.ScriptTarget.Latest, false);
|
|
23164
23511
|
const stmt = sf.statements[0];
|
|
23165
|
-
if (!stmt || !
|
|
23512
|
+
if (!stmt || !ts24.isVariableStatement(stmt))
|
|
23166
23513
|
return null;
|
|
23167
23514
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
23168
|
-
while (init &&
|
|
23515
|
+
while (init && ts24.isParenthesizedExpression(init))
|
|
23169
23516
|
init = init.expression;
|
|
23170
|
-
if (!init || !
|
|
23517
|
+
if (!init || !ts24.isTemplateExpression(init))
|
|
23171
23518
|
return null;
|
|
23172
23519
|
let out = init.head.text;
|
|
23173
23520
|
for (const span of init.templateSpans) {
|
|
23174
|
-
if (!
|
|
23521
|
+
if (!ts24.isIdentifier(span.expression))
|
|
23175
23522
|
return null;
|
|
23176
23523
|
const value = resolved.get(span.expression.text);
|
|
23177
23524
|
if (value === undefined)
|
|
@@ -23199,28 +23546,28 @@ function collectModuleStringConsts(constants) {
|
|
|
23199
23546
|
return map;
|
|
23200
23547
|
}
|
|
23201
23548
|
function evalStringArrayJoin(source) {
|
|
23202
|
-
const sf =
|
|
23549
|
+
const sf = ts24.createSourceFile("__join.ts", `const __x = (${source});`, ts24.ScriptTarget.Latest, false);
|
|
23203
23550
|
const stmt = sf.statements[0];
|
|
23204
|
-
if (!stmt || !
|
|
23551
|
+
if (!stmt || !ts24.isVariableStatement(stmt))
|
|
23205
23552
|
return null;
|
|
23206
23553
|
let node = stmt.declarationList.declarations[0]?.initializer;
|
|
23207
|
-
while (node &&
|
|
23554
|
+
while (node && ts24.isParenthesizedExpression(node))
|
|
23208
23555
|
node = node.expression;
|
|
23209
|
-
if (!node || !
|
|
23556
|
+
if (!node || !ts24.isCallExpression(node))
|
|
23210
23557
|
return null;
|
|
23211
23558
|
const callee = node.expression;
|
|
23212
|
-
if (!
|
|
23559
|
+
if (!ts24.isPropertyAccessExpression(callee))
|
|
23213
23560
|
return null;
|
|
23214
23561
|
if (callee.name.text !== "join")
|
|
23215
23562
|
return null;
|
|
23216
23563
|
let recv = callee.expression;
|
|
23217
|
-
while (
|
|
23564
|
+
while (ts24.isParenthesizedExpression(recv))
|
|
23218
23565
|
recv = recv.expression;
|
|
23219
|
-
if (!
|
|
23566
|
+
if (!ts24.isArrayLiteralExpression(recv))
|
|
23220
23567
|
return null;
|
|
23221
23568
|
const parts = [];
|
|
23222
23569
|
for (const el of recv.elements) {
|
|
23223
|
-
if (
|
|
23570
|
+
if (ts24.isStringLiteral(el) || ts24.isNoSubstitutionTemplateLiteral(el)) {
|
|
23224
23571
|
parts.push(el.text);
|
|
23225
23572
|
} else {
|
|
23226
23573
|
return null;
|
|
@@ -23229,7 +23576,7 @@ function evalStringArrayJoin(source) {
|
|
|
23229
23576
|
let sep = ",";
|
|
23230
23577
|
if (node.arguments.length >= 1) {
|
|
23231
23578
|
const arg = node.arguments[0];
|
|
23232
|
-
if (
|
|
23579
|
+
if (ts24.isStringLiteral(arg) || ts24.isNoSubstitutionTemplateLiteral(arg))
|
|
23233
23580
|
sep = arg.text;
|
|
23234
23581
|
else
|
|
23235
23582
|
return null;
|
|
@@ -23589,31 +23936,54 @@ function walkNode2(node, meta, bindings, matchers, errors, seen) {
|
|
|
23589
23936
|
function mergeTemplateImports(lines) {
|
|
23590
23937
|
const result = [];
|
|
23591
23938
|
const valueIdx = new Map;
|
|
23939
|
+
const valueDefault = new Map;
|
|
23592
23940
|
const valueNames = new Map;
|
|
23593
23941
|
const typeIdx = new Map;
|
|
23594
23942
|
const typeNames = new Map;
|
|
23595
23943
|
const seenOther = new Set;
|
|
23596
|
-
const
|
|
23597
|
-
if (!
|
|
23598
|
-
|
|
23599
|
-
|
|
23944
|
+
const foldType = (src, rawNames) => {
|
|
23945
|
+
if (!typeIdx.has(src)) {
|
|
23946
|
+
typeIdx.set(src, result.length);
|
|
23947
|
+
typeNames.set(src, new Set);
|
|
23600
23948
|
result.push("");
|
|
23601
23949
|
}
|
|
23602
|
-
const set =
|
|
23950
|
+
const set = typeNames.get(src);
|
|
23603
23951
|
for (const n of rawNames.split(",").map((s) => s.trim()).filter(Boolean))
|
|
23604
23952
|
set.add(n);
|
|
23605
|
-
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
|
+
`);
|
|
23606
23970
|
};
|
|
23607
23971
|
for (const raw of lines) {
|
|
23608
23972
|
const line = raw.trim();
|
|
23609
23973
|
if (!line)
|
|
23610
23974
|
continue;
|
|
23611
23975
|
const typeMatch = line.match(/^import\s+type\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]\s*;?$/);
|
|
23612
|
-
const
|
|
23613
|
-
|
|
23614
|
-
|
|
23615
|
-
|
|
23616
|
-
|
|
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);
|
|
23617
23987
|
} else if (!seenOther.has(line)) {
|
|
23618
23988
|
seenOther.add(line);
|
|
23619
23989
|
result.push(line);
|
|
@@ -23655,13 +24025,13 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23655
24025
|
if (entries.some((e) => e.componentIR.metadata.isClientComponent)) {
|
|
23656
24026
|
const topLevelNames = new Set;
|
|
23657
24027
|
{
|
|
23658
|
-
const sf =
|
|
24028
|
+
const sf = ts25.createSourceFile(filePath, source, ts25.ScriptTarget.Latest, true, ts25.ScriptKind.TSX);
|
|
23659
24029
|
for (const stmt of sf.statements) {
|
|
23660
|
-
if (
|
|
24030
|
+
if (ts25.isFunctionDeclaration(stmt) && stmt.name)
|
|
23661
24031
|
topLevelNames.add(stmt.name.text);
|
|
23662
|
-
else if (
|
|
24032
|
+
else if (ts25.isVariableStatement(stmt)) {
|
|
23663
24033
|
for (const d of stmt.declarationList.declarations) {
|
|
23664
|
-
if (
|
|
24034
|
+
if (ts25.isIdentifier(d.name))
|
|
23665
24035
|
topLevelNames.add(d.name.text);
|
|
23666
24036
|
}
|
|
23667
24037
|
}
|
|
@@ -23720,7 +24090,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23720
24090
|
const moduleStatementSeen = new Set;
|
|
23721
24091
|
const moduleStatementsOrdered = [];
|
|
23722
24092
|
const collectModuleStatements = (block) => {
|
|
23723
|
-
const sf =
|
|
24093
|
+
const sf = ts25.createSourceFile("__bf_module_decls.tsx", block, ts25.ScriptTarget.Latest, false, ts25.ScriptKind.TSX);
|
|
23724
24094
|
for (const stmt of sf.statements) {
|
|
23725
24095
|
const text = stmt.getText(sf);
|
|
23726
24096
|
if (moduleStatementSeen.has(text))
|
|
@@ -23809,32 +24179,9 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23809
24179
|
}
|
|
23810
24180
|
const clientJsOutputs2 = allOutputs.map((o) => o.clientJs).filter(Boolean);
|
|
23811
24181
|
if (clientJsOutputs2.length > 0) {
|
|
23812
|
-
const importsBySource = new Map;
|
|
23813
|
-
const otherImports = [];
|
|
23814
|
-
const allCode = [];
|
|
23815
|
-
for (const js of clientJsOutputs2) {
|
|
23816
|
-
for (const line of js.split(`
|
|
23817
|
-
`)) {
|
|
23818
|
-
if (line.startsWith("import ")) {
|
|
23819
|
-
const match = line.match(/^import \{ ([^}]+) \} from ['"]([^'"]+)['"]$/);
|
|
23820
|
-
if (match) {
|
|
23821
|
-
const source2 = match[2];
|
|
23822
|
-
if (!importsBySource.has(source2))
|
|
23823
|
-
importsBySource.set(source2, new Set);
|
|
23824
|
-
for (const n of match[1].split(",").map((n2) => n2.trim()))
|
|
23825
|
-
importsBySource.get(source2).add(n);
|
|
23826
|
-
} else if (!otherImports.includes(line)) {
|
|
23827
|
-
otherImports.push(line);
|
|
23828
|
-
}
|
|
23829
|
-
}
|
|
23830
|
-
}
|
|
23831
|
-
allCode.push(js.replace(/^import .+\n/gm, "").trim());
|
|
23832
|
-
}
|
|
23833
|
-
const mergedClientImports = [...importsBySource].map(([src, names]) => `import { ${[...names].sort().join(", ")} } from '${src}'`);
|
|
23834
24182
|
files.push({
|
|
23835
24183
|
path: filePath.replace(/\.tsx?$/, ".client.js"),
|
|
23836
|
-
content:
|
|
23837
|
-
`),
|
|
24184
|
+
content: mergeCompiledClientJsImports(clientJsOutputs2),
|
|
23838
24185
|
type: "clientJs"
|
|
23839
24186
|
});
|
|
23840
24187
|
}
|
|
@@ -23905,53 +24252,9 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23905
24252
|
}
|
|
23906
24253
|
const clientJsOutputs = allOutputs.map((o) => o.clientJs).filter(Boolean);
|
|
23907
24254
|
if (clientJsOutputs.length > 0) {
|
|
23908
|
-
const importsBySource = new Map;
|
|
23909
|
-
const otherImports = [];
|
|
23910
|
-
const allCode = [];
|
|
23911
|
-
for (const js of clientJsOutputs) {
|
|
23912
|
-
const lines = js.split(`
|
|
23913
|
-
`);
|
|
23914
|
-
const codeLines = [];
|
|
23915
|
-
for (const line of lines) {
|
|
23916
|
-
if (line.startsWith("import ")) {
|
|
23917
|
-
const match = line.match(/^import \{ ([^}]+) \} from ['"]([^'"]+)['"]$/);
|
|
23918
|
-
if (match) {
|
|
23919
|
-
const names = match[1].split(",").map((n) => n.trim());
|
|
23920
|
-
const source2 = match[2];
|
|
23921
|
-
if (!importsBySource.has(source2)) {
|
|
23922
|
-
importsBySource.set(source2, new Set);
|
|
23923
|
-
}
|
|
23924
|
-
const set = importsBySource.get(source2);
|
|
23925
|
-
for (const name of names) {
|
|
23926
|
-
set.add(name);
|
|
23927
|
-
}
|
|
23928
|
-
} else {
|
|
23929
|
-
if (!otherImports.includes(line)) {
|
|
23930
|
-
otherImports.push(line);
|
|
23931
|
-
}
|
|
23932
|
-
}
|
|
23933
|
-
} else {
|
|
23934
|
-
codeLines.push(line);
|
|
23935
|
-
}
|
|
23936
|
-
}
|
|
23937
|
-
allCode.push(codeLines.join(`
|
|
23938
|
-
`).trim());
|
|
23939
|
-
}
|
|
23940
|
-
const mergedImports2 = [];
|
|
23941
|
-
for (const [source2, names] of importsBySource) {
|
|
23942
|
-
const sortedNames = [...names].sort();
|
|
23943
|
-
mergedImports2.push(`import { ${sortedNames.join(", ")} } from '${source2}'`);
|
|
23944
|
-
}
|
|
23945
|
-
const combinedClientJs = [
|
|
23946
|
-
...mergedImports2,
|
|
23947
|
-
...otherImports,
|
|
23948
|
-
"",
|
|
23949
|
-
...allCode.filter(Boolean)
|
|
23950
|
-
].join(`
|
|
23951
|
-
`);
|
|
23952
24255
|
files.push({
|
|
23953
24256
|
path: filePath.replace(/\.tsx?$/, ".client.js"),
|
|
23954
|
-
content:
|
|
24257
|
+
content: mergeCompiledClientJsImports(clientJsOutputs),
|
|
23955
24258
|
type: "clientJs"
|
|
23956
24259
|
});
|
|
23957
24260
|
}
|
|
@@ -24024,10 +24327,24 @@ function compileJSX(source, filePath, options) {
|
|
|
24024
24327
|
externalImportLines.push(`import '${imp.source}'`);
|
|
24025
24328
|
continue;
|
|
24026
24329
|
}
|
|
24027
|
-
const
|
|
24028
|
-
|
|
24029
|
-
|
|
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
|
+
}
|
|
24030
24346
|
}
|
|
24347
|
+
externalImportLines.push(...renderUsedImportLines(imp.source, usedDefault, usedNamespace, usedNamed));
|
|
24031
24348
|
}
|
|
24032
24349
|
const allImports = [runtimeImportLine, ...externalImportLines].filter(Boolean).join(`
|
|
24033
24350
|
`);
|
|
@@ -24163,7 +24480,7 @@ function compileJSX(source, filePath, options) {
|
|
|
24163
24480
|
return { files, errors };
|
|
24164
24481
|
}
|
|
24165
24482
|
// ../jsx/src/shared-program.ts
|
|
24166
|
-
import
|
|
24483
|
+
import ts26 from "typescript";
|
|
24167
24484
|
import path3 from "node:path";
|
|
24168
24485
|
function commonParent(paths) {
|
|
24169
24486
|
if (paths.length === 0)
|
|
@@ -24185,10 +24502,10 @@ function commonParent(paths) {
|
|
|
24185
24502
|
function createProgramForCorpus(files, options = {}) {
|
|
24186
24503
|
const baseUrl = options.baseUrl ?? commonParent(files);
|
|
24187
24504
|
const compilerOptions = {
|
|
24188
|
-
target:
|
|
24189
|
-
module:
|
|
24190
|
-
moduleResolution:
|
|
24191
|
-
jsx:
|
|
24505
|
+
target: ts26.ScriptTarget.Latest,
|
|
24506
|
+
module: ts26.ModuleKind.ESNext,
|
|
24507
|
+
moduleResolution: ts26.ModuleResolutionKind.Bundler,
|
|
24508
|
+
jsx: ts26.JsxEmit.ReactJSX,
|
|
24192
24509
|
strict: true,
|
|
24193
24510
|
skipLibCheck: true,
|
|
24194
24511
|
noEmit: true,
|
|
@@ -24198,7 +24515,7 @@ function createProgramForCorpus(files, options = {}) {
|
|
|
24198
24515
|
...options.compilerOptions
|
|
24199
24516
|
};
|
|
24200
24517
|
const absolute = files.map((f) => path3.resolve(f));
|
|
24201
|
-
return
|
|
24518
|
+
return ts26.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
|
|
24202
24519
|
}
|
|
24203
24520
|
// ../jsx/src/adapters/interface.ts
|
|
24204
24521
|
class BaseAdapter {
|
|
@@ -24481,7 +24798,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
24481
24798
|
}
|
|
24482
24799
|
|
|
24483
24800
|
// ../jsx/src/adapters/template-imports.ts
|
|
24484
|
-
import
|
|
24801
|
+
import ts27 from "typescript";
|
|
24485
24802
|
var CLIENT_PACKAGE_SOURCES = new Set([
|
|
24486
24803
|
"@barefootjs/client",
|
|
24487
24804
|
"@barefootjs/client/runtime"
|
|
@@ -24874,11 +25191,11 @@ function registerBuiltinLoweringPlugins() {
|
|
|
24874
25191
|
registerLoweringPlugin(plugin);
|
|
24875
25192
|
}
|
|
24876
25193
|
// ../jsx/src/combine-client-js.ts
|
|
24877
|
-
import ts27 from "typescript";
|
|
24878
|
-
// ../jsx/src/debug.ts
|
|
24879
25194
|
import ts28 from "typescript";
|
|
24880
|
-
// ../jsx/src/
|
|
25195
|
+
// ../jsx/src/debug.ts
|
|
24881
25196
|
import ts29 from "typescript";
|
|
25197
|
+
// ../jsx/src/profiler.ts
|
|
25198
|
+
import ts30 from "typescript";
|
|
24882
25199
|
|
|
24883
25200
|
// ../jsx/src/index.ts
|
|
24884
25201
|
registerBuiltinLoweringPlugins();
|
|
@@ -25017,21 +25334,24 @@ async function discoverComponents(entries, readFile) {
|
|
|
25017
25334
|
seen.add(absPath);
|
|
25018
25335
|
const content = await readFile(absPath);
|
|
25019
25336
|
const isClient = hasUseClientDirective(content);
|
|
25337
|
+
const scan = scanComponentFile(content, absPath);
|
|
25020
25338
|
out.push({
|
|
25021
25339
|
absPath,
|
|
25022
25340
|
content,
|
|
25023
25341
|
isClient,
|
|
25024
|
-
exportedComponents:
|
|
25342
|
+
exportedComponents: scan.exports,
|
|
25343
|
+
referencedComponents: scan.referencedComponents,
|
|
25025
25344
|
cssLayerPrefix: entry.cssLayerPrefix
|
|
25026
25345
|
});
|
|
25027
25346
|
}
|
|
25028
25347
|
}
|
|
25029
|
-
|
|
25348
|
+
const clientEntryPaths = computeClientEntryPaths(out);
|
|
25349
|
+
return out.map((row) => ({ ...row, needsClientEntry: clientEntryPaths.has(row.absPath) }));
|
|
25030
25350
|
}
|
|
25031
|
-
function
|
|
25351
|
+
function nameIndexOver(rows, include) {
|
|
25032
25352
|
const index = new Map;
|
|
25033
|
-
for (const c of
|
|
25034
|
-
if (!c
|
|
25353
|
+
for (const c of rows) {
|
|
25354
|
+
if (!include(c))
|
|
25035
25355
|
continue;
|
|
25036
25356
|
const names = c.exportedComponents.length > 0 ? c.exportedComponents : [basename(c.absPath).replace(/\.tsx?$/, "")];
|
|
25037
25357
|
for (const name of names) {
|
|
@@ -25041,6 +25361,44 @@ function buildChildNameIndex(discovered) {
|
|
|
25041
25361
|
}
|
|
25042
25362
|
return index;
|
|
25043
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
|
+
}
|
|
25044
25402
|
|
|
25045
25403
|
// src/resolve-client-js.ts
|
|
25046
25404
|
import { existsSync } from "node:fs";
|
|
@@ -25375,7 +25733,7 @@ function barefoot(options) {
|
|
|
25375
25733
|
const canonical = compileCanonical(component.absPath, content);
|
|
25376
25734
|
reportErrors(canonical, content, projectDir);
|
|
25377
25735
|
let result = canonical;
|
|
25378
|
-
if (component.
|
|
25736
|
+
if (component.needsClientEntry) {
|
|
25379
25737
|
const { scriptAssets, preloadAssets } = resolveAssetsFor(component);
|
|
25380
25738
|
if (scriptAssets.length > 0) {
|
|
25381
25739
|
result = compileJSX(content, component.absPath, {
|
|
@@ -25461,7 +25819,7 @@ function barefoot(options) {
|
|
|
25461
25819
|
const found = await discoverComponents(guessedEntries, (absPath) => readFile2(absPath, "utf8"));
|
|
25462
25820
|
const input = {};
|
|
25463
25821
|
for (const c of found) {
|
|
25464
|
-
if (!c.
|
|
25822
|
+
if (!c.needsClientEntry)
|
|
25465
25823
|
continue;
|
|
25466
25824
|
input[safeRollupEntryName(guessedRoot, c.absPath, dirs)] = c.absPath;
|
|
25467
25825
|
}
|