@barefootjs/jsx 0.39.3 → 0.39.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/boolean-result.d.ts +32 -0
- package/dist/adapters/boolean-result.d.ts.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +335 -49
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-composite-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +5 -0
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/event-delegation.d.ts +7 -0
- package/dist/ir-to-client-js/control-flow/plan/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/composite-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/loop.d.ts +14 -0
- package/dist/ir-to-client-js/control-flow/stringify/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/rest-attr-applications.d.ts +3 -1
- package/dist/ir-to-client-js/phases/rest-attr-applications.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts +6 -0
- package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +12 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +21 -0
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/profiler.d.ts +9 -1
- package/dist/profiler.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/boolean-result.test.ts +27 -0
- package/src/__tests__/csr-template-loop-shadow.test.ts +83 -0
- package/src/__tests__/profile-turn-markers.test.ts +22 -0
- package/src/__tests__/profiler.test.ts +10 -9
- package/src/__tests__/ssr-portal-ref-callback.test.ts +88 -13
- package/src/adapters/boolean-result.ts +89 -0
- package/src/errors.ts +11 -0
- package/src/index.ts +3 -0
- package/src/ir-to-client-js/collect-elements.ts +11 -3
- package/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/build-event-delegation.ts +13 -0
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +7 -2
- package/src/ir-to-client-js/control-flow/plan/event-delegation.ts +7 -0
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/loop.ts +2 -0
- package/src/ir-to-client-js/control-flow/shared.ts +2 -0
- package/src/ir-to-client-js/control-flow/stringify/branch-loop.ts +6 -3
- package/src/ir-to-client-js/control-flow/stringify/composite-loop.ts +7 -4
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +21 -6
- package/src/ir-to-client-js/control-flow/stringify/insert.ts +6 -1
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +55 -8
- package/src/ir-to-client-js/html-template.ts +59 -8
- package/src/ir-to-client-js/imports.ts +3 -1
- package/src/ir-to-client-js/phases/rest-attr-applications.ts +8 -2
- package/src/ir-to-client-js/reactivity.ts +1 -0
- package/src/ir-to-client-js/safe-html.ts +10 -0
- package/src/ir-to-client-js/types.ts +12 -0
- package/src/jsx-to-ir.ts +138 -32
- package/src/nullable-signal-attr.ts +46 -0
- package/src/profiler.ts +79 -10
package/dist/index.js
CHANGED
|
@@ -2600,6 +2600,10 @@ var RUNTIME_IMPORT_CANDIDATES = [
|
|
|
2600
2600
|
"markupOrEmpty",
|
|
2601
2601
|
"qsa",
|
|
2602
2602
|
"qsaItem",
|
|
2603
|
+
"adoptRowPortal",
|
|
2604
|
+
"claimRowPortals",
|
|
2605
|
+
"relayRowPortalEvents",
|
|
2606
|
+
"isRowPortalOf",
|
|
2603
2607
|
"qsaChildScope",
|
|
2604
2608
|
"qsaChildScopes",
|
|
2605
2609
|
"upsertChildItem",
|
|
@@ -4293,6 +4297,11 @@ function conditionalMarkup(condition, whenTrue, whenFalse) {
|
|
|
4293
4297
|
function mappedRowsMarkup(arrayExpr, method, params, body) {
|
|
4294
4298
|
return safeHtml(`${arrayExpr}.${method}(${params} => ${body}).join('')`);
|
|
4295
4299
|
}
|
|
4300
|
+
function withOuterBindings(params, values, markup) {
|
|
4301
|
+
if (params.length === 0)
|
|
4302
|
+
return markup;
|
|
4303
|
+
return safeHtml(`((${params.join(", ")}) => ${markup})(${values.join(", ")})`);
|
|
4304
|
+
}
|
|
4296
4305
|
var EMPTY_MARKUP = safeHtml("''");
|
|
4297
4306
|
function isChildrenPassthroughExpr(expr) {
|
|
4298
4307
|
return isChildrenPassthrough(parseExpression(expr));
|
|
@@ -5481,6 +5490,23 @@ function mergeCsrNullUnsafe(ctx, unsafeLocalNames) {
|
|
|
5481
5490
|
}
|
|
5482
5491
|
return merged ?? unsafeLocalNames;
|
|
5483
5492
|
}
|
|
5493
|
+
function closeOverLoopBindings(env, boundHere) {
|
|
5494
|
+
const substitutions = new Map;
|
|
5495
|
+
const hoisted = [];
|
|
5496
|
+
for (const [name, sub] of env.substitutions) {
|
|
5497
|
+
if (boundHere.has(name))
|
|
5498
|
+
continue;
|
|
5499
|
+
if (!setIntersects(extractFreeIdentifiersFromText(sub.replacement), boundHere)) {
|
|
5500
|
+
substitutions.set(name, sub);
|
|
5501
|
+
continue;
|
|
5502
|
+
}
|
|
5503
|
+
const closed = csrSubstitute(sub.replacement, env);
|
|
5504
|
+
if (setIntersects(closed.freeIdentifiers, boundHere))
|
|
5505
|
+
hoisted.push(name);
|
|
5506
|
+
substitutions.set(name, { ...sub, replacement: closed.rewritten, freeIdentifiers: closed.freeIdentifiers });
|
|
5507
|
+
}
|
|
5508
|
+
return { substitutions, hoisted };
|
|
5509
|
+
}
|
|
5484
5510
|
function buildCsrEnvForCtx(ctx, inlinableConstants, propsObjectName) {
|
|
5485
5511
|
const base = buildSignalMemoEnv(ctx.signals, ctx.memos, propsObjectName ?? null, ctx.localConstants);
|
|
5486
5512
|
const csrEnv = { substitutions: new Map(base.substitutions), propsObjectName: base.propsObjectName };
|
|
@@ -5727,10 +5753,20 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
5727
5753
|
case "loop": {
|
|
5728
5754
|
const childScope = (opts.scope ?? BindingScope.EMPTY).enterLoopRow(node);
|
|
5729
5755
|
const boundHere = childScope.boundNames();
|
|
5730
|
-
const
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5756
|
+
const { substitutions: childSubstitutions, hoisted } = closeOverLoopBindings(env, boundHere);
|
|
5757
|
+
const hoistParams = [];
|
|
5758
|
+
const hoistValues = [];
|
|
5759
|
+
for (const name of hoisted) {
|
|
5760
|
+
const sub = env.substitutions.get(name);
|
|
5761
|
+
const value = transformExpr(sub.kind === "call" ? `${name}()` : name);
|
|
5762
|
+
if (value === UNSAFE_TEMPLATE_EXPR)
|
|
5763
|
+
continue;
|
|
5764
|
+
const param = `__bf_outer_${name}`;
|
|
5765
|
+
hoistParams.push(param);
|
|
5766
|
+
hoistValues.push(value);
|
|
5767
|
+
childSubstitutions.set(name, { kind: sub.kind, replacement: param, freeIdentifiers: new Set([param]) });
|
|
5768
|
+
}
|
|
5769
|
+
const childEnv = { ...env, substitutions: childSubstitutions };
|
|
5734
5770
|
const recurseInLoopBody = (n) => generateCsrTemplateWithOpts(n, {
|
|
5735
5771
|
...opts,
|
|
5736
5772
|
loopDepth: loopDepth + 1,
|
|
@@ -5755,12 +5791,12 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
5755
5791
|
transformJs: (t) => rewritePropsObjectRef(t, propsObjectName ?? null, restPropsName ?? null, { enclosingScope: childScope }),
|
|
5756
5792
|
renderLeaf: (ir) => recurseInLoopBody(leafKeyAsDataKeyAttr(ir))
|
|
5757
5793
|
});
|
|
5758
|
-
mapExpr = interp(mappedRowsMarkup(iterArrayExpr, "flatMap", node.flatMapCallback.params, body));
|
|
5794
|
+
mapExpr = interp(withOuterBindings(hoistParams, hoistValues, mappedRowsMarkup(iterArrayExpr, "flatMap", node.flatMapCallback.params, body)));
|
|
5759
5795
|
} else if (node.preamble) {
|
|
5760
5796
|
const preamble = renderPreamble(node.preamble, { textVariant: "template", transformJs: (t) => rewritePropsObjectRef(t, propsObjectName ?? null, restPropsName ?? null, { enclosingScope: childScope }), renderLeaf: (ir) => recurseInLoopBody(ir) });
|
|
5761
|
-
mapExpr = interp(mappedRowsMarkup(iterArrayExpr, iterMethod, callbackParam, `{ ${preamble} return \`${childTemplate}\` }`));
|
|
5797
|
+
mapExpr = interp(withOuterBindings(hoistParams, hoistValues, mappedRowsMarkup(iterArrayExpr, iterMethod, callbackParam, `{ ${preamble} return \`${childTemplate}\` }`)));
|
|
5762
5798
|
} else {
|
|
5763
|
-
mapExpr = interp(mappedRowsMarkup(iterArrayExpr, iterMethod, callbackParam, `\`${childTemplate}\``));
|
|
5799
|
+
mapExpr = interp(withOuterBindings(hoistParams, hoistValues, mappedRowsMarkup(iterArrayExpr, iterMethod, callbackParam, `\`${childTemplate}\``)));
|
|
5764
5800
|
}
|
|
5765
5801
|
return `<!--${loopStartMarker(node.markerId)}-->${mapExpr}<!--${loopEndMarker(node.markerId)}-->`;
|
|
5766
5802
|
}
|
|
@@ -6909,6 +6945,7 @@ var ErrorCodes = {
|
|
|
6909
6945
|
STAGE_INIT_LOCAL_IN_TEMPLATE: "BF061",
|
|
6910
6946
|
STAGE_AWAIT_IN_TEMPLATE: "BF062",
|
|
6911
6947
|
REF_ATTR_ABSENT_AT_SSR: "BF063",
|
|
6948
|
+
ROW_PORTAL_UNPAIRABLE: "BF064",
|
|
6912
6949
|
INLINE_JSX_CALLBACK_CAPTURE: "BF080",
|
|
6913
6950
|
UNRECOGNIZED_REACTIVE_FACTORY: "BF110",
|
|
6914
6951
|
REACTIVE_FACTORY_RENAME_UNSUPPORTED: "BF111",
|
|
@@ -6948,6 +6985,7 @@ var errorMessages = {
|
|
|
6948
6985
|
[ErrorCodes.STAGE_INIT_LOCAL_IN_TEMPLATE]: "Init-scope local referenced from template scope. The template lambda runs at module scope (via render() / renderChild()) and cannot reach init-body locals. Wrap the JSX expression in /* @client */, or lift the value to a prop or module-scope const.",
|
|
6949
6986
|
[ErrorCodes.STAGE_AWAIT_IN_TEMPLATE]: "AwaitExpression in template scope. The generated template and init functions are synchronous — a bare `await` produces a SyntaxError at parse time. Move the await into the component body (before the return) or into an onMount/effect callback, and pass the resolved value to JSX.",
|
|
6950
6987
|
[ErrorCodes.REF_ATTR_ABSENT_AT_SSR]: "A ref callback writes an attribute on mount that the element's JSX never renders. A ref callback never runs at SSR, so the server HTML lacks the attribute and hydration adds it — the DOM visibly changes at the hydrate boundary.",
|
|
6988
|
+
[ErrorCodes.ROW_PORTAL_UNPAIRABLE]: "A ref callback portals an element out of a .map() row that hydration cannot pair with the element (the row root itself, a nested or unkeyed loop, an element inside a reactive conditional in the row, or an element inside a child component's children), so its event handlers would stop running after hydration.",
|
|
6951
6989
|
[ErrorCodes.INLINE_JSX_CALLBACK_CAPTURE]: "Inline JSX-returning arrow function captures a non-module identifier. 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.",
|
|
6952
6990
|
[ErrorCodes.UNRECOGNIZED_REACTIVE_FACTORY]: "Tuple destructuring of a non-reactive factory call. The compiler only recognizes createSignal / createMemo calls and same-file helpers that wrap them with a single `return [a, b]` exit.",
|
|
6953
6991
|
[ErrorCodes.REACTIVE_FACTORY_RENAME_UNSUPPORTED]: "Reactive factory object return/destructure must use shorthand properties only. " + "Property renames (`{ lists: myLists }`), defaults, and rest elements are not " + "supported — destructure with the factory's own property names.",
|
|
@@ -14542,6 +14580,88 @@ function applyLoopKeyAttr(node, name, value) {
|
|
|
14542
14580
|
applyLoopKeyAttr(first, name, value);
|
|
14543
14581
|
}
|
|
14544
14582
|
}
|
|
14583
|
+
function applyRowPortalKeyAttrs(children, key, depth, ctx) {
|
|
14584
|
+
const refuse = (el, reason) => {
|
|
14585
|
+
ctx.analyzer.errors.push(createError(ErrorCodes.ROW_PORTAL_UNPAIRABLE, el.loc, {
|
|
14586
|
+
message: `A ref callback portals <${el.tag}> out of a .map() row, but ${reason}, so hydration cannot pair the ` + "portaled element with its row and its event handlers would stop running after hydration.",
|
|
14587
|
+
suggestion: {
|
|
14588
|
+
message: "Portal an element inside the root of a keyed top-level .map() row (`key={…}` on the row root), " + "outside reactive conditionals and child components' children, or move the portal outside the loop.",
|
|
14589
|
+
escape: [{ kind: "rewrite" }]
|
|
14590
|
+
}
|
|
14591
|
+
}));
|
|
14592
|
+
};
|
|
14593
|
+
const visit3 = (node, blocked) => {
|
|
14594
|
+
switch (node.type) {
|
|
14595
|
+
case "element":
|
|
14596
|
+
if (node.ssrPortalOwnerScope) {
|
|
14597
|
+
if (node.keyAttr)
|
|
14598
|
+
refuse(node, "it is the root element of the row");
|
|
14599
|
+
else if (blocked)
|
|
14600
|
+
refuse(node, blocked);
|
|
14601
|
+
else if (key === null)
|
|
14602
|
+
refuse(node, "the loop has no `key`");
|
|
14603
|
+
else if (depth > 0)
|
|
14604
|
+
refuse(node, "the loop is nested inside another loop");
|
|
14605
|
+
else {
|
|
14606
|
+
node.keyAttr = { name: keyAttrName2(depth), value: key };
|
|
14607
|
+
if (!node.attrs.some((a) => a.name === "key")) {
|
|
14608
|
+
node.attrs.push(rowKeyAttribute(children) ?? { name: "key", value: { kind: "expression", expr: key }, loc: node.loc });
|
|
14609
|
+
}
|
|
14610
|
+
}
|
|
14611
|
+
}
|
|
14612
|
+
for (const c of node.children)
|
|
14613
|
+
visit3(c, blocked);
|
|
14614
|
+
return;
|
|
14615
|
+
case "fragment":
|
|
14616
|
+
for (const c of node.children)
|
|
14617
|
+
visit3(c, blocked);
|
|
14618
|
+
return;
|
|
14619
|
+
case "conditional": {
|
|
14620
|
+
const inner = blocked ?? (node.slotId ? "it is rendered inside a reactive conditional in the row" : null);
|
|
14621
|
+
visit3(node.whenTrue, inner);
|
|
14622
|
+
visit3(node.whenFalse, inner);
|
|
14623
|
+
return;
|
|
14624
|
+
}
|
|
14625
|
+
case "if-statement":
|
|
14626
|
+
visit3(node.consequent, blocked);
|
|
14627
|
+
if (node.alternate)
|
|
14628
|
+
visit3(node.alternate, blocked);
|
|
14629
|
+
return;
|
|
14630
|
+
case "component":
|
|
14631
|
+
case "provider":
|
|
14632
|
+
for (const c of node.children)
|
|
14633
|
+
visit3(c, blocked ?? "it is rendered inside another component's children");
|
|
14634
|
+
return;
|
|
14635
|
+
case "async":
|
|
14636
|
+
visit3(node.fallback, blocked ?? "it is rendered inside another component's children");
|
|
14637
|
+
for (const c of node.children)
|
|
14638
|
+
visit3(c, blocked ?? "it is rendered inside another component's children");
|
|
14639
|
+
return;
|
|
14640
|
+
default:
|
|
14641
|
+
return;
|
|
14642
|
+
}
|
|
14643
|
+
};
|
|
14644
|
+
for (const c of children)
|
|
14645
|
+
visit3(c, null);
|
|
14646
|
+
}
|
|
14647
|
+
function rowKeyAttribute(children) {
|
|
14648
|
+
const find = (node) => {
|
|
14649
|
+
switch (node.type) {
|
|
14650
|
+
case "element":
|
|
14651
|
+
return node.attrs.find((a) => a.name === "key") ?? null;
|
|
14652
|
+
case "conditional":
|
|
14653
|
+
return find(node.whenTrue);
|
|
14654
|
+
case "fragment": {
|
|
14655
|
+
const first2 = node.children.find((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
|
|
14656
|
+
return first2 ? find(first2) : null;
|
|
14657
|
+
}
|
|
14658
|
+
default:
|
|
14659
|
+
return null;
|
|
14660
|
+
}
|
|
14661
|
+
};
|
|
14662
|
+
const first = children.find((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
|
|
14663
|
+
return first ? find(first) : null;
|
|
14664
|
+
}
|
|
14545
14665
|
function loopBodyItemConditional(children) {
|
|
14546
14666
|
const real = children.filter((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
|
|
14547
14667
|
if (real.length !== 1)
|
|
@@ -14935,6 +15055,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
14935
15055
|
applyLoopKeyAttr(children[0], resolvedKeyAttrName2, key);
|
|
14936
15056
|
}
|
|
14937
15057
|
}
|
|
15058
|
+
applyRowPortalKeyAttrs(children, key, depth, ctx);
|
|
14938
15059
|
const declaredNameSet = preamble && preamble.declaredNames.length > 0 ? new Set(preamble.declaredNames) : undefined;
|
|
14939
15060
|
if (key && declaredNameSet) {
|
|
14940
15061
|
const keyRefs = extractFreeIdentifiersFromText(key);
|
|
@@ -15826,12 +15947,12 @@ function datasetKeyToAttrName(key) {
|
|
|
15826
15947
|
function resolveRefCallback(refExpr) {
|
|
15827
15948
|
const expr = unwrapTransparentTsWrappers(refExpr);
|
|
15828
15949
|
if (ts19.isArrowFunction(expr) || ts19.isFunctionExpression(expr)) {
|
|
15829
|
-
return { param: firstSimpleParamName(expr), body: expr.body, named: false
|
|
15950
|
+
return { param: firstSimpleParamName(expr), body: expr.body, named: false };
|
|
15830
15951
|
}
|
|
15831
15952
|
if (!ts19.isIdentifier(expr))
|
|
15832
15953
|
return;
|
|
15833
|
-
const
|
|
15834
|
-
return
|
|
15954
|
+
const callback = findNamedCallback(expr);
|
|
15955
|
+
return callback && { ...callback, named: true };
|
|
15835
15956
|
}
|
|
15836
15957
|
function isFunctionLike(node) {
|
|
15837
15958
|
return ts19.isArrowFunction(node) || ts19.isFunctionExpression(node) || ts19.isFunctionDeclaration(node);
|
|
@@ -15846,15 +15967,13 @@ function findEnclosingFunctionLike(node) {
|
|
|
15846
15967
|
return;
|
|
15847
15968
|
}
|
|
15848
15969
|
function findNamedCallback(ident) {
|
|
15849
|
-
|
|
15850
|
-
for (let fn = innermost;fn; fn = findEnclosingFunctionLike(fn)) {
|
|
15970
|
+
for (let fn = findEnclosingFunctionLike(ident);fn; fn = findEnclosingFunctionLike(fn)) {
|
|
15851
15971
|
if (fn.parameters.some((p) => bindingDeclares(p.name, ident.text)))
|
|
15852
15972
|
return;
|
|
15853
15973
|
const decl = fn.body && findScopeDeclaration(ident.text, fn.body);
|
|
15854
15974
|
if (!decl)
|
|
15855
15975
|
continue;
|
|
15856
|
-
|
|
15857
|
-
return callback && { callback, innermostScope: fn === innermost };
|
|
15976
|
+
return localCallbackOf(decl);
|
|
15858
15977
|
}
|
|
15859
15978
|
return;
|
|
15860
15979
|
}
|
|
@@ -15890,7 +16009,7 @@ function bindingDeclares(binding, name) {
|
|
|
15890
16009
|
return names.has(name);
|
|
15891
16010
|
}
|
|
15892
16011
|
function isSsrPortalRefCallback(callback) {
|
|
15893
|
-
return !!callback?.named &&
|
|
16012
|
+
return !!callback?.named && !!callback.param && containsSsrPortalPlacementCall(callback.body, callback.param);
|
|
15894
16013
|
}
|
|
15895
16014
|
function firstSimpleParamName(fn) {
|
|
15896
16015
|
const first = fn.parameters[0];
|
|
@@ -17265,7 +17384,8 @@ function collectLoopChildRefs(node) {
|
|
|
17265
17384
|
if (el.slotId && el.ref) {
|
|
17266
17385
|
refs.push({
|
|
17267
17386
|
childSlotId: el.slotId,
|
|
17268
|
-
callback: el.ref
|
|
17387
|
+
callback: el.ref,
|
|
17388
|
+
...el.ssrPortalOwnerScope && { ssrPortalOwner: true }
|
|
17269
17389
|
});
|
|
17270
17390
|
}
|
|
17271
17391
|
}, true);
|
|
@@ -18210,9 +18330,12 @@ function collectFromElement(element, ctx, insideConditional = false) {
|
|
|
18210
18330
|
}
|
|
18211
18331
|
function collectBranchReactiveAttrs(node, ctx) {
|
|
18212
18332
|
const attrs = [];
|
|
18213
|
-
walkIR(node,
|
|
18333
|
+
walkIR(node, [], {
|
|
18214
18334
|
...stopAt("conditional", "ifStatement", "loop"),
|
|
18215
|
-
|
|
18335
|
+
component: ({ node: c, scope, descend }) => {
|
|
18336
|
+
descend(c.slotId ? [...scope, c.slotId] : scope);
|
|
18337
|
+
},
|
|
18338
|
+
element: ({ node: el, scope, descend }) => {
|
|
18216
18339
|
if (!el.slotId) {
|
|
18217
18340
|
descend();
|
|
18218
18341
|
return;
|
|
@@ -18230,6 +18353,7 @@ function collectBranchReactiveAttrs(node, ctx) {
|
|
|
18230
18353
|
continue;
|
|
18231
18354
|
attrs.push({
|
|
18232
18355
|
slotId: el.slotId,
|
|
18356
|
+
...el.slotId.startsWith("^") && { receiverSlotIds: scope },
|
|
18233
18357
|
attrName: attr.name,
|
|
18234
18358
|
expression: expanded.expr,
|
|
18235
18359
|
...pickAttrMetaFromIR(attr),
|
|
@@ -20358,7 +20482,8 @@ function buildChildRefBindings(refs, loopParam, loopParamBindings, loopIndex) {
|
|
|
20358
20482
|
return [];
|
|
20359
20483
|
return refs.map((r) => ({
|
|
20360
20484
|
childSlotId: r.childSlotId,
|
|
20361
|
-
callback: wrapLoopParamAsAccessor(r.callback, loopParam, loopParamBindings, loopIndex)
|
|
20485
|
+
callback: wrapLoopParamAsAccessor(r.callback, loopParam, loopParamBindings, loopIndex),
|
|
20486
|
+
...r.ssrPortalOwner && { ssrPortalOwner: true }
|
|
20362
20487
|
}));
|
|
20363
20488
|
}
|
|
20364
20489
|
function buildStaticChildRefBindings(refs) {
|
|
@@ -20366,7 +20491,8 @@ function buildStaticChildRefBindings(refs) {
|
|
|
20366
20491
|
return [];
|
|
20367
20492
|
return refs.map((r) => ({
|
|
20368
20493
|
childSlotId: r.childSlotId,
|
|
20369
|
-
callback: r.callback
|
|
20494
|
+
callback: r.callback,
|
|
20495
|
+
...r.ssrPortalOwner && { ssrPortalOwner: true }
|
|
20370
20496
|
}));
|
|
20371
20497
|
}
|
|
20372
20498
|
function exprRefsLoopBinding(freeIds, loop) {
|
|
@@ -21601,7 +21727,7 @@ function wrapAttrValueExpression2(value, wrap) {
|
|
|
21601
21727
|
}
|
|
21602
21728
|
}
|
|
21603
21729
|
function buildInnerLoopsPlan(args) {
|
|
21604
|
-
const { levels, parentElVar, outerLoopParam, outerLoopParamBindings, outerLoopIndex } = args;
|
|
21730
|
+
const { levels, parentElVar, outerLoopParam, outerLoopParamBindings, outerLoopIndex, rowHasPortal } = args;
|
|
21605
21731
|
const wrapOuter = outerLoopParam ? (expr) => wrapLoopParamAsAccessor(expr, outerLoopParam, outerLoopParamBindings, outerLoopIndex) : (expr) => expr;
|
|
21606
21732
|
const plan = [];
|
|
21607
21733
|
let i = 0;
|
|
@@ -21623,7 +21749,7 @@ function buildInnerLoopsPlan(args) {
|
|
|
21623
21749
|
j++;
|
|
21624
21750
|
}
|
|
21625
21751
|
const uidSuffix = `${inner.depth}_${i}`;
|
|
21626
|
-
const containerExpr = inner.containerSlotId ?
|
|
21752
|
+
const containerExpr = inner.containerSlotId ? `${rowHasPortal ? "qsaItem" : "qsa"}(${parentElVar}, '[bf="${inner.containerSlotId}"]')` : parentElVar;
|
|
21627
21753
|
const emit = buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, outerLoopParamBindings, outerLoopIndex);
|
|
21628
21754
|
const arrayExpr = wrapOuter(inner.array);
|
|
21629
21755
|
const childLevelsPlan = childLevels.length > 0 ? buildInnerLoopsPlan({
|
|
@@ -21771,7 +21897,8 @@ function buildTopLevelCompositePlan(elem, profileComponentName) {
|
|
|
21771
21897
|
parentElVar: "__el",
|
|
21772
21898
|
outerLoopParam: elem.param,
|
|
21773
21899
|
outerLoopParamBindings: elem.paramBindings,
|
|
21774
|
-
outerLoopIndex: elem.index
|
|
21900
|
+
outerLoopIndex: elem.index,
|
|
21901
|
+
rowHasPortal: elem.bindings.refs.some((r) => r.ssrPortalOwner)
|
|
21775
21902
|
}),
|
|
21776
21903
|
loopParam: elem.param,
|
|
21777
21904
|
loopParamBindings: elem.paramBindings,
|
|
@@ -21824,7 +21951,8 @@ function buildBranchCompositePlan(loop, cv, profileComponentName) {
|
|
|
21824
21951
|
parentElVar: "__el",
|
|
21825
21952
|
outerLoopParam: loop.param,
|
|
21826
21953
|
outerLoopParamBindings: loop.paramBindings,
|
|
21827
|
-
outerLoopIndex: loop.index
|
|
21954
|
+
outerLoopIndex: loop.index,
|
|
21955
|
+
rowHasPortal: loop.bindings.refs.some((r) => r.ssrPortalOwner)
|
|
21828
21956
|
}),
|
|
21829
21957
|
loopParam: loop.param,
|
|
21830
21958
|
loopParamBindings: loop.paramBindings,
|
|
@@ -22159,7 +22287,8 @@ function emitRestAttrApplications(lines, ctx) {
|
|
|
22159
22287
|
for (const elem of ctx.restAttrElements) {
|
|
22160
22288
|
const v = varSlotId(elem.slotId);
|
|
22161
22289
|
const excludeKeys = JSON.stringify(elem.excludeKeys);
|
|
22162
|
-
|
|
22290
|
+
const turnSite = ctx.profile ? `, ${JSON.stringify(`${ctx.componentName}#handler:${elem.slotId}`)}` : "";
|
|
22291
|
+
lines.push(` if (_${v}) applyRestAttrs(_${v}, ${elem.source}, ${excludeKeys}${turnSite})`);
|
|
22163
22292
|
}
|
|
22164
22293
|
lines.push("");
|
|
22165
22294
|
}
|
|
@@ -23229,14 +23358,16 @@ function stringifyCompositeLoop(lines, plan) {
|
|
|
23229
23358
|
singleRootLayout: "multiline",
|
|
23230
23359
|
mountRow: true
|
|
23231
23360
|
});
|
|
23232
|
-
|
|
23361
|
+
emitRowPortalClaim(lines, childRefs, { indent: bodyIndent, containerVar });
|
|
23362
|
+
const itemLookup = bodyIsMultiRoot || rowPortalSlotIds(childRefs).length > 0;
|
|
23363
|
+
emitComponentAndEventSetup(lines, bodyIndent, "__el", compsArr, eventsArr, loopParam, loopParamBindings, itemLookup, loopIndex);
|
|
23233
23364
|
if (innerLoops.length > 0) {
|
|
23234
23365
|
stringifyInnerLoops(lines, innerLoops, bodyIndent, pc);
|
|
23235
23366
|
}
|
|
23236
23367
|
if (reactiveEffects) {
|
|
23237
|
-
stringifyReactiveEffects(lines, reactiveEffects, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot });
|
|
23368
|
+
stringifyReactiveEffects(lines, reactiveEffects, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot: itemLookup });
|
|
23238
23369
|
}
|
|
23239
|
-
emitLoopChildRefs(lines, childRefs, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot });
|
|
23370
|
+
emitLoopChildRefs(lines, childRefs, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot: itemLookup, containerVar });
|
|
23240
23371
|
lines.push(`${bodyIndent}return __el`);
|
|
23241
23372
|
const loopBfId = profileLoopId ? `, ${JSON.stringify(profileLoopId)}` : "";
|
|
23242
23373
|
if (branchClearChildren) {
|
|
@@ -23467,16 +23598,30 @@ function seedDiffersExpr(target, a) {
|
|
|
23467
23598
|
function emitLoopChildRefs(lines, refs, opts) {
|
|
23468
23599
|
if (refs.length === 0)
|
|
23469
23600
|
return;
|
|
23470
|
-
const { indent, elVar, bodyIsMultiRoot, elementIndexBySlot } = opts;
|
|
23471
|
-
const lookup = bodyIsMultiRoot ? "qsaItem" : "qsa";
|
|
23601
|
+
const { indent, elVar, bodyIsMultiRoot, elementIndexBySlot, containerVar } = opts;
|
|
23472
23602
|
for (const ref of refs) {
|
|
23603
|
+
const lookup = bodyIsMultiRoot || ref.ssrPortalOwner ? "qsaItem" : "qsa";
|
|
23473
23604
|
const varName = `__rf_${varSlotId(ref.childSlotId)}`;
|
|
23474
23605
|
const pIdx = elementIndexBySlot?.get(ref.childSlotId);
|
|
23475
23606
|
const lookupExpr = pIdx !== undefined ? `__p ? __p[${pIdx}] : ${lookup}(${elVar}, '[bf="${ref.childSlotId}"]')` : `${lookup}(${elVar}, '[bf="${ref.childSlotId}"]')`;
|
|
23476
23607
|
lines.push(`${indent}{ const ${varName} = ${lookupExpr}`);
|
|
23477
|
-
|
|
23608
|
+
if (ref.ssrPortalOwner && containerVar) {
|
|
23609
|
+
lines.push(`${indent}if (${varName}) { ${emitRefCall(ref.callback, varName, true)}; adoptRowPortal(${elVar}, ${varName}, ${containerVar}) } }`);
|
|
23610
|
+
} else {
|
|
23611
|
+
lines.push(`${indent}if (${varName}) ${emitRefCall(ref.callback, varName)} }`);
|
|
23612
|
+
}
|
|
23478
23613
|
}
|
|
23479
23614
|
}
|
|
23615
|
+
function rowPortalSlotIds(refs) {
|
|
23616
|
+
return refs.filter((r) => r.ssrPortalOwner).map((r) => r.childSlotId);
|
|
23617
|
+
}
|
|
23618
|
+
function emitRowPortalClaim(lines, refs, opts) {
|
|
23619
|
+
const slots = rowPortalSlotIds(refs);
|
|
23620
|
+
if (slots.length === 0)
|
|
23621
|
+
return;
|
|
23622
|
+
const claim = `claimRowPortals(${opts.rowVar ?? "__existing"}, __scopeId, ${JSON.stringify(slots)}, ${opts.containerVar})`;
|
|
23623
|
+
lines.push(opts.rowVar ? `${opts.indent}${claim}` : `${opts.indent}if (__existing) ${claim}`);
|
|
23624
|
+
}
|
|
23480
23625
|
function stringifyLoop(lines, plan) {
|
|
23481
23626
|
switch (plan.kind) {
|
|
23482
23627
|
case "static":
|
|
@@ -23586,6 +23731,8 @@ function stringifyPlainLoop(lines, plan, topIndent = " ") {
|
|
|
23586
23731
|
singleRootLayout: "inline"
|
|
23587
23732
|
});
|
|
23588
23733
|
}
|
|
23734
|
+
emitRowPortalClaim(lines, childRefs, { indent: bodyIndent, containerVar });
|
|
23735
|
+
const itemLookup = bodyIsMultiRoot || rowPortalSlotIds(childRefs).length > 0;
|
|
23589
23736
|
let pathPlan = null;
|
|
23590
23737
|
if (hoistedTpl && plan.skeletonPaths) {
|
|
23591
23738
|
const elementSlotIds = [
|
|
@@ -23612,14 +23759,14 @@ function stringifyPlainLoop(lines, plan, topIndent = " ") {
|
|
|
23612
23759
|
stringifyReactiveEffects(lines, reactiveEffects, {
|
|
23613
23760
|
indent: bodyIndent,
|
|
23614
23761
|
elVar: "__el",
|
|
23615
|
-
bodyIsMultiRoot,
|
|
23762
|
+
bodyIsMultiRoot: itemLookup,
|
|
23616
23763
|
elementIndexBySlot: pathPlan?.elementIndexBySlot,
|
|
23617
23764
|
textClaimPathExprs,
|
|
23618
23765
|
preambleRegions,
|
|
23619
23766
|
mapPreambleWrapped
|
|
23620
23767
|
});
|
|
23621
23768
|
}
|
|
23622
|
-
emitLoopChildRefs(lines, childRefs, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot, elementIndexBySlot: pathPlan?.elementIndexBySlot });
|
|
23769
|
+
emitLoopChildRefs(lines, childRefs, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot: itemLookup, elementIndexBySlot: pathPlan?.elementIndexBySlot, containerVar });
|
|
23623
23770
|
lines.push(`${bodyIndent}return __el`);
|
|
23624
23771
|
lines.push(`${topIndent}}, '${markerId}'${loopBfId})`);
|
|
23625
23772
|
}
|
|
@@ -23715,12 +23862,14 @@ function stringifyStaticLoop(lines, plan) {
|
|
|
23715
23862
|
lines.push(` }`);
|
|
23716
23863
|
}
|
|
23717
23864
|
lines.push(` if (__iterEl) {`);
|
|
23865
|
+
emitRowPortalClaim(lines, childRefs, { indent: " ", containerVar, rowVar: "__iterEl" });
|
|
23866
|
+
const rowHasPortal = rowPortalSlotIds(childRefs).length > 0;
|
|
23718
23867
|
if (attrsBySlot.length > 0)
|
|
23719
23868
|
lines.push(` ${DEDUP_STORE_DECL}`);
|
|
23720
23869
|
let ordinal = 0;
|
|
23721
23870
|
for (const [slotId, attrs] of attrsBySlot) {
|
|
23722
23871
|
const varName = `__t_${varSlotId(slotId)}`;
|
|
23723
|
-
lines.push(` const ${varName} = qsa(__iterEl, '[bf="${slotId}"]')`);
|
|
23872
|
+
lines.push(` const ${varName} = ${rowHasPortal ? "qsaItem" : "qsa"}(__iterEl, '[bf="${slotId}"]')`);
|
|
23724
23873
|
lines.push(` if (${varName}) {`);
|
|
23725
23874
|
for (const attr of attrs) {
|
|
23726
23875
|
lines.push(` createEffect(() => {`);
|
|
@@ -23739,7 +23888,7 @@ function stringifyStaticLoop(lines, plan) {
|
|
|
23739
23888
|
lines.push(` createEffect(() => { ${writer}('${text.slotId}', String(${text.expression})) }${profileBindingId(pc, text.slotId)})`);
|
|
23740
23889
|
}
|
|
23741
23890
|
}
|
|
23742
|
-
emitLoopChildRefs(lines, childRefs, { indent: " ", elVar: "__iterEl", bodyIsMultiRoot:
|
|
23891
|
+
emitLoopChildRefs(lines, childRefs, { indent: " ", elVar: "__iterEl", bodyIsMultiRoot: rowHasPortal, containerVar });
|
|
23743
23892
|
lines.push(` }`);
|
|
23744
23893
|
lines.push(` })`);
|
|
23745
23894
|
lines.push(` }`);
|
|
@@ -23929,6 +24078,7 @@ function buildDynamicLoopDelegationPlan(elem, profileComponentName, ownHandlers)
|
|
|
23929
24078
|
events: elem.bindings.events,
|
|
23930
24079
|
profileComponentName,
|
|
23931
24080
|
ownHandlers,
|
|
24081
|
+
...hasRowPortalRef(elem) && { relayRowPortals: true },
|
|
23932
24082
|
itemLookup: buildKeyedOrIndexLookup({
|
|
23933
24083
|
array: buildChainedArrayExpr(elem),
|
|
23934
24084
|
param: elem.param,
|
|
@@ -23948,6 +24098,7 @@ function buildBranchLoopDelegationPlan(loop, cv, profileComponentName) {
|
|
|
23948
24098
|
containerVar: `__loop_${cv}`,
|
|
23949
24099
|
events: loop.bindings.events,
|
|
23950
24100
|
profileComponentName,
|
|
24101
|
+
...hasRowPortalRef(loop) && { relayRowPortals: true },
|
|
23951
24102
|
itemLookup: buildKeyedOrIndexLookup({
|
|
23952
24103
|
array: buildChainedArrayExpr(loop),
|
|
23953
24104
|
param: loop.param,
|
|
@@ -23962,6 +24113,9 @@ function buildBranchLoopDelegationPlan(loop, cv, profileComponentName) {
|
|
|
23962
24113
|
};
|
|
23963
24114
|
}
|
|
23964
24115
|
function buildStaticArrayDelegationPlan(elem, profileComponentName, ownHandlers) {
|
|
24116
|
+
if (hasRowPortalRef(elem) && elem.key !== null) {
|
|
24117
|
+
return buildDynamicLoopDelegationPlan(elem, profileComponentName, ownHandlers);
|
|
24118
|
+
}
|
|
23965
24119
|
return {
|
|
23966
24120
|
kind: "event-delegation",
|
|
23967
24121
|
containerVar: `_${varSlotId(elem.slotId)}`,
|
|
@@ -23981,6 +24135,9 @@ function buildStaticArrayDelegationPlan(elem, profileComponentName, ownHandlers)
|
|
|
23981
24135
|
}
|
|
23982
24136
|
};
|
|
23983
24137
|
}
|
|
24138
|
+
function hasRowPortalRef(loop) {
|
|
24139
|
+
return loop.bindings.refs.some((r) => r.ssrPortalOwner);
|
|
24140
|
+
}
|
|
23984
24141
|
function buildKeyedOrIndexLookup(args) {
|
|
23985
24142
|
const hasBindings = (args.paramBindings?.length ?? 0) > 0;
|
|
23986
24143
|
if (args.key !== null) {
|
|
@@ -24138,7 +24295,7 @@ function preambleLineForHandler(mapPreamble, declaredNames, handler) {
|
|
|
24138
24295
|
return declaredNames.some((name) => free.has(name)) ? mapPreamble : null;
|
|
24139
24296
|
}
|
|
24140
24297
|
function stringifyEventDelegation(lines, plan) {
|
|
24141
|
-
const { containerVar, events, itemLookup, profileComponentName, ownHandlers } = plan;
|
|
24298
|
+
const { containerVar, events, itemLookup, profileComponentName, ownHandlers, relayRowPortals } = plan;
|
|
24142
24299
|
const eventsByName = new Map;
|
|
24143
24300
|
for (const ev of events) {
|
|
24144
24301
|
if (!eventsByName.has(ev.eventName))
|
|
@@ -24151,16 +24308,19 @@ function stringifyEventDelegation(lines, plan) {
|
|
|
24151
24308
|
const domEventName = toDomEventName(eventName);
|
|
24152
24309
|
const ownHandler = ownHandlers?.get(domEventName);
|
|
24153
24310
|
const ownHandlerCall = ownHandler ? withTurn(`(${ownHandler.handler.trim()})(__bfEvt)`, profileComponentName, ownHandler.slotId, ownHandler.eventName) : null;
|
|
24154
|
-
|
|
24155
|
-
|
|
24311
|
+
const listenedName = useCapture ? eventName : domEventName;
|
|
24312
|
+
if (relayRowPortals) {
|
|
24313
|
+
lines.push(` if (${containerVar}) {`);
|
|
24314
|
+
lines.push(` const __bfDl = (__bfEvt) => {`);
|
|
24156
24315
|
} else {
|
|
24157
|
-
lines.push(` if (${containerVar}) ${containerVar}.addEventListener('${
|
|
24316
|
+
lines.push(` if (${containerVar}) ${containerVar}.addEventListener('${listenedName}', (__bfEvt) => {`);
|
|
24158
24317
|
}
|
|
24159
24318
|
lines.push(` const target = __bfEvt.target`);
|
|
24160
24319
|
for (const ev of evs) {
|
|
24161
24320
|
const childVar = varSlotId(ev.childSlotId);
|
|
24162
24321
|
lines.push(` const ${childVar}El = target.closest('[bf="${ev.childSlotId}"]')`);
|
|
24163
|
-
|
|
24322
|
+
const inContainer = relayRowPortals ? `(${containerVar}.contains(${childVar}El) || isRowPortalOf(${childVar}El, ${containerVar}))` : `${containerVar}.contains(${childVar}El)`;
|
|
24323
|
+
lines.push(` if (${childVar}El && ${inContainer}) {`);
|
|
24164
24324
|
const handlerCall = withTurn(`(${ev.handler.trim()})(__bfEvt)`, profileComponentName, ev.childSlotId, ev.eventName);
|
|
24165
24325
|
switch (itemLookup.kind) {
|
|
24166
24326
|
case "keyed":
|
|
@@ -24182,7 +24342,13 @@ function stringifyEventDelegation(lines, plan) {
|
|
|
24182
24342
|
if (ownHandlerCall) {
|
|
24183
24343
|
lines.push(` if (!__bfEvt.cancelBubble) { ${ownHandlerCall} }`);
|
|
24184
24344
|
}
|
|
24185
|
-
if (
|
|
24345
|
+
if (relayRowPortals) {
|
|
24346
|
+
const captureArg = useCapture ? ", true" : "";
|
|
24347
|
+
lines.push(` }`);
|
|
24348
|
+
lines.push(` ${containerVar}.addEventListener('${listenedName}', __bfDl${captureArg})`);
|
|
24349
|
+
lines.push(` relayRowPortalEvents(${containerVar}, '${listenedName}', __bfDl${captureArg})`);
|
|
24350
|
+
lines.push(` }`);
|
|
24351
|
+
} else if (useCapture) {
|
|
24186
24352
|
lines.push(` }, true)`);
|
|
24187
24353
|
} else {
|
|
24188
24354
|
lines.push(` })`);
|
|
@@ -24420,16 +24586,18 @@ function emitPlain(lines, plan) {
|
|
|
24420
24586
|
indent: " ",
|
|
24421
24587
|
singleRootLayout: "inline"
|
|
24422
24588
|
});
|
|
24589
|
+
emitRowPortalClaim(lines, childRefs, { indent: " ", containerVar });
|
|
24590
|
+
const itemLookup = bodyIsMultiRoot || rowPortalSlotIds(childRefs).length > 0;
|
|
24423
24591
|
if (reactiveEffects !== null || preambleRegions.length > 0) {
|
|
24424
24592
|
stringifyReactiveEffects(lines, reactiveEffects, {
|
|
24425
24593
|
indent: " ",
|
|
24426
24594
|
elVar: "__el",
|
|
24427
|
-
bodyIsMultiRoot,
|
|
24595
|
+
bodyIsMultiRoot: itemLookup,
|
|
24428
24596
|
preambleRegions,
|
|
24429
24597
|
mapPreambleWrapped
|
|
24430
24598
|
});
|
|
24431
24599
|
}
|
|
24432
|
-
emitLoopChildRefs(lines, childRefs, { indent: " ", elVar: "__el", bodyIsMultiRoot });
|
|
24600
|
+
emitLoopChildRefs(lines, childRefs, { indent: " ", elVar: "__el", bodyIsMultiRoot: itemLookup, containerVar });
|
|
24433
24601
|
lines.push(` return __el`);
|
|
24434
24602
|
lines.push(` }, '${markerId}'${loopBfId})`);
|
|
24435
24603
|
}
|
|
@@ -24504,7 +24672,9 @@ function emitArmBody(lines, body, mode, indent, profileComponentName) {
|
|
|
24504
24672
|
for (const [slotId, attrs] of attrsBySlot) {
|
|
24505
24673
|
const v = varSlotId(slotId);
|
|
24506
24674
|
const elVar = `__ra_${v}`;
|
|
24507
|
-
|
|
24675
|
+
const receivers = attrs[0].receiverSlotIds;
|
|
24676
|
+
const receiverArg = receivers && receivers.length > 0 ? `, ${JSON.stringify(receivers)}` : "";
|
|
24677
|
+
lines.push(`${indent}{ const ${elVar} = qsa(__branchScope, '[bf="${slotId}"]'${receiverArg})`);
|
|
24508
24678
|
lines.push(`${indent}${DEDUP_STORE_DECL}`);
|
|
24509
24679
|
lines.push(`${indent}if (${elVar}) {`);
|
|
24510
24680
|
let ordinal = 0;
|
|
@@ -28832,6 +29002,55 @@ function collectLoopBoundNames(ir) {
|
|
|
28832
29002
|
visit3(ir.root);
|
|
28833
29003
|
return names;
|
|
28834
29004
|
}
|
|
29005
|
+
// src/adapters/boolean-result.ts
|
|
29006
|
+
var COMPARISON_OPS = new Set([
|
|
29007
|
+
"<",
|
|
29008
|
+
">",
|
|
29009
|
+
"<=",
|
|
29010
|
+
">=",
|
|
29011
|
+
"==",
|
|
29012
|
+
"===",
|
|
29013
|
+
"!=",
|
|
29014
|
+
"!=="
|
|
29015
|
+
]);
|
|
29016
|
+
function isBooleanResultParsed(node) {
|
|
29017
|
+
switch (node.kind) {
|
|
29018
|
+
case "literal":
|
|
29019
|
+
return node.literalType === "boolean";
|
|
29020
|
+
case "binary":
|
|
29021
|
+
return COMPARISON_OPS.has(node.op);
|
|
29022
|
+
case "unary":
|
|
29023
|
+
return node.op === "!";
|
|
29024
|
+
case "logical":
|
|
29025
|
+
return isBooleanResultParsed(node.left) && isBooleanResultParsed(node.right);
|
|
29026
|
+
case "conditional":
|
|
29027
|
+
return isBooleanResultParsed(node.consequent) && isBooleanResultParsed(node.alternate);
|
|
29028
|
+
default:
|
|
29029
|
+
return false;
|
|
29030
|
+
}
|
|
29031
|
+
}
|
|
29032
|
+
function stringifyBooleanTernaryBranches(node) {
|
|
29033
|
+
if (node.kind !== "conditional" || isBooleanResultParsed(node))
|
|
29034
|
+
return node;
|
|
29035
|
+
return {
|
|
29036
|
+
...node,
|
|
29037
|
+
consequent: stringifyBooleanBranch(node.consequent),
|
|
29038
|
+
alternate: stringifyBooleanBranch(node.alternate)
|
|
29039
|
+
};
|
|
29040
|
+
}
|
|
29041
|
+
function stringifyBooleanBranch(branch) {
|
|
29042
|
+
if (!isBooleanResultParsed(branch))
|
|
29043
|
+
return stringifyBooleanTernaryBranches(branch);
|
|
29044
|
+
if (branch.kind === "literal") {
|
|
29045
|
+
return { kind: "literal", value: String(branch.value), literalType: "string" };
|
|
29046
|
+
}
|
|
29047
|
+
return {
|
|
29048
|
+
kind: "conditional",
|
|
29049
|
+
test: branch,
|
|
29050
|
+
consequent: { kind: "literal", value: "true", literalType: "string" },
|
|
29051
|
+
alternate: { kind: "literal", value: "false", literalType: "string" }
|
|
29052
|
+
};
|
|
29053
|
+
}
|
|
28835
29054
|
// src/static-literal.ts
|
|
28836
29055
|
function evaluateStaticLiteral(expr, bindings) {
|
|
28837
29056
|
switch (expr.kind) {
|
|
@@ -28967,8 +29186,10 @@ function nullableSignalAttrGetter(parsed, nullable) {
|
|
|
28967
29186
|
return getter !== null && nullable.has(getter) ? getter : null;
|
|
28968
29187
|
}
|
|
28969
29188
|
function collectNullishAttrContext(ir) {
|
|
29189
|
+
const signals = ir.metadata.signals ?? [];
|
|
28970
29190
|
return {
|
|
28971
29191
|
nullableSignals: collectNullableSignalGetters(ir),
|
|
29192
|
+
nullSeededSignals: new Set(signals.filter((s) => s.parsed?.kind === "literal" && s.parsed.literalType === "null").map((s) => s.getter)),
|
|
28972
29193
|
memos: new Map((ir.metadata.memos ?? []).map((m) => [m.name, m]))
|
|
28973
29194
|
};
|
|
28974
29195
|
}
|
|
@@ -29010,6 +29231,27 @@ function attrValueMayBeNullish(parsed, ctx, isShadowed = () => false) {
|
|
|
29010
29231
|
};
|
|
29011
29232
|
return parsed !== undefined && walk(parsed, isShadowed);
|
|
29012
29233
|
}
|
|
29234
|
+
function arithmeticOperandIsNull(parsed, ctx, isShadowed = () => false) {
|
|
29235
|
+
const visiting = new Set;
|
|
29236
|
+
const walk = (expr, shadowed) => {
|
|
29237
|
+
if (expr.kind === "literal")
|
|
29238
|
+
return expr.literalType === "null";
|
|
29239
|
+
const getter = expr.kind === "identifier" ? expr.name : bareGetterCallName(expr);
|
|
29240
|
+
if (getter === null || shadowed(getter))
|
|
29241
|
+
return false;
|
|
29242
|
+
if (ctx.nullSeededSignals?.has(getter))
|
|
29243
|
+
return true;
|
|
29244
|
+
const memo = ctx.memos.get(getter);
|
|
29245
|
+
if (!memo?.parsed || visiting.has(getter))
|
|
29246
|
+
return false;
|
|
29247
|
+
visiting.add(getter);
|
|
29248
|
+
const result = walk(memo.parsed, () => false);
|
|
29249
|
+
visiting.delete(getter);
|
|
29250
|
+
return result;
|
|
29251
|
+
};
|
|
29252
|
+
return parsed !== undefined && walk(parsed, isShadowed);
|
|
29253
|
+
}
|
|
29254
|
+
var NULL_COERCING_ARITHMETIC_OPS = new Set(["-", "*", "/", "%", "**"]);
|
|
29013
29255
|
// src/query-href-lowering.ts
|
|
29014
29256
|
function matchQueryHrefCall(callee, args, localNames) {
|
|
29015
29257
|
if (callee.kind !== "identifier" || !localNames.has(callee.name))
|
|
@@ -31313,6 +31555,32 @@ function buildIdIndex(graph) {
|
|
|
31313
31555
|
}
|
|
31314
31556
|
return index;
|
|
31315
31557
|
}
|
|
31558
|
+
function buildRestHandlerSites(componentName, ir) {
|
|
31559
|
+
const sites = new Map;
|
|
31560
|
+
walkIR(ir.root, undefined, {
|
|
31561
|
+
element({ node, descend }) {
|
|
31562
|
+
const spread = node.slotId ? node.attrs.find((a) => a.name === "...") : undefined;
|
|
31563
|
+
if (spread && node.slotId) {
|
|
31564
|
+
const loc = spread.loc ?? node.loc;
|
|
31565
|
+
sites.set(`${componentName}#handler:${node.slotId}`, {
|
|
31566
|
+
kind: "handler",
|
|
31567
|
+
name: `@${node.slotId} {...}`,
|
|
31568
|
+
loc: { file: loc.file, line: loc.start.line }
|
|
31569
|
+
});
|
|
31570
|
+
}
|
|
31571
|
+
descend();
|
|
31572
|
+
},
|
|
31573
|
+
component({ descend, descendJsxChildren }) {
|
|
31574
|
+
descend();
|
|
31575
|
+
descendJsxChildren();
|
|
31576
|
+
}
|
|
31577
|
+
});
|
|
31578
|
+
return sites;
|
|
31579
|
+
}
|
|
31580
|
+
function restSiteOf(handlerId, sites) {
|
|
31581
|
+
const colon = handlerId.lastIndexOf(":");
|
|
31582
|
+
return colon < 0 ? undefined : sites.get(handlerId.slice(0, colon));
|
|
31583
|
+
}
|
|
31316
31584
|
function isRuntimeBookkeepingId(id) {
|
|
31317
31585
|
return /^[serm]\d+$/.test(id);
|
|
31318
31586
|
}
|
|
@@ -31784,7 +32052,8 @@ function buildProfileReport(input) {
|
|
|
31784
32052
|
const allSources = [{ source, filePath }, ...input.extraSources ?? []];
|
|
31785
32053
|
const index = new Map;
|
|
31786
32054
|
const turnBindings = new Map;
|
|
31787
|
-
|
|
32055
|
+
const staticHandlerIds = new Set;
|
|
32056
|
+
const restSites = new Map;
|
|
31788
32057
|
const instrumentedEffectLines = new Map;
|
|
31789
32058
|
for (const s of allSources) {
|
|
31790
32059
|
const program = createProgramForFile(s.source, s.filePath)?.program;
|
|
@@ -31798,13 +32067,19 @@ function buildProfileReport(input) {
|
|
|
31798
32067
|
componentNames = [undefined];
|
|
31799
32068
|
for (const name of componentNames) {
|
|
31800
32069
|
let graph;
|
|
32070
|
+
let ir;
|
|
31801
32071
|
try {
|
|
31802
|
-
graph = buildComponentAnalysis(s.source, s.filePath, name, program)
|
|
32072
|
+
({ graph, ir } = buildComponentAnalysis(s.source, s.filePath, name, program));
|
|
31803
32073
|
} catch {
|
|
31804
32074
|
continue;
|
|
31805
32075
|
}
|
|
31806
|
-
for (const [k, v] of buildIdIndex(graph))
|
|
32076
|
+
for (const [k, v] of buildIdIndex(graph)) {
|
|
31807
32077
|
index.set(k, v);
|
|
32078
|
+
if (v.kind === "handler")
|
|
32079
|
+
staticHandlerIds.add(k);
|
|
32080
|
+
}
|
|
32081
|
+
for (const [k, v] of buildRestHandlerSites(graph.componentName, ir))
|
|
32082
|
+
restSites.set(k, v);
|
|
31808
32083
|
for (const e of graph.effects) {
|
|
31809
32084
|
const set = instrumentedEffectLines.get(e.loc.file) ?? new Set;
|
|
31810
32085
|
set.add(e.loc.line);
|
|
@@ -31812,13 +32087,19 @@ function buildProfileReport(input) {
|
|
|
31812
32087
|
}
|
|
31813
32088
|
try {
|
|
31814
32089
|
const summary = buildEventSummary(s.source, s.filePath, name, program);
|
|
31815
|
-
handlersTotal += summary.events.length;
|
|
31816
32090
|
for (const [turn, binding] of turnToEventBinding(graph, summary.events)) {
|
|
31817
32091
|
turnBindings.set(turn, { binding, graph });
|
|
31818
32092
|
}
|
|
31819
32093
|
} catch {}
|
|
31820
32094
|
}
|
|
31821
32095
|
}
|
|
32096
|
+
for (const e of events) {
|
|
32097
|
+
if (e.turn === null || index.has(e.turn))
|
|
32098
|
+
continue;
|
|
32099
|
+
const site = restSiteOf(e.turn, restSites);
|
|
32100
|
+
if (site)
|
|
32101
|
+
index.set(e.turn, { ...site, name: `${e.turn.slice(e.turn.lastIndexOf(":") + 1)}${site.name}` });
|
|
32102
|
+
}
|
|
31822
32103
|
const hasFallbackEffectId = events.some((e) => e.subscriber !== undefined && isFallbackEffectId(e.subscriber));
|
|
31823
32104
|
const uninstrumentedCandidates = [];
|
|
31824
32105
|
if (hasFallbackEffectId) {
|
|
@@ -31854,9 +32135,10 @@ function buildProfileReport(input) {
|
|
|
31854
32135
|
handlerIds.add(e.turn);
|
|
31855
32136
|
}
|
|
31856
32137
|
}
|
|
32138
|
+
const handlersTotal = new Set([...staticHandlerIds, ...handlerIds]).size;
|
|
31857
32139
|
const findings = buildAgentFindings(primary.componentName, hotSubscribers, wastedReReruns, batchAdvisor, unattributed);
|
|
31858
32140
|
const status = findings.some((f) => f.severity === "warning" || f.severity === "error") ? "warning" : "ok";
|
|
31859
|
-
const ratio = handlersTotal > 0 ?
|
|
32141
|
+
const ratio = handlersTotal > 0 ? handlerIds.size / handlersTotal : 1;
|
|
31860
32142
|
let guidance;
|
|
31861
32143
|
if (turnSeqs.size === 0) {
|
|
31862
32144
|
guidance = handlersTotal === 0 ? {
|
|
@@ -32321,6 +32603,7 @@ export {
|
|
|
32321
32603
|
traceUpdatePath,
|
|
32322
32604
|
testAdapter,
|
|
32323
32605
|
stringifyParsedExpr,
|
|
32606
|
+
stringifyBooleanTernaryBranches,
|
|
32324
32607
|
sortComparatorFromArrow,
|
|
32325
32608
|
serializeParsedExpr,
|
|
32326
32609
|
searchParamsLocalNames,
|
|
@@ -32385,6 +32668,7 @@ export {
|
|
|
32385
32668
|
isEventHandlerName,
|
|
32386
32669
|
isElidedFactoryGetter,
|
|
32387
32670
|
isDangerousInnerHtmlAttr,
|
|
32671
|
+
isBooleanResultParsed,
|
|
32388
32672
|
isBooleanAttr,
|
|
32389
32673
|
importsSearchParams,
|
|
32390
32674
|
identifierPath,
|
|
@@ -32482,6 +32766,7 @@ export {
|
|
|
32482
32766
|
augmentInheritedPropAccesses,
|
|
32483
32767
|
attrValueMayBeNullish,
|
|
32484
32768
|
asCallbackMethodCall,
|
|
32769
|
+
arithmeticOperandIsNull,
|
|
32485
32770
|
applyCssLayerPrefix,
|
|
32486
32771
|
analyzeWastedReReruns,
|
|
32487
32772
|
analyzeHotSubscribers,
|
|
@@ -32498,6 +32783,7 @@ export {
|
|
|
32498
32783
|
REACTIVE_PRIMITIVES,
|
|
32499
32784
|
PROFILE_SCHEMA_VERSION,
|
|
32500
32785
|
PARSED_EXPR_KINDS,
|
|
32786
|
+
NULL_COERCING_ARITHMETIC_OPS,
|
|
32501
32787
|
JsxAdapter,
|
|
32502
32788
|
ErrorCodes,
|
|
32503
32789
|
ESCAPE_SSR_COST,
|