@barefootjs/jsx 0.39.3 → 0.39.5
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/adapters/filter-capture-collisions.d.ts +17 -0
- package/dist/adapters/filter-capture-collisions.d.ts.map +1 -0
- package/dist/adapters/parsed-expr-emitter.d.ts +8 -0
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/template-name-collisions.d.ts +21 -0
- package/dist/adapters/template-name-collisions.d.ts.map +1 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +10 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +688 -176
- 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 +13 -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/build-loop-child-arm.d.ts +3 -2
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.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/ir-to-client-js/utils.d.ts +39 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +33 -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/dist/scope/binding-scope.d.ts +10 -0
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/binding-scope-ratchet.test.ts +1 -1
- package/src/__tests__/binding-scope.test.ts +11 -0
- package/src/__tests__/boolean-result.test.ts +27 -0
- package/src/__tests__/compile-without-node-process.test.ts +78 -0
- package/src/__tests__/csr-template-loop-shadow.test.ts +83 -0
- package/src/__tests__/doc-examples.test.ts +1 -0
- package/src/__tests__/nested-row-shadowing.test.ts +57 -0
- package/src/__tests__/profile-turn-markers.test.ts +22 -0
- package/src/__tests__/profiler.test.ts +10 -9
- package/src/__tests__/rename-free-identifiers.test.ts +26 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +88 -13
- package/src/__tests__/template-name-collisions.test.ts +81 -0
- package/src/adapters/boolean-result.ts +89 -0
- package/src/adapters/filter-capture-collisions.ts +29 -0
- package/src/adapters/parsed-expr-emitter.ts +18 -0
- package/src/adapters/template-name-collisions.ts +120 -0
- package/src/analyzer-context.ts +15 -1
- package/src/errors.ts +11 -0
- package/src/expression-parser.ts +32 -0
- package/src/index.ts +9 -2
- package/src/ir-to-client-js/collect-elements.ts +22 -10
- 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 +38 -12
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +12 -5
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +2 -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 +6 -1
- 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 +72 -15
- package/src/ir-to-client-js/imports.ts +3 -1
- package/src/ir-to-client-js/index.ts +7 -2
- 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/ir-to-client-js/utils.ts +81 -7
- package/src/jsx-to-ir.ts +138 -32
- package/src/nullable-signal-attr.ts +78 -0
- package/src/profiler.ts +79 -10
- package/src/scope/binding-scope.ts +19 -0
- package/src/types.ts +7 -0
package/dist/index.js
CHANGED
|
@@ -2144,6 +2144,33 @@ function freeVarsInBody(body, params) {
|
|
|
2144
2144
|
visit(body, params);
|
|
2145
2145
|
return [...found].sort();
|
|
2146
2146
|
}
|
|
2147
|
+
function renameFreeIdentifiers(expr, renames) {
|
|
2148
|
+
if (renames.size === 0)
|
|
2149
|
+
return expr;
|
|
2150
|
+
const walk = (value, active) => {
|
|
2151
|
+
if (Array.isArray(value))
|
|
2152
|
+
return value.map((v) => walk(v, active));
|
|
2153
|
+
if (value === null || typeof value !== "object")
|
|
2154
|
+
return value;
|
|
2155
|
+
const node = value;
|
|
2156
|
+
if (node.kind === "identifier" && typeof node.name === "string") {
|
|
2157
|
+
const renamed = active.get(node.name);
|
|
2158
|
+
return renamed === undefined ? node : { ...node, name: renamed };
|
|
2159
|
+
}
|
|
2160
|
+
let inner = active;
|
|
2161
|
+
if (node.kind === "arrow" && Array.isArray(node.params)) {
|
|
2162
|
+
const shadowed = new Map(active);
|
|
2163
|
+
for (const p of node.params)
|
|
2164
|
+
shadowed.delete(p);
|
|
2165
|
+
inner = shadowed;
|
|
2166
|
+
}
|
|
2167
|
+
const out = {};
|
|
2168
|
+
for (const [k, v] of Object.entries(node))
|
|
2169
|
+
out[k] = walk(v, inner);
|
|
2170
|
+
return out;
|
|
2171
|
+
};
|
|
2172
|
+
return walk(expr, renames);
|
|
2173
|
+
}
|
|
2147
2174
|
function freeIdentifiers(expr) {
|
|
2148
2175
|
const free = new Set;
|
|
2149
2176
|
function visit(e, bound) {
|
|
@@ -2397,6 +2424,112 @@ import ts11 from "typescript";
|
|
|
2397
2424
|
// src/ir-to-client-js/utils.ts
|
|
2398
2425
|
import ts5 from "typescript";
|
|
2399
2426
|
|
|
2427
|
+
// src/scope/binding-scope.ts
|
|
2428
|
+
function isStringLoopValue(type) {
|
|
2429
|
+
return type.primitive === "string" || type.unionTypes !== undefined && type.unionTypes.length > 0 && type.unionTypes.every(isStringLoopValue);
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
class BindingScope {
|
|
2433
|
+
frames;
|
|
2434
|
+
static EMPTY = new BindingScope([]);
|
|
2435
|
+
constructor(frames) {
|
|
2436
|
+
this.frames = frames;
|
|
2437
|
+
}
|
|
2438
|
+
enterLoopRow(loop) {
|
|
2439
|
+
const bindings = new Map;
|
|
2440
|
+
if (loop.paramBindings && loop.paramBindings.length > 0) {
|
|
2441
|
+
for (const b of loop.paramBindings)
|
|
2442
|
+
bindings.set(b.name, { source: "destructure" });
|
|
2443
|
+
} else {
|
|
2444
|
+
bindings.set(loop.param, {
|
|
2445
|
+
source: "item",
|
|
2446
|
+
...loop.itemType ? { stringValue: isStringLoopValue(loop.itemType) } : {}
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2449
|
+
if (loop.index != null)
|
|
2450
|
+
bindings.set(loop.index, { source: "index" });
|
|
2451
|
+
for (const name of loop.preamble?.declaredNames ?? [])
|
|
2452
|
+
bindings.set(name, { source: "preamble" });
|
|
2453
|
+
const frame = { kind: "loop-row", bindings };
|
|
2454
|
+
return new BindingScope([frame, ...this.frames]);
|
|
2455
|
+
}
|
|
2456
|
+
enterCallback(params) {
|
|
2457
|
+
const bindings = new Map;
|
|
2458
|
+
for (const name of params)
|
|
2459
|
+
bindings.set(name, { source: "param" });
|
|
2460
|
+
const frame = { kind: "callback", bindings };
|
|
2461
|
+
return new BindingScope([frame, ...this.frames]);
|
|
2462
|
+
}
|
|
2463
|
+
enterAliases(aliasToOriginal) {
|
|
2464
|
+
const bindings = new Map;
|
|
2465
|
+
for (const [alias, original] of aliasToOriginal) {
|
|
2466
|
+
const hit = this.lookup(original);
|
|
2467
|
+
if (hit)
|
|
2468
|
+
bindings.set(alias, hit.binding);
|
|
2469
|
+
}
|
|
2470
|
+
if (bindings.size === 0)
|
|
2471
|
+
return this;
|
|
2472
|
+
return new BindingScope([{ kind: "callback", bindings }, ...this.frames]);
|
|
2473
|
+
}
|
|
2474
|
+
isBound(name) {
|
|
2475
|
+
for (const frame of this.frames) {
|
|
2476
|
+
if (frame.bindings.has(name))
|
|
2477
|
+
return true;
|
|
2478
|
+
}
|
|
2479
|
+
return false;
|
|
2480
|
+
}
|
|
2481
|
+
isStringValueName(name, outer, componentProperty = false) {
|
|
2482
|
+
if (componentProperty)
|
|
2483
|
+
return outer(name);
|
|
2484
|
+
const hit = this.lookup(name);
|
|
2485
|
+
return hit ? hit.binding.stringValue === true : outer(name);
|
|
2486
|
+
}
|
|
2487
|
+
shadowedNames() {
|
|
2488
|
+
if (!this.frames[0])
|
|
2489
|
+
return [];
|
|
2490
|
+
return [...this.frames[0].bindings.keys()].filter((name) => this.frames.slice(1).some((frame) => frame.bindings.has(name)));
|
|
2491
|
+
}
|
|
2492
|
+
lookup(name) {
|
|
2493
|
+
for (let depth = 0;depth < this.frames.length; depth++) {
|
|
2494
|
+
const frame = this.frames[depth];
|
|
2495
|
+
const binding = frame.bindings.get(name);
|
|
2496
|
+
if (binding)
|
|
2497
|
+
return { depth, frame, binding };
|
|
2498
|
+
}
|
|
2499
|
+
return null;
|
|
2500
|
+
}
|
|
2501
|
+
boundNames() {
|
|
2502
|
+
if (this.boundNamesCache)
|
|
2503
|
+
return this.boundNamesCache;
|
|
2504
|
+
const names = new Set;
|
|
2505
|
+
for (const frame of this.frames) {
|
|
2506
|
+
for (const name of frame.bindings.keys())
|
|
2507
|
+
names.add(name);
|
|
2508
|
+
}
|
|
2509
|
+
this.boundNamesCache = names;
|
|
2510
|
+
return names;
|
|
2511
|
+
}
|
|
2512
|
+
boundNamesCache;
|
|
2513
|
+
valueBoundNamesCache;
|
|
2514
|
+
valueBoundNames() {
|
|
2515
|
+
if (this.valueBoundNamesCache)
|
|
2516
|
+
return this.valueBoundNamesCache;
|
|
2517
|
+
const names = new Set;
|
|
2518
|
+
for (const frame of this.frames) {
|
|
2519
|
+
for (const [name, binding] of frame.bindings) {
|
|
2520
|
+
if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
|
|
2521
|
+
names.add(name);
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
this.valueBoundNamesCache = names;
|
|
2526
|
+
return names;
|
|
2527
|
+
}
|
|
2528
|
+
asShadowPredicate() {
|
|
2529
|
+
return (name) => this.isBound(name);
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2400
2533
|
// src/loop-chain.ts
|
|
2401
2534
|
function buildLoopChainExpr(opts) {
|
|
2402
2535
|
const sortExpr = opts.sortComparator ? `.toSorted((${opts.sortComparator.paramA}, ${opts.sortComparator.paramB}) => ${opts.sortComparator.raw})` : "";
|
|
@@ -2600,6 +2733,10 @@ var RUNTIME_IMPORT_CANDIDATES = [
|
|
|
2600
2733
|
"markupOrEmpty",
|
|
2601
2734
|
"qsa",
|
|
2602
2735
|
"qsaItem",
|
|
2736
|
+
"adoptRowPortal",
|
|
2737
|
+
"claimRowPortals",
|
|
2738
|
+
"relayRowPortalEvents",
|
|
2739
|
+
"isRowPortalOf",
|
|
2603
2740
|
"qsaChildScope",
|
|
2604
2741
|
"qsaChildScopes",
|
|
2605
2742
|
"upsertChildItem",
|
|
@@ -2819,6 +2956,9 @@ function isCommentScopedRoot(root) {
|
|
|
2819
2956
|
function isScopeCommentFragmentRoot(root) {
|
|
2820
2957
|
return root.type === "fragment" && !!root.needsScopeComment;
|
|
2821
2958
|
}
|
|
2959
|
+
function isTransparentFragmentRoot(root) {
|
|
2960
|
+
return root.type === "fragment" && !!root.transparent;
|
|
2961
|
+
}
|
|
2822
2962
|
function componentDefScopeFlags(root) {
|
|
2823
2963
|
const flags = [];
|
|
2824
2964
|
if (isCommentScopedRoot(root))
|
|
@@ -3062,7 +3202,7 @@ function scanForIdentifiers(expr, predicate) {
|
|
|
3062
3202
|
return false;
|
|
3063
3203
|
}
|
|
3064
3204
|
function renderLoopBindingAccess(b, base) {
|
|
3065
|
-
const parent = `${base}${b.path}`;
|
|
3205
|
+
const parent = `${b.accessor ?? base}${b.path}`;
|
|
3066
3206
|
if (b.rest?.kind === "object") {
|
|
3067
3207
|
if (b.rest.exclude.length === 0) {
|
|
3068
3208
|
return `({...${parent}})`;
|
|
@@ -3077,18 +3217,27 @@ function renderLoopBindingAccess(b, base) {
|
|
|
3077
3217
|
}
|
|
3078
3218
|
return parent;
|
|
3079
3219
|
}
|
|
3080
|
-
function wrapLoopParamAsAccessor(expr, paramName, bindings, indexParam) {
|
|
3220
|
+
function wrapLoopParamAsAccessor(expr, paramName, bindings, indexParam, shadowed) {
|
|
3221
|
+
const destructured = !!bindings && bindings.length > 0;
|
|
3222
|
+
const liveBindings = destructured && shadowed ? bindings.filter((b) => !shadowed.has(b.name)) : bindings;
|
|
3223
|
+
const liveIndex = indexParam && shadowed?.has(indexParam) ? null : indexParam;
|
|
3081
3224
|
let result;
|
|
3082
|
-
if (
|
|
3083
|
-
result = rewriteLoopBindingRefs(expr,
|
|
3225
|
+
if (destructured) {
|
|
3226
|
+
result = liveBindings && liveBindings.length > 0 ? rewriteLoopBindingRefs(expr, liveBindings, "__bfItem()") : expr;
|
|
3084
3227
|
} else {
|
|
3085
|
-
result = rewriteIdentifierAsAccessor(expr, paramName);
|
|
3228
|
+
result = shadowed?.has(paramName) ? expr : rewriteIdentifierAsAccessor(expr, paramName);
|
|
3086
3229
|
}
|
|
3087
|
-
if (
|
|
3088
|
-
result = wrapIndexParamAsAccessor(result,
|
|
3230
|
+
if (liveIndex && liveIndex !== paramName) {
|
|
3231
|
+
result = wrapIndexParamAsAccessor(result, liveIndex);
|
|
3089
3232
|
}
|
|
3090
3233
|
return result;
|
|
3091
3234
|
}
|
|
3235
|
+
function unionNames(a, b) {
|
|
3236
|
+
return b && b.size > 0 ? new Set([...a, ...b]) : a;
|
|
3237
|
+
}
|
|
3238
|
+
function rowBoundNames(loop) {
|
|
3239
|
+
return BindingScope.EMPTY.enterLoopRow(loop).boundNames();
|
|
3240
|
+
}
|
|
3092
3241
|
function wrapIndexParamAsAccessor(expr, indexParam) {
|
|
3093
3242
|
return rewriteIdentifierAsAccessor(expr, indexParam);
|
|
3094
3243
|
}
|
|
@@ -3167,10 +3316,28 @@ function wrapExprWithLoopParams(expr, loopParams) {
|
|
|
3167
3316
|
let result = expr;
|
|
3168
3317
|
for (const p of loopParams) {
|
|
3169
3318
|
const spec = typeof p === "string" ? { param: p } : p;
|
|
3170
|
-
result = wrapLoopParamAsAccessor(result, spec.param, spec.bindings, spec.index);
|
|
3319
|
+
result = wrapLoopParamAsAccessor(result, spec.param, spec.bindings, spec.index, spec.shadowed);
|
|
3171
3320
|
}
|
|
3172
3321
|
return result;
|
|
3173
3322
|
}
|
|
3323
|
+
function specsInsideRow(specs, loop) {
|
|
3324
|
+
if (!specs)
|
|
3325
|
+
return specs;
|
|
3326
|
+
const names = rowBoundNames(loop);
|
|
3327
|
+
if (names.size === 0)
|
|
3328
|
+
return specs;
|
|
3329
|
+
return specs.map((p) => {
|
|
3330
|
+
const spec = typeof p === "string" ? { param: p } : p;
|
|
3331
|
+
const shadowed = spec.shadowed ? new Set([...spec.shadowed, ...names]) : names;
|
|
3332
|
+
return { ...spec, shadowed };
|
|
3333
|
+
});
|
|
3334
|
+
}
|
|
3335
|
+
function withRowAccessor(bindings, markerId) {
|
|
3336
|
+
if (!bindings || bindings.length === 0)
|
|
3337
|
+
return bindings;
|
|
3338
|
+
const accessor = `__bfItem_${markerId}()`;
|
|
3339
|
+
return bindings.map((b) => ({ ...b, accessor }));
|
|
3340
|
+
}
|
|
3174
3341
|
|
|
3175
3342
|
// src/html-constants.ts
|
|
3176
3343
|
import { BOOLEAN_ATTRS, isBooleanAttr } from "@barefootjs/shared";
|
|
@@ -4164,101 +4331,6 @@ function renderChildScopeArgs(comp, keyArg) {
|
|
|
4164
4331
|
return derivesScopeFromSlot(comp) ? `${key}, '${comp.slotId}'` : `${key}, '${comp.slotId}', true`;
|
|
4165
4332
|
}
|
|
4166
4333
|
|
|
4167
|
-
// src/scope/binding-scope.ts
|
|
4168
|
-
function isStringLoopValue(type) {
|
|
4169
|
-
return type.primitive === "string" || type.unionTypes !== undefined && type.unionTypes.length > 0 && type.unionTypes.every(isStringLoopValue);
|
|
4170
|
-
}
|
|
4171
|
-
|
|
4172
|
-
class BindingScope {
|
|
4173
|
-
frames;
|
|
4174
|
-
static EMPTY = new BindingScope([]);
|
|
4175
|
-
constructor(frames) {
|
|
4176
|
-
this.frames = frames;
|
|
4177
|
-
}
|
|
4178
|
-
enterLoopRow(loop) {
|
|
4179
|
-
const bindings = new Map;
|
|
4180
|
-
if (loop.paramBindings && loop.paramBindings.length > 0) {
|
|
4181
|
-
for (const b of loop.paramBindings)
|
|
4182
|
-
bindings.set(b.name, { source: "destructure" });
|
|
4183
|
-
} else {
|
|
4184
|
-
bindings.set(loop.param, {
|
|
4185
|
-
source: "item",
|
|
4186
|
-
...loop.itemType ? { stringValue: isStringLoopValue(loop.itemType) } : {}
|
|
4187
|
-
});
|
|
4188
|
-
}
|
|
4189
|
-
if (loop.index != null)
|
|
4190
|
-
bindings.set(loop.index, { source: "index" });
|
|
4191
|
-
for (const name of loop.preamble?.declaredNames ?? [])
|
|
4192
|
-
bindings.set(name, { source: "preamble" });
|
|
4193
|
-
const frame = { kind: "loop-row", bindings };
|
|
4194
|
-
return new BindingScope([frame, ...this.frames]);
|
|
4195
|
-
}
|
|
4196
|
-
enterCallback(params) {
|
|
4197
|
-
const bindings = new Map;
|
|
4198
|
-
for (const name of params)
|
|
4199
|
-
bindings.set(name, { source: "param" });
|
|
4200
|
-
const frame = { kind: "callback", bindings };
|
|
4201
|
-
return new BindingScope([frame, ...this.frames]);
|
|
4202
|
-
}
|
|
4203
|
-
isBound(name) {
|
|
4204
|
-
for (const frame of this.frames) {
|
|
4205
|
-
if (frame.bindings.has(name))
|
|
4206
|
-
return true;
|
|
4207
|
-
}
|
|
4208
|
-
return false;
|
|
4209
|
-
}
|
|
4210
|
-
isStringValueName(name, outer, componentProperty = false) {
|
|
4211
|
-
if (componentProperty)
|
|
4212
|
-
return outer(name);
|
|
4213
|
-
const hit = this.lookup(name);
|
|
4214
|
-
return hit ? hit.binding.stringValue === true : outer(name);
|
|
4215
|
-
}
|
|
4216
|
-
shadowedNames() {
|
|
4217
|
-
if (!this.frames[0])
|
|
4218
|
-
return [];
|
|
4219
|
-
return [...this.frames[0].bindings.keys()].filter((name) => this.frames.slice(1).some((frame) => frame.bindings.has(name)));
|
|
4220
|
-
}
|
|
4221
|
-
lookup(name) {
|
|
4222
|
-
for (let depth = 0;depth < this.frames.length; depth++) {
|
|
4223
|
-
const frame = this.frames[depth];
|
|
4224
|
-
const binding = frame.bindings.get(name);
|
|
4225
|
-
if (binding)
|
|
4226
|
-
return { depth, frame, binding };
|
|
4227
|
-
}
|
|
4228
|
-
return null;
|
|
4229
|
-
}
|
|
4230
|
-
boundNames() {
|
|
4231
|
-
if (this.boundNamesCache)
|
|
4232
|
-
return this.boundNamesCache;
|
|
4233
|
-
const names = new Set;
|
|
4234
|
-
for (const frame of this.frames) {
|
|
4235
|
-
for (const name of frame.bindings.keys())
|
|
4236
|
-
names.add(name);
|
|
4237
|
-
}
|
|
4238
|
-
this.boundNamesCache = names;
|
|
4239
|
-
return names;
|
|
4240
|
-
}
|
|
4241
|
-
boundNamesCache;
|
|
4242
|
-
valueBoundNamesCache;
|
|
4243
|
-
valueBoundNames() {
|
|
4244
|
-
if (this.valueBoundNamesCache)
|
|
4245
|
-
return this.valueBoundNamesCache;
|
|
4246
|
-
const names = new Set;
|
|
4247
|
-
for (const frame of this.frames) {
|
|
4248
|
-
for (const [name, binding] of frame.bindings) {
|
|
4249
|
-
if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
|
|
4250
|
-
names.add(name);
|
|
4251
|
-
}
|
|
4252
|
-
}
|
|
4253
|
-
}
|
|
4254
|
-
this.valueBoundNamesCache = names;
|
|
4255
|
-
return names;
|
|
4256
|
-
}
|
|
4257
|
-
asShadowPredicate() {
|
|
4258
|
-
return (name) => this.isBound(name);
|
|
4259
|
-
}
|
|
4260
|
-
}
|
|
4261
|
-
|
|
4262
4334
|
// src/ir-to-client-js/safe-html.ts
|
|
4263
4335
|
function safeHtml(expr) {
|
|
4264
4336
|
return expr;
|
|
@@ -4293,6 +4365,11 @@ function conditionalMarkup(condition, whenTrue, whenFalse) {
|
|
|
4293
4365
|
function mappedRowsMarkup(arrayExpr, method, params, body) {
|
|
4294
4366
|
return safeHtml(`${arrayExpr}.${method}(${params} => ${body}).join('')`);
|
|
4295
4367
|
}
|
|
4368
|
+
function withOuterBindings(params, values, markup) {
|
|
4369
|
+
if (params.length === 0)
|
|
4370
|
+
return markup;
|
|
4371
|
+
return safeHtml(`((${params.join(", ")}) => ${markup})(${values.join(", ")})`);
|
|
4372
|
+
}
|
|
4296
4373
|
var EMPTY_MARKUP = safeHtml("''");
|
|
4297
4374
|
function isChildrenPassthroughExpr(expr) {
|
|
4298
4375
|
return isChildrenPassthrough(parseExpression(expr));
|
|
@@ -4782,7 +4859,8 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
|
|
|
4782
4859
|
return interp(renderChildCall(nameForRegistryRef(node.name), propsExpr, renderChildScopeArgs(node, keyArg)));
|
|
4783
4860
|
}
|
|
4784
4861
|
case "loop": {
|
|
4785
|
-
const
|
|
4862
|
+
const rowLoopParams = specsInsideRow(loopParams, node);
|
|
4863
|
+
const innerRecurse = (n) => irToHtmlTemplate(n, restSpreadNames, loopDepth + 1, rowLoopParams, branchSlotsVar);
|
|
4786
4864
|
let childTemplate = node.children.map(innerRecurse).join("");
|
|
4787
4865
|
if (node.bodyIsItemConditional && node.key) {
|
|
4788
4866
|
childTemplate = `${itemAnchorTemplate(node.key)}${childTemplate}`;
|
|
@@ -4795,11 +4873,11 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
|
|
|
4795
4873
|
let mapExpr;
|
|
4796
4874
|
if (node.flatMapCallback) {
|
|
4797
4875
|
const body = renderPreamble(node.flatMapCallback, {
|
|
4798
|
-
renderLeaf: (ir) => irToHtmlTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1,
|
|
4876
|
+
renderLeaf: (ir) => irToHtmlTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1, rowLoopParams, branchSlotsVar)
|
|
4799
4877
|
});
|
|
4800
4878
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, "flatMap", node.flatMapCallback.params, body));
|
|
4801
4879
|
} else if (node.preamble) {
|
|
4802
|
-
const preamble = renderPreamble(node.preamble, { textVariant: "client", renderLeaf: (ir) => irToHtmlTemplate(ir, restSpreadNames, loopDepth + 1,
|
|
4880
|
+
const preamble = renderPreamble(node.preamble, { textVariant: "client", renderLeaf: (ir) => irToHtmlTemplate(ir, restSpreadNames, loopDepth + 1, rowLoopParams, branchSlotsVar) });
|
|
4803
4881
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, iterMethod, callbackParam, `{ ${preamble} return \`${childTemplate}\` }`));
|
|
4804
4882
|
} else {
|
|
4805
4883
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, iterMethod, callbackParam, `\`${childTemplate}\``));
|
|
@@ -5081,7 +5159,8 @@ function irToPlaceholderTemplate(node, restSpreadNames, loopDepth = 0, loopParam
|
|
|
5081
5159
|
return `<div ${DATA_BF_PH}="${phId}"></div>`;
|
|
5082
5160
|
}
|
|
5083
5161
|
case "loop": {
|
|
5084
|
-
const
|
|
5162
|
+
const rowLoopParams = specsInsideRow(loopParams, node);
|
|
5163
|
+
const innerRecurse = (n) => irToPlaceholderTemplate(n, restSpreadNames, loopDepth + 1, rowLoopParams);
|
|
5085
5164
|
const childTemplate = node.children.map(innerRecurse).join("");
|
|
5086
5165
|
const indexParam = node.index ? `, ${node.index}` : "";
|
|
5087
5166
|
const rawChainedArray = applyLoopChain(node);
|
|
@@ -5091,11 +5170,11 @@ function irToPlaceholderTemplate(node, restSpreadNames, loopDepth = 0, loopParam
|
|
|
5091
5170
|
let mapExpr;
|
|
5092
5171
|
if (node.flatMapCallback) {
|
|
5093
5172
|
const body = renderPreamble(node.flatMapCallback, {
|
|
5094
|
-
renderLeaf: (ir) => irToPlaceholderTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1,
|
|
5173
|
+
renderLeaf: (ir) => irToPlaceholderTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1, rowLoopParams)
|
|
5095
5174
|
});
|
|
5096
5175
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, "flatMap", node.flatMapCallback.params, body));
|
|
5097
5176
|
} else if (node.preamble) {
|
|
5098
|
-
const preamble = renderPreamble(node.preamble, { textVariant: "client", renderLeaf: (ir) => irToPlaceholderTemplate(ir, restSpreadNames, loopDepth + 1,
|
|
5177
|
+
const preamble = renderPreamble(node.preamble, { textVariant: "client", renderLeaf: (ir) => irToPlaceholderTemplate(ir, restSpreadNames, loopDepth + 1, rowLoopParams) });
|
|
5099
5178
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, iterMethod, callbackParam, `{ ${preamble} return \`${childTemplate}\` }`));
|
|
5100
5179
|
} else {
|
|
5101
5180
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, iterMethod, callbackParam, `\`${childTemplate}\``));
|
|
@@ -5481,6 +5560,23 @@ function mergeCsrNullUnsafe(ctx, unsafeLocalNames) {
|
|
|
5481
5560
|
}
|
|
5482
5561
|
return merged ?? unsafeLocalNames;
|
|
5483
5562
|
}
|
|
5563
|
+
function closeOverLoopBindings(env, boundHere) {
|
|
5564
|
+
const substitutions = new Map;
|
|
5565
|
+
const hoisted = [];
|
|
5566
|
+
for (const [name, sub] of env.substitutions) {
|
|
5567
|
+
if (boundHere.has(name))
|
|
5568
|
+
continue;
|
|
5569
|
+
if (!setIntersects(extractFreeIdentifiersFromText(sub.replacement), boundHere)) {
|
|
5570
|
+
substitutions.set(name, sub);
|
|
5571
|
+
continue;
|
|
5572
|
+
}
|
|
5573
|
+
const closed = csrSubstitute(sub.replacement, env);
|
|
5574
|
+
if (setIntersects(closed.freeIdentifiers, boundHere))
|
|
5575
|
+
hoisted.push(name);
|
|
5576
|
+
substitutions.set(name, { ...sub, replacement: closed.rewritten, freeIdentifiers: closed.freeIdentifiers });
|
|
5577
|
+
}
|
|
5578
|
+
return { substitutions, hoisted };
|
|
5579
|
+
}
|
|
5484
5580
|
function buildCsrEnvForCtx(ctx, inlinableConstants, propsObjectName) {
|
|
5485
5581
|
const base = buildSignalMemoEnv(ctx.signals, ctx.memos, propsObjectName ?? null, ctx.localConstants);
|
|
5486
5582
|
const csrEnv = { substitutions: new Map(base.substitutions), propsObjectName: base.propsObjectName };
|
|
@@ -5727,10 +5823,20 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
5727
5823
|
case "loop": {
|
|
5728
5824
|
const childScope = (opts.scope ?? BindingScope.EMPTY).enterLoopRow(node);
|
|
5729
5825
|
const boundHere = childScope.boundNames();
|
|
5730
|
-
const
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5826
|
+
const { substitutions: childSubstitutions, hoisted } = closeOverLoopBindings(env, boundHere);
|
|
5827
|
+
const hoistParams = [];
|
|
5828
|
+
const hoistValues = [];
|
|
5829
|
+
for (const name of hoisted) {
|
|
5830
|
+
const sub = env.substitutions.get(name);
|
|
5831
|
+
const value = transformExpr(sub.kind === "call" ? `${name}()` : name);
|
|
5832
|
+
if (value === UNSAFE_TEMPLATE_EXPR)
|
|
5833
|
+
continue;
|
|
5834
|
+
const param = `__bf_outer_${name}`;
|
|
5835
|
+
hoistParams.push(param);
|
|
5836
|
+
hoistValues.push(value);
|
|
5837
|
+
childSubstitutions.set(name, { kind: sub.kind, replacement: param, freeIdentifiers: new Set([param]) });
|
|
5838
|
+
}
|
|
5839
|
+
const childEnv = { ...env, substitutions: childSubstitutions };
|
|
5734
5840
|
const recurseInLoopBody = (n) => generateCsrTemplateWithOpts(n, {
|
|
5735
5841
|
...opts,
|
|
5736
5842
|
loopDepth: loopDepth + 1,
|
|
@@ -5755,12 +5861,12 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
5755
5861
|
transformJs: (t) => rewritePropsObjectRef(t, propsObjectName ?? null, restPropsName ?? null, { enclosingScope: childScope }),
|
|
5756
5862
|
renderLeaf: (ir) => recurseInLoopBody(leafKeyAsDataKeyAttr(ir))
|
|
5757
5863
|
});
|
|
5758
|
-
mapExpr = interp(mappedRowsMarkup(iterArrayExpr, "flatMap", node.flatMapCallback.params, body));
|
|
5864
|
+
mapExpr = interp(withOuterBindings(hoistParams, hoistValues, mappedRowsMarkup(iterArrayExpr, "flatMap", node.flatMapCallback.params, body)));
|
|
5759
5865
|
} else if (node.preamble) {
|
|
5760
5866
|
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}\` }`));
|
|
5867
|
+
mapExpr = interp(withOuterBindings(hoistParams, hoistValues, mappedRowsMarkup(iterArrayExpr, iterMethod, callbackParam, `{ ${preamble} return \`${childTemplate}\` }`)));
|
|
5762
5868
|
} else {
|
|
5763
|
-
mapExpr = interp(mappedRowsMarkup(iterArrayExpr, iterMethod, callbackParam, `\`${childTemplate}\``));
|
|
5869
|
+
mapExpr = interp(withOuterBindings(hoistParams, hoistValues, mappedRowsMarkup(iterArrayExpr, iterMethod, callbackParam, `\`${childTemplate}\``)));
|
|
5764
5870
|
}
|
|
5765
5871
|
return `<!--${loopStartMarker(node.markerId)}-->${mapExpr}<!--${loopEndMarker(node.markerId)}-->`;
|
|
5766
5872
|
}
|
|
@@ -6340,6 +6446,10 @@ function collectReactiveBrandLeaves(node, checker) {
|
|
|
6340
6446
|
}
|
|
6341
6447
|
|
|
6342
6448
|
// src/analyzer-context.ts
|
|
6449
|
+
function isGetJsAssertionArmed() {
|
|
6450
|
+
const env = globalThis.process?.env;
|
|
6451
|
+
return env?.BF_ASSERT_NO_JSX_IN_GETJS === "1";
|
|
6452
|
+
}
|
|
6343
6453
|
function createAnalyzerContext(sourceFile, filePath, acceptsCallbackBody) {
|
|
6344
6454
|
return {
|
|
6345
6455
|
sourceFile,
|
|
@@ -6390,7 +6500,7 @@ function createAnalyzerContext(sourceFile, filePath, acceptsCallbackBody) {
|
|
|
6390
6500
|
} catch {
|
|
6391
6501
|
ownSourceFile = undefined;
|
|
6392
6502
|
}
|
|
6393
|
-
if (
|
|
6503
|
+
if (isGetJsAssertionArmed() && !this.errors.some((e) => e.severity === "error") && nodeContainsJsx(node)) {
|
|
6394
6504
|
throw new Error("getJS() called on a JSX-bearing node — raw JSX must never be spliced " + "into emitted output. Carry mixed content as structured segments " + "(MapCallbackPreamble / FlatMapCallback) instead.");
|
|
6395
6505
|
}
|
|
6396
6506
|
if (ownSourceFile && ownSourceFile !== sourceFile) {
|
|
@@ -6909,6 +7019,7 @@ var ErrorCodes = {
|
|
|
6909
7019
|
STAGE_INIT_LOCAL_IN_TEMPLATE: "BF061",
|
|
6910
7020
|
STAGE_AWAIT_IN_TEMPLATE: "BF062",
|
|
6911
7021
|
REF_ATTR_ABSENT_AT_SSR: "BF063",
|
|
7022
|
+
ROW_PORTAL_UNPAIRABLE: "BF064",
|
|
6912
7023
|
INLINE_JSX_CALLBACK_CAPTURE: "BF080",
|
|
6913
7024
|
UNRECOGNIZED_REACTIVE_FACTORY: "BF110",
|
|
6914
7025
|
REACTIVE_FACTORY_RENAME_UNSUPPORTED: "BF111",
|
|
@@ -6948,6 +7059,7 @@ var errorMessages = {
|
|
|
6948
7059
|
[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
7060
|
[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
7061
|
[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.",
|
|
7062
|
+
[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
7063
|
[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
7064
|
[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
7065
|
[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 +14654,88 @@ function applyLoopKeyAttr(node, name, value) {
|
|
|
14542
14654
|
applyLoopKeyAttr(first, name, value);
|
|
14543
14655
|
}
|
|
14544
14656
|
}
|
|
14657
|
+
function applyRowPortalKeyAttrs(children, key, depth, ctx) {
|
|
14658
|
+
const refuse = (el, reason) => {
|
|
14659
|
+
ctx.analyzer.errors.push(createError(ErrorCodes.ROW_PORTAL_UNPAIRABLE, el.loc, {
|
|
14660
|
+
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.",
|
|
14661
|
+
suggestion: {
|
|
14662
|
+
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.",
|
|
14663
|
+
escape: [{ kind: "rewrite" }]
|
|
14664
|
+
}
|
|
14665
|
+
}));
|
|
14666
|
+
};
|
|
14667
|
+
const visit3 = (node, blocked) => {
|
|
14668
|
+
switch (node.type) {
|
|
14669
|
+
case "element":
|
|
14670
|
+
if (node.ssrPortalOwnerScope) {
|
|
14671
|
+
if (node.keyAttr)
|
|
14672
|
+
refuse(node, "it is the root element of the row");
|
|
14673
|
+
else if (blocked)
|
|
14674
|
+
refuse(node, blocked);
|
|
14675
|
+
else if (key === null)
|
|
14676
|
+
refuse(node, "the loop has no `key`");
|
|
14677
|
+
else if (depth > 0)
|
|
14678
|
+
refuse(node, "the loop is nested inside another loop");
|
|
14679
|
+
else {
|
|
14680
|
+
node.keyAttr = { name: keyAttrName2(depth), value: key };
|
|
14681
|
+
if (!node.attrs.some((a) => a.name === "key")) {
|
|
14682
|
+
node.attrs.push(rowKeyAttribute(children) ?? { name: "key", value: { kind: "expression", expr: key }, loc: node.loc });
|
|
14683
|
+
}
|
|
14684
|
+
}
|
|
14685
|
+
}
|
|
14686
|
+
for (const c of node.children)
|
|
14687
|
+
visit3(c, blocked);
|
|
14688
|
+
return;
|
|
14689
|
+
case "fragment":
|
|
14690
|
+
for (const c of node.children)
|
|
14691
|
+
visit3(c, blocked);
|
|
14692
|
+
return;
|
|
14693
|
+
case "conditional": {
|
|
14694
|
+
const inner = blocked ?? (node.slotId ? "it is rendered inside a reactive conditional in the row" : null);
|
|
14695
|
+
visit3(node.whenTrue, inner);
|
|
14696
|
+
visit3(node.whenFalse, inner);
|
|
14697
|
+
return;
|
|
14698
|
+
}
|
|
14699
|
+
case "if-statement":
|
|
14700
|
+
visit3(node.consequent, blocked);
|
|
14701
|
+
if (node.alternate)
|
|
14702
|
+
visit3(node.alternate, blocked);
|
|
14703
|
+
return;
|
|
14704
|
+
case "component":
|
|
14705
|
+
case "provider":
|
|
14706
|
+
for (const c of node.children)
|
|
14707
|
+
visit3(c, blocked ?? "it is rendered inside another component's children");
|
|
14708
|
+
return;
|
|
14709
|
+
case "async":
|
|
14710
|
+
visit3(node.fallback, blocked ?? "it is rendered inside another component's children");
|
|
14711
|
+
for (const c of node.children)
|
|
14712
|
+
visit3(c, blocked ?? "it is rendered inside another component's children");
|
|
14713
|
+
return;
|
|
14714
|
+
default:
|
|
14715
|
+
return;
|
|
14716
|
+
}
|
|
14717
|
+
};
|
|
14718
|
+
for (const c of children)
|
|
14719
|
+
visit3(c, null);
|
|
14720
|
+
}
|
|
14721
|
+
function rowKeyAttribute(children) {
|
|
14722
|
+
const find = (node) => {
|
|
14723
|
+
switch (node.type) {
|
|
14724
|
+
case "element":
|
|
14725
|
+
return node.attrs.find((a) => a.name === "key") ?? null;
|
|
14726
|
+
case "conditional":
|
|
14727
|
+
return find(node.whenTrue);
|
|
14728
|
+
case "fragment": {
|
|
14729
|
+
const first2 = node.children.find((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
|
|
14730
|
+
return first2 ? find(first2) : null;
|
|
14731
|
+
}
|
|
14732
|
+
default:
|
|
14733
|
+
return null;
|
|
14734
|
+
}
|
|
14735
|
+
};
|
|
14736
|
+
const first = children.find((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
|
|
14737
|
+
return first ? find(first) : null;
|
|
14738
|
+
}
|
|
14545
14739
|
function loopBodyItemConditional(children) {
|
|
14546
14740
|
const real = children.filter((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
|
|
14547
14741
|
if (real.length !== 1)
|
|
@@ -14935,6 +15129,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
14935
15129
|
applyLoopKeyAttr(children[0], resolvedKeyAttrName2, key);
|
|
14936
15130
|
}
|
|
14937
15131
|
}
|
|
15132
|
+
applyRowPortalKeyAttrs(children, key, depth, ctx);
|
|
14938
15133
|
const declaredNameSet = preamble && preamble.declaredNames.length > 0 ? new Set(preamble.declaredNames) : undefined;
|
|
14939
15134
|
if (key && declaredNameSet) {
|
|
14940
15135
|
const keyRefs = extractFreeIdentifiersFromText(key);
|
|
@@ -15826,12 +16021,12 @@ function datasetKeyToAttrName(key) {
|
|
|
15826
16021
|
function resolveRefCallback(refExpr) {
|
|
15827
16022
|
const expr = unwrapTransparentTsWrappers(refExpr);
|
|
15828
16023
|
if (ts19.isArrowFunction(expr) || ts19.isFunctionExpression(expr)) {
|
|
15829
|
-
return { param: firstSimpleParamName(expr), body: expr.body, named: false
|
|
16024
|
+
return { param: firstSimpleParamName(expr), body: expr.body, named: false };
|
|
15830
16025
|
}
|
|
15831
16026
|
if (!ts19.isIdentifier(expr))
|
|
15832
16027
|
return;
|
|
15833
|
-
const
|
|
15834
|
-
return
|
|
16028
|
+
const callback = findNamedCallback(expr);
|
|
16029
|
+
return callback && { ...callback, named: true };
|
|
15835
16030
|
}
|
|
15836
16031
|
function isFunctionLike(node) {
|
|
15837
16032
|
return ts19.isArrowFunction(node) || ts19.isFunctionExpression(node) || ts19.isFunctionDeclaration(node);
|
|
@@ -15846,15 +16041,13 @@ function findEnclosingFunctionLike(node) {
|
|
|
15846
16041
|
return;
|
|
15847
16042
|
}
|
|
15848
16043
|
function findNamedCallback(ident) {
|
|
15849
|
-
|
|
15850
|
-
for (let fn = innermost;fn; fn = findEnclosingFunctionLike(fn)) {
|
|
16044
|
+
for (let fn = findEnclosingFunctionLike(ident);fn; fn = findEnclosingFunctionLike(fn)) {
|
|
15851
16045
|
if (fn.parameters.some((p) => bindingDeclares(p.name, ident.text)))
|
|
15852
16046
|
return;
|
|
15853
16047
|
const decl = fn.body && findScopeDeclaration(ident.text, fn.body);
|
|
15854
16048
|
if (!decl)
|
|
15855
16049
|
continue;
|
|
15856
|
-
|
|
15857
|
-
return callback && { callback, innermostScope: fn === innermost };
|
|
16050
|
+
return localCallbackOf(decl);
|
|
15858
16051
|
}
|
|
15859
16052
|
return;
|
|
15860
16053
|
}
|
|
@@ -15890,7 +16083,7 @@ function bindingDeclares(binding, name) {
|
|
|
15890
16083
|
return names.has(name);
|
|
15891
16084
|
}
|
|
15892
16085
|
function isSsrPortalRefCallback(callback) {
|
|
15893
|
-
return !!callback?.named &&
|
|
16086
|
+
return !!callback?.named && !!callback.param && containsSsrPortalPlacementCall(callback.body, callback.param);
|
|
15894
16087
|
}
|
|
15895
16088
|
function firstSimpleParamName(fn) {
|
|
15896
16089
|
const first = fn.parameters[0];
|
|
@@ -17265,7 +17458,8 @@ function collectLoopChildRefs(node) {
|
|
|
17265
17458
|
if (el.slotId && el.ref) {
|
|
17266
17459
|
refs.push({
|
|
17267
17460
|
childSlotId: el.slotId,
|
|
17268
|
-
callback: el.ref
|
|
17461
|
+
callback: el.ref,
|
|
17462
|
+
...el.ssrPortalOwnerScope && { ssrPortalOwner: true }
|
|
17269
17463
|
});
|
|
17270
17464
|
}
|
|
17271
17465
|
}, true);
|
|
@@ -17763,17 +17957,18 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx, options)
|
|
|
17763
17957
|
},
|
|
17764
17958
|
loop: ({ node: n, scope, descend }) => {
|
|
17765
17959
|
const emitDepth = fixedDepth ?? scope.depth + 1;
|
|
17766
|
-
const
|
|
17960
|
+
const rowBindings = withRowAccessor(n.paramBindings, n.markerId);
|
|
17961
|
+
const loopParamsForTemplate = outerSpec ? [{ ...outerSpec, shadowed: rowBoundNames(n) }, { param: n.param, bindings: rowBindings, index: n.index }] : undefined;
|
|
17767
17962
|
const template = n.children.map((c) => irToPlaceholderTemplate(c, undefined, emitDepth, loopParamsForTemplate)).join("");
|
|
17768
17963
|
const bindings = emptyLoopChildBindings();
|
|
17769
17964
|
const innerPreambleNames = preambleNamesOf(n);
|
|
17770
17965
|
if (ctx) {
|
|
17771
17966
|
for (const child of n.children) {
|
|
17772
|
-
bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, n.param,
|
|
17773
|
-
bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, n.param,
|
|
17967
|
+
bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, n.param, rowBindings, true, innerPreambleNames, n.index, scope.bindingScope));
|
|
17968
|
+
bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, n.param, rowBindings, true, innerPreambleNames, n.index, scope.bindingScope));
|
|
17774
17969
|
bindings.refs.push(...collectLoopChildRefs(child));
|
|
17775
17970
|
}
|
|
17776
|
-
bindings.conditionals.push(...collectLoopChildConditionals({ type: "fragment", children: n.children, loc: n.loc }, ctx, siblingOffsets, n.param,
|
|
17971
|
+
bindings.conditionals.push(...collectLoopChildConditionals({ type: "fragment", children: n.children, loc: n.loc }, ctx, siblingOffsets, n.param, rowBindings, innerPreambleNames, n.index, loopParamsForTemplate, scope.bindingScope));
|
|
17777
17972
|
}
|
|
17778
17973
|
let childComponents;
|
|
17779
17974
|
if (collectBindings) {
|
|
@@ -17804,7 +17999,7 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx, options)
|
|
|
17804
17999
|
array: n.array,
|
|
17805
18000
|
arrayFreeIdentifiers: n.arrayFreeIdentifiers,
|
|
17806
18001
|
param: n.param,
|
|
17807
|
-
paramBindings:
|
|
18002
|
+
paramBindings: rowBindings,
|
|
17808
18003
|
index: n.index,
|
|
17809
18004
|
key: n.key,
|
|
17810
18005
|
markerId: n.markerId,
|
|
@@ -17824,7 +18019,7 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx, options)
|
|
|
17824
18019
|
descend({
|
|
17825
18020
|
...scope,
|
|
17826
18021
|
depth: scope.depth + 1,
|
|
17827
|
-
bindingScope: buildLoopRowScope(n.param,
|
|
18022
|
+
bindingScope: buildLoopRowScope(n.param, rowBindings, innerPreambleNames, n.index, scope.bindingScope)
|
|
17828
18023
|
});
|
|
17829
18024
|
}
|
|
17830
18025
|
}
|
|
@@ -18210,9 +18405,12 @@ function collectFromElement(element, ctx, insideConditional = false) {
|
|
|
18210
18405
|
}
|
|
18211
18406
|
function collectBranchReactiveAttrs(node, ctx) {
|
|
18212
18407
|
const attrs = [];
|
|
18213
|
-
walkIR(node,
|
|
18408
|
+
walkIR(node, [], {
|
|
18214
18409
|
...stopAt("conditional", "ifStatement", "loop"),
|
|
18215
|
-
|
|
18410
|
+
component: ({ node: c, scope, descend }) => {
|
|
18411
|
+
descend(c.slotId ? [...scope, c.slotId] : scope);
|
|
18412
|
+
},
|
|
18413
|
+
element: ({ node: el, scope, descend }) => {
|
|
18216
18414
|
if (!el.slotId) {
|
|
18217
18415
|
descend();
|
|
18218
18416
|
return;
|
|
@@ -18230,6 +18428,7 @@ function collectBranchReactiveAttrs(node, ctx) {
|
|
|
18230
18428
|
continue;
|
|
18231
18429
|
attrs.push({
|
|
18232
18430
|
slotId: el.slotId,
|
|
18431
|
+
...el.slotId.startsWith("^") && { receiverSlotIds: scope },
|
|
18233
18432
|
attrName: attr.name,
|
|
18234
18433
|
expression: expanded.expr,
|
|
18235
18434
|
...pickAttrMetaFromIR(attr),
|
|
@@ -20358,7 +20557,8 @@ function buildChildRefBindings(refs, loopParam, loopParamBindings, loopIndex) {
|
|
|
20358
20557
|
return [];
|
|
20359
20558
|
return refs.map((r) => ({
|
|
20360
20559
|
childSlotId: r.childSlotId,
|
|
20361
|
-
callback: wrapLoopParamAsAccessor(r.callback, loopParam, loopParamBindings, loopIndex)
|
|
20560
|
+
callback: wrapLoopParamAsAccessor(r.callback, loopParam, loopParamBindings, loopIndex),
|
|
20561
|
+
...r.ssrPortalOwner && { ssrPortalOwner: true }
|
|
20362
20562
|
}));
|
|
20363
20563
|
}
|
|
20364
20564
|
function buildStaticChildRefBindings(refs) {
|
|
@@ -20366,7 +20566,8 @@ function buildStaticChildRefBindings(refs) {
|
|
|
20366
20566
|
return [];
|
|
20367
20567
|
return refs.map((r) => ({
|
|
20368
20568
|
childSlotId: r.childSlotId,
|
|
20369
|
-
callback: r.callback
|
|
20569
|
+
callback: r.callback,
|
|
20570
|
+
...r.ssrPortalOwner && { ssrPortalOwner: true }
|
|
20370
20571
|
}));
|
|
20371
20572
|
}
|
|
20372
20573
|
function exprRefsLoopBinding(freeIds, loop) {
|
|
@@ -20382,7 +20583,8 @@ function exprRefsLoopBinding(freeIds, loop) {
|
|
|
20382
20583
|
function destructureLoopParam(param, paramBindings) {
|
|
20383
20584
|
if (param.startsWith("[") || param.startsWith("{")) {
|
|
20384
20585
|
if (paramBindings && paramBindings.length > 0) {
|
|
20385
|
-
|
|
20586
|
+
const accessor = paramBindings[0].accessor;
|
|
20587
|
+
return { head: accessor ? accessor.replace(/\(\)$/, "") : "__bfItem", unwrap: "" };
|
|
20386
20588
|
}
|
|
20387
20589
|
return {
|
|
20388
20590
|
head: "__bfItem",
|
|
@@ -20617,7 +20819,9 @@ function buildBranchInnerLoopsPlan(args) {
|
|
|
20617
20819
|
if (!inner.template)
|
|
20618
20820
|
continue;
|
|
20619
20821
|
const wrapInner = (expr) => wrapLoopParamAsAccessor(expr, inner.param, inner.paramBindings, inner.index);
|
|
20620
|
-
const
|
|
20822
|
+
const innerShadowed = rowBoundNames(inner);
|
|
20823
|
+
const wrapOuterRow = (expr, shadowed) => wrapOuter(expr, unionNames(innerShadowed, shadowed));
|
|
20824
|
+
const wrapBoth = (expr, shadowed) => wrapLoopParamAsAccessor(wrapOuterRow(expr, shadowed), inner.param, inner.paramBindings, inner.index, shadowed);
|
|
20621
20825
|
const csl = inner.containerSlotId;
|
|
20622
20826
|
const containerExpr = csl ? `(${scopeVar}.querySelector('[bf="${csl}"]') ?? ${scopeVar}.querySelector(\`[${BF_HOST2}="\${__scopeId}"][${BF_AT2}="${csl}"]\`) ?? ${scopeVar})` : `findCondContainer(${scopeVar}, '${condSlotId}')`;
|
|
20623
20827
|
const { head: paramHead, unwrap: paramUnwrap } = destructureLoopParam(inner.param, inner.paramBindings);
|
|
@@ -20796,7 +21000,7 @@ function buildLoopChildArmPlan(args) {
|
|
|
20796
21000
|
// src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts
|
|
20797
21001
|
function buildReactiveEffectsPlan(args) {
|
|
20798
21002
|
const { attrs, texts, conditionals, loopParam, loopParamBindings, loopIndex, profileComponentName } = args;
|
|
20799
|
-
const wrap = (expr) => wrapLoopParamAsAccessor(expr, loopParam, loopParamBindings, loopIndex);
|
|
21003
|
+
const wrap = (expr, shadowed) => wrapLoopParamAsAccessor(expr, loopParam, loopParamBindings, loopIndex, shadowed);
|
|
20800
21004
|
const attrsBySlot = new Map;
|
|
20801
21005
|
for (const attr of attrs) {
|
|
20802
21006
|
let bucket = attrsBySlot.get(attr.childSlotId);
|
|
@@ -21601,8 +21805,8 @@ function wrapAttrValueExpression2(value, wrap) {
|
|
|
21601
21805
|
}
|
|
21602
21806
|
}
|
|
21603
21807
|
function buildInnerLoopsPlan(args) {
|
|
21604
|
-
const { levels, parentElVar, outerLoopParam, outerLoopParamBindings, outerLoopIndex } = args;
|
|
21605
|
-
const wrapOuter = outerLoopParam ? (expr) => wrapLoopParamAsAccessor(expr, outerLoopParam, outerLoopParamBindings, outerLoopIndex) : (expr) => expr;
|
|
21808
|
+
const { levels, parentElVar, outerLoopParam, outerLoopParamBindings, outerLoopIndex, rowHasPortal } = args;
|
|
21809
|
+
const wrapOuter = args.wrapOuter ?? (outerLoopParam ? (expr, shadowed) => wrapLoopParamAsAccessor(expr, outerLoopParam, outerLoopParamBindings, outerLoopIndex, shadowed) : (expr) => expr);
|
|
21606
21810
|
const plan = [];
|
|
21607
21811
|
let i = 0;
|
|
21608
21812
|
while (i < levels.length) {
|
|
@@ -21623,7 +21827,7 @@ function buildInnerLoopsPlan(args) {
|
|
|
21623
21827
|
j++;
|
|
21624
21828
|
}
|
|
21625
21829
|
const uidSuffix = `${inner.depth}_${i}`;
|
|
21626
|
-
const containerExpr = inner.containerSlotId ?
|
|
21830
|
+
const containerExpr = inner.containerSlotId ? `${rowHasPortal ? "qsaItem" : "qsa"}(${parentElVar}, '[bf="${inner.containerSlotId}"]')` : parentElVar;
|
|
21627
21831
|
const emit = buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, outerLoopParamBindings, outerLoopIndex);
|
|
21628
21832
|
const arrayExpr = wrapOuter(inner.array);
|
|
21629
21833
|
const childLevelsPlan = childLevels.length > 0 ? buildInnerLoopsPlan({
|
|
@@ -21631,7 +21835,8 @@ function buildInnerLoopsPlan(args) {
|
|
|
21631
21835
|
parentElVar: `__innerEl${uidSuffix}`,
|
|
21632
21836
|
outerLoopParam: inner.param,
|
|
21633
21837
|
outerLoopParamBindings: inner.paramBindings,
|
|
21634
|
-
outerLoopIndex: inner.index
|
|
21838
|
+
outerLoopIndex: inner.index,
|
|
21839
|
+
wrapOuter: (expr, shadowed) => wrapLoopParamAsAccessor(wrapOuter(expr, unionNames(rowBoundNames(inner), shadowed)), inner.param, inner.paramBindings, inner.index, shadowed)
|
|
21635
21840
|
}) : [];
|
|
21636
21841
|
plan.push({
|
|
21637
21842
|
uidSuffix,
|
|
@@ -21654,7 +21859,9 @@ function buildInnerLoopsPlan(args) {
|
|
|
21654
21859
|
}
|
|
21655
21860
|
function buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, outerLoopParamBindings, outerLoopIndex) {
|
|
21656
21861
|
const wrapInner = (expr) => wrapLoopParamAsAccessor(expr, inner.param, inner.paramBindings, inner.index);
|
|
21657
|
-
const
|
|
21862
|
+
const innerShadowed = rowBoundNames(inner);
|
|
21863
|
+
const wrapOuterRow = (expr, shadowed) => wrapOuter(expr, unionNames(innerShadowed, shadowed));
|
|
21864
|
+
const wrapBoth = (expr, shadowed) => wrapLoopParamAsAccessor(wrapOuterRow(expr, shadowed), inner.param, inner.paramBindings, inner.index, shadowed);
|
|
21658
21865
|
const { head: paramHead, unwrap: paramUnwrap } = destructureLoopParam(inner.param, inner.paramBindings);
|
|
21659
21866
|
const wrappedKey = inner.key ? wrapLoopParamAsAccessor(inner.key, inner.param, inner.paramBindings, inner.index) : null;
|
|
21660
21867
|
const wrapIRNode = (node) => {
|
|
@@ -21687,11 +21894,11 @@ function buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, o
|
|
|
21687
21894
|
}));
|
|
21688
21895
|
const reactiveTexts = inner.bindings.reactiveTexts.map((text) => ({
|
|
21689
21896
|
slotId: text.slotId,
|
|
21690
|
-
wrappedExpression: wrapLoopParamAsAccessor(
|
|
21897
|
+
wrappedExpression: wrapLoopParamAsAccessor(wrapOuterRow(text.expression), inner.param, inner.paramBindings, inner.index),
|
|
21691
21898
|
insideConditional: !!text.insideConditional
|
|
21692
21899
|
}));
|
|
21693
21900
|
const reactiveAttrs = inner.bindings.reactiveAttrs.map((attr) => {
|
|
21694
|
-
const wrapped = wrapLoopParamAsAccessor(
|
|
21901
|
+
const wrapped = wrapLoopParamAsAccessor(wrapOuterRow(attr.expression), inner.param, inner.paramBindings, inner.index);
|
|
21695
21902
|
return {
|
|
21696
21903
|
slotId: attr.childSlotId,
|
|
21697
21904
|
attrName: attr.attrName,
|
|
@@ -21707,11 +21914,11 @@ function buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, o
|
|
|
21707
21914
|
preludeStatements.push(paramUnwrap);
|
|
21708
21915
|
if (inner.preamble) {
|
|
21709
21916
|
const leafLoopParams = outerLoopParam ? [
|
|
21710
|
-
{ param: outerLoopParam, bindings: outerLoopParamBindings, index: outerLoopIndex },
|
|
21917
|
+
{ param: outerLoopParam, bindings: outerLoopParamBindings, index: outerLoopIndex, shadowed: innerShadowed },
|
|
21711
21918
|
{ param: inner.param, bindings: inner.paramBindings, index: inner.index }
|
|
21712
21919
|
] : [{ param: inner.param, bindings: inner.paramBindings, index: inner.index }];
|
|
21713
21920
|
preludeStatements.push(renderPreamble(inner.preamble, {
|
|
21714
|
-
transformJs: (t) => wrapInner(
|
|
21921
|
+
transformJs: (t) => wrapInner(wrapOuterRow(t)),
|
|
21715
21922
|
renderLeaf: (ir) => irToHtmlTemplate(ir, undefined, 1, leafLoopParams, undefined)
|
|
21716
21923
|
}));
|
|
21717
21924
|
}
|
|
@@ -21771,7 +21978,8 @@ function buildTopLevelCompositePlan(elem, profileComponentName) {
|
|
|
21771
21978
|
parentElVar: "__el",
|
|
21772
21979
|
outerLoopParam: elem.param,
|
|
21773
21980
|
outerLoopParamBindings: elem.paramBindings,
|
|
21774
|
-
outerLoopIndex: elem.index
|
|
21981
|
+
outerLoopIndex: elem.index,
|
|
21982
|
+
rowHasPortal: elem.bindings.refs.some((r) => r.ssrPortalOwner)
|
|
21775
21983
|
}),
|
|
21776
21984
|
loopParam: elem.param,
|
|
21777
21985
|
loopParamBindings: elem.paramBindings,
|
|
@@ -21824,7 +22032,8 @@ function buildBranchCompositePlan(loop, cv, profileComponentName) {
|
|
|
21824
22032
|
parentElVar: "__el",
|
|
21825
22033
|
outerLoopParam: loop.param,
|
|
21826
22034
|
outerLoopParamBindings: loop.paramBindings,
|
|
21827
|
-
outerLoopIndex: loop.index
|
|
22035
|
+
outerLoopIndex: loop.index,
|
|
22036
|
+
rowHasPortal: loop.bindings.refs.some((r) => r.ssrPortalOwner)
|
|
21828
22037
|
}),
|
|
21829
22038
|
loopParam: loop.param,
|
|
21830
22039
|
loopParamBindings: loop.paramBindings,
|
|
@@ -22159,7 +22368,8 @@ function emitRestAttrApplications(lines, ctx) {
|
|
|
22159
22368
|
for (const elem of ctx.restAttrElements) {
|
|
22160
22369
|
const v = varSlotId(elem.slotId);
|
|
22161
22370
|
const excludeKeys = JSON.stringify(elem.excludeKeys);
|
|
22162
|
-
|
|
22371
|
+
const turnSite = ctx.profile ? `, ${JSON.stringify(`${ctx.componentName}#handler:${elem.slotId}`)}` : "";
|
|
22372
|
+
lines.push(` if (_${v}) applyRestAttrs(_${v}, ${elem.source}, ${excludeKeys}${turnSite})`);
|
|
22163
22373
|
}
|
|
22164
22374
|
lines.push("");
|
|
22165
22375
|
}
|
|
@@ -23229,14 +23439,16 @@ function stringifyCompositeLoop(lines, plan) {
|
|
|
23229
23439
|
singleRootLayout: "multiline",
|
|
23230
23440
|
mountRow: true
|
|
23231
23441
|
});
|
|
23232
|
-
|
|
23442
|
+
emitRowPortalClaim(lines, childRefs, { indent: bodyIndent, containerVar });
|
|
23443
|
+
const itemLookup = bodyIsMultiRoot || rowPortalSlotIds(childRefs).length > 0;
|
|
23444
|
+
emitComponentAndEventSetup(lines, bodyIndent, "__el", compsArr, eventsArr, loopParam, loopParamBindings, itemLookup, loopIndex);
|
|
23233
23445
|
if (innerLoops.length > 0) {
|
|
23234
23446
|
stringifyInnerLoops(lines, innerLoops, bodyIndent, pc);
|
|
23235
23447
|
}
|
|
23236
23448
|
if (reactiveEffects) {
|
|
23237
|
-
stringifyReactiveEffects(lines, reactiveEffects, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot });
|
|
23449
|
+
stringifyReactiveEffects(lines, reactiveEffects, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot: itemLookup });
|
|
23238
23450
|
}
|
|
23239
|
-
emitLoopChildRefs(lines, childRefs, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot });
|
|
23451
|
+
emitLoopChildRefs(lines, childRefs, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot: itemLookup, containerVar });
|
|
23240
23452
|
lines.push(`${bodyIndent}return __el`);
|
|
23241
23453
|
const loopBfId = profileLoopId ? `, ${JSON.stringify(profileLoopId)}` : "";
|
|
23242
23454
|
if (branchClearChildren) {
|
|
@@ -23467,16 +23679,30 @@ function seedDiffersExpr(target, a) {
|
|
|
23467
23679
|
function emitLoopChildRefs(lines, refs, opts) {
|
|
23468
23680
|
if (refs.length === 0)
|
|
23469
23681
|
return;
|
|
23470
|
-
const { indent, elVar, bodyIsMultiRoot, elementIndexBySlot } = opts;
|
|
23471
|
-
const lookup = bodyIsMultiRoot ? "qsaItem" : "qsa";
|
|
23682
|
+
const { indent, elVar, bodyIsMultiRoot, elementIndexBySlot, containerVar } = opts;
|
|
23472
23683
|
for (const ref of refs) {
|
|
23684
|
+
const lookup = bodyIsMultiRoot || ref.ssrPortalOwner ? "qsaItem" : "qsa";
|
|
23473
23685
|
const varName = `__rf_${varSlotId(ref.childSlotId)}`;
|
|
23474
23686
|
const pIdx = elementIndexBySlot?.get(ref.childSlotId);
|
|
23475
23687
|
const lookupExpr = pIdx !== undefined ? `__p ? __p[${pIdx}] : ${lookup}(${elVar}, '[bf="${ref.childSlotId}"]')` : `${lookup}(${elVar}, '[bf="${ref.childSlotId}"]')`;
|
|
23476
23688
|
lines.push(`${indent}{ const ${varName} = ${lookupExpr}`);
|
|
23477
|
-
|
|
23689
|
+
if (ref.ssrPortalOwner && containerVar) {
|
|
23690
|
+
lines.push(`${indent}if (${varName}) { ${emitRefCall(ref.callback, varName, true)}; adoptRowPortal(${elVar}, ${varName}, ${containerVar}) } }`);
|
|
23691
|
+
} else {
|
|
23692
|
+
lines.push(`${indent}if (${varName}) ${emitRefCall(ref.callback, varName)} }`);
|
|
23693
|
+
}
|
|
23478
23694
|
}
|
|
23479
23695
|
}
|
|
23696
|
+
function rowPortalSlotIds(refs) {
|
|
23697
|
+
return refs.filter((r) => r.ssrPortalOwner).map((r) => r.childSlotId);
|
|
23698
|
+
}
|
|
23699
|
+
function emitRowPortalClaim(lines, refs, opts) {
|
|
23700
|
+
const slots = rowPortalSlotIds(refs);
|
|
23701
|
+
if (slots.length === 0)
|
|
23702
|
+
return;
|
|
23703
|
+
const claim = `claimRowPortals(${opts.rowVar ?? "__existing"}, __scopeId, ${JSON.stringify(slots)}, ${opts.containerVar})`;
|
|
23704
|
+
lines.push(opts.rowVar ? `${opts.indent}${claim}` : `${opts.indent}if (__existing) ${claim}`);
|
|
23705
|
+
}
|
|
23480
23706
|
function stringifyLoop(lines, plan) {
|
|
23481
23707
|
switch (plan.kind) {
|
|
23482
23708
|
case "static":
|
|
@@ -23586,6 +23812,8 @@ function stringifyPlainLoop(lines, plan, topIndent = " ") {
|
|
|
23586
23812
|
singleRootLayout: "inline"
|
|
23587
23813
|
});
|
|
23588
23814
|
}
|
|
23815
|
+
emitRowPortalClaim(lines, childRefs, { indent: bodyIndent, containerVar });
|
|
23816
|
+
const itemLookup = bodyIsMultiRoot || rowPortalSlotIds(childRefs).length > 0;
|
|
23589
23817
|
let pathPlan = null;
|
|
23590
23818
|
if (hoistedTpl && plan.skeletonPaths) {
|
|
23591
23819
|
const elementSlotIds = [
|
|
@@ -23612,14 +23840,14 @@ function stringifyPlainLoop(lines, plan, topIndent = " ") {
|
|
|
23612
23840
|
stringifyReactiveEffects(lines, reactiveEffects, {
|
|
23613
23841
|
indent: bodyIndent,
|
|
23614
23842
|
elVar: "__el",
|
|
23615
|
-
bodyIsMultiRoot,
|
|
23843
|
+
bodyIsMultiRoot: itemLookup,
|
|
23616
23844
|
elementIndexBySlot: pathPlan?.elementIndexBySlot,
|
|
23617
23845
|
textClaimPathExprs,
|
|
23618
23846
|
preambleRegions,
|
|
23619
23847
|
mapPreambleWrapped
|
|
23620
23848
|
});
|
|
23621
23849
|
}
|
|
23622
|
-
emitLoopChildRefs(lines, childRefs, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot, elementIndexBySlot: pathPlan?.elementIndexBySlot });
|
|
23850
|
+
emitLoopChildRefs(lines, childRefs, { indent: bodyIndent, elVar: "__el", bodyIsMultiRoot: itemLookup, elementIndexBySlot: pathPlan?.elementIndexBySlot, containerVar });
|
|
23623
23851
|
lines.push(`${bodyIndent}return __el`);
|
|
23624
23852
|
lines.push(`${topIndent}}, '${markerId}'${loopBfId})`);
|
|
23625
23853
|
}
|
|
@@ -23715,12 +23943,14 @@ function stringifyStaticLoop(lines, plan) {
|
|
|
23715
23943
|
lines.push(` }`);
|
|
23716
23944
|
}
|
|
23717
23945
|
lines.push(` if (__iterEl) {`);
|
|
23946
|
+
emitRowPortalClaim(lines, childRefs, { indent: " ", containerVar, rowVar: "__iterEl" });
|
|
23947
|
+
const rowHasPortal = rowPortalSlotIds(childRefs).length > 0;
|
|
23718
23948
|
if (attrsBySlot.length > 0)
|
|
23719
23949
|
lines.push(` ${DEDUP_STORE_DECL}`);
|
|
23720
23950
|
let ordinal = 0;
|
|
23721
23951
|
for (const [slotId, attrs] of attrsBySlot) {
|
|
23722
23952
|
const varName = `__t_${varSlotId(slotId)}`;
|
|
23723
|
-
lines.push(` const ${varName} = qsa(__iterEl, '[bf="${slotId}"]')`);
|
|
23953
|
+
lines.push(` const ${varName} = ${rowHasPortal ? "qsaItem" : "qsa"}(__iterEl, '[bf="${slotId}"]')`);
|
|
23724
23954
|
lines.push(` if (${varName}) {`);
|
|
23725
23955
|
for (const attr of attrs) {
|
|
23726
23956
|
lines.push(` createEffect(() => {`);
|
|
@@ -23739,7 +23969,7 @@ function stringifyStaticLoop(lines, plan) {
|
|
|
23739
23969
|
lines.push(` createEffect(() => { ${writer}('${text.slotId}', String(${text.expression})) }${profileBindingId(pc, text.slotId)})`);
|
|
23740
23970
|
}
|
|
23741
23971
|
}
|
|
23742
|
-
emitLoopChildRefs(lines, childRefs, { indent: " ", elVar: "__iterEl", bodyIsMultiRoot:
|
|
23972
|
+
emitLoopChildRefs(lines, childRefs, { indent: " ", elVar: "__iterEl", bodyIsMultiRoot: rowHasPortal, containerVar });
|
|
23743
23973
|
lines.push(` }`);
|
|
23744
23974
|
lines.push(` })`);
|
|
23745
23975
|
lines.push(` }`);
|
|
@@ -23929,6 +24159,7 @@ function buildDynamicLoopDelegationPlan(elem, profileComponentName, ownHandlers)
|
|
|
23929
24159
|
events: elem.bindings.events,
|
|
23930
24160
|
profileComponentName,
|
|
23931
24161
|
ownHandlers,
|
|
24162
|
+
...hasRowPortalRef(elem) && { relayRowPortals: true },
|
|
23932
24163
|
itemLookup: buildKeyedOrIndexLookup({
|
|
23933
24164
|
array: buildChainedArrayExpr(elem),
|
|
23934
24165
|
param: elem.param,
|
|
@@ -23948,6 +24179,7 @@ function buildBranchLoopDelegationPlan(loop, cv, profileComponentName) {
|
|
|
23948
24179
|
containerVar: `__loop_${cv}`,
|
|
23949
24180
|
events: loop.bindings.events,
|
|
23950
24181
|
profileComponentName,
|
|
24182
|
+
...hasRowPortalRef(loop) && { relayRowPortals: true },
|
|
23951
24183
|
itemLookup: buildKeyedOrIndexLookup({
|
|
23952
24184
|
array: buildChainedArrayExpr(loop),
|
|
23953
24185
|
param: loop.param,
|
|
@@ -23962,6 +24194,9 @@ function buildBranchLoopDelegationPlan(loop, cv, profileComponentName) {
|
|
|
23962
24194
|
};
|
|
23963
24195
|
}
|
|
23964
24196
|
function buildStaticArrayDelegationPlan(elem, profileComponentName, ownHandlers) {
|
|
24197
|
+
if (hasRowPortalRef(elem) && elem.key !== null) {
|
|
24198
|
+
return buildDynamicLoopDelegationPlan(elem, profileComponentName, ownHandlers);
|
|
24199
|
+
}
|
|
23965
24200
|
return {
|
|
23966
24201
|
kind: "event-delegation",
|
|
23967
24202
|
containerVar: `_${varSlotId(elem.slotId)}`,
|
|
@@ -23981,6 +24216,9 @@ function buildStaticArrayDelegationPlan(elem, profileComponentName, ownHandlers)
|
|
|
23981
24216
|
}
|
|
23982
24217
|
};
|
|
23983
24218
|
}
|
|
24219
|
+
function hasRowPortalRef(loop) {
|
|
24220
|
+
return loop.bindings.refs.some((r) => r.ssrPortalOwner);
|
|
24221
|
+
}
|
|
23984
24222
|
function buildKeyedOrIndexLookup(args) {
|
|
23985
24223
|
const hasBindings = (args.paramBindings?.length ?? 0) > 0;
|
|
23986
24224
|
if (args.key !== null) {
|
|
@@ -24138,7 +24376,7 @@ function preambleLineForHandler(mapPreamble, declaredNames, handler) {
|
|
|
24138
24376
|
return declaredNames.some((name) => free.has(name)) ? mapPreamble : null;
|
|
24139
24377
|
}
|
|
24140
24378
|
function stringifyEventDelegation(lines, plan) {
|
|
24141
|
-
const { containerVar, events, itemLookup, profileComponentName, ownHandlers } = plan;
|
|
24379
|
+
const { containerVar, events, itemLookup, profileComponentName, ownHandlers, relayRowPortals } = plan;
|
|
24142
24380
|
const eventsByName = new Map;
|
|
24143
24381
|
for (const ev of events) {
|
|
24144
24382
|
if (!eventsByName.has(ev.eventName))
|
|
@@ -24151,16 +24389,19 @@ function stringifyEventDelegation(lines, plan) {
|
|
|
24151
24389
|
const domEventName = toDomEventName(eventName);
|
|
24152
24390
|
const ownHandler = ownHandlers?.get(domEventName);
|
|
24153
24391
|
const ownHandlerCall = ownHandler ? withTurn(`(${ownHandler.handler.trim()})(__bfEvt)`, profileComponentName, ownHandler.slotId, ownHandler.eventName) : null;
|
|
24154
|
-
|
|
24155
|
-
|
|
24392
|
+
const listenedName = useCapture ? eventName : domEventName;
|
|
24393
|
+
if (relayRowPortals) {
|
|
24394
|
+
lines.push(` if (${containerVar}) {`);
|
|
24395
|
+
lines.push(` const __bfDl = (__bfEvt) => {`);
|
|
24156
24396
|
} else {
|
|
24157
|
-
lines.push(` if (${containerVar}) ${containerVar}.addEventListener('${
|
|
24397
|
+
lines.push(` if (${containerVar}) ${containerVar}.addEventListener('${listenedName}', (__bfEvt) => {`);
|
|
24158
24398
|
}
|
|
24159
24399
|
lines.push(` const target = __bfEvt.target`);
|
|
24160
24400
|
for (const ev of evs) {
|
|
24161
24401
|
const childVar = varSlotId(ev.childSlotId);
|
|
24162
24402
|
lines.push(` const ${childVar}El = target.closest('[bf="${ev.childSlotId}"]')`);
|
|
24163
|
-
|
|
24403
|
+
const inContainer = relayRowPortals ? `(${containerVar}.contains(${childVar}El) || isRowPortalOf(${childVar}El, ${containerVar}))` : `${containerVar}.contains(${childVar}El)`;
|
|
24404
|
+
lines.push(` if (${childVar}El && ${inContainer}) {`);
|
|
24164
24405
|
const handlerCall = withTurn(`(${ev.handler.trim()})(__bfEvt)`, profileComponentName, ev.childSlotId, ev.eventName);
|
|
24165
24406
|
switch (itemLookup.kind) {
|
|
24166
24407
|
case "keyed":
|
|
@@ -24182,7 +24423,13 @@ function stringifyEventDelegation(lines, plan) {
|
|
|
24182
24423
|
if (ownHandlerCall) {
|
|
24183
24424
|
lines.push(` if (!__bfEvt.cancelBubble) { ${ownHandlerCall} }`);
|
|
24184
24425
|
}
|
|
24185
|
-
if (
|
|
24426
|
+
if (relayRowPortals) {
|
|
24427
|
+
const captureArg = useCapture ? ", true" : "";
|
|
24428
|
+
lines.push(` }`);
|
|
24429
|
+
lines.push(` ${containerVar}.addEventListener('${listenedName}', __bfDl${captureArg})`);
|
|
24430
|
+
lines.push(` relayRowPortalEvents(${containerVar}, '${listenedName}', __bfDl${captureArg})`);
|
|
24431
|
+
lines.push(` }`);
|
|
24432
|
+
} else if (useCapture) {
|
|
24186
24433
|
lines.push(` }, true)`);
|
|
24187
24434
|
} else {
|
|
24188
24435
|
lines.push(` })`);
|
|
@@ -24420,16 +24667,18 @@ function emitPlain(lines, plan) {
|
|
|
24420
24667
|
indent: " ",
|
|
24421
24668
|
singleRootLayout: "inline"
|
|
24422
24669
|
});
|
|
24670
|
+
emitRowPortalClaim(lines, childRefs, { indent: " ", containerVar });
|
|
24671
|
+
const itemLookup = bodyIsMultiRoot || rowPortalSlotIds(childRefs).length > 0;
|
|
24423
24672
|
if (reactiveEffects !== null || preambleRegions.length > 0) {
|
|
24424
24673
|
stringifyReactiveEffects(lines, reactiveEffects, {
|
|
24425
24674
|
indent: " ",
|
|
24426
24675
|
elVar: "__el",
|
|
24427
|
-
bodyIsMultiRoot,
|
|
24676
|
+
bodyIsMultiRoot: itemLookup,
|
|
24428
24677
|
preambleRegions,
|
|
24429
24678
|
mapPreambleWrapped
|
|
24430
24679
|
});
|
|
24431
24680
|
}
|
|
24432
|
-
emitLoopChildRefs(lines, childRefs, { indent: " ", elVar: "__el", bodyIsMultiRoot });
|
|
24681
|
+
emitLoopChildRefs(lines, childRefs, { indent: " ", elVar: "__el", bodyIsMultiRoot: itemLookup, containerVar });
|
|
24433
24682
|
lines.push(` return __el`);
|
|
24434
24683
|
lines.push(` }, '${markerId}'${loopBfId})`);
|
|
24435
24684
|
}
|
|
@@ -24504,7 +24753,9 @@ function emitArmBody(lines, body, mode, indent, profileComponentName) {
|
|
|
24504
24753
|
for (const [slotId, attrs] of attrsBySlot) {
|
|
24505
24754
|
const v = varSlotId(slotId);
|
|
24506
24755
|
const elVar = `__ra_${v}`;
|
|
24507
|
-
|
|
24756
|
+
const receivers = attrs[0].receiverSlotIds;
|
|
24757
|
+
const receiverArg = receivers && receivers.length > 0 ? `, ${JSON.stringify(receivers)}` : "";
|
|
24758
|
+
lines.push(`${indent}{ const ${elVar} = qsa(__branchScope, '[bf="${slotId}"]'${receiverArg})`);
|
|
24508
24759
|
lines.push(`${indent}${DEDUP_STORE_DECL}`);
|
|
24509
24760
|
lines.push(`${indent}if (${elVar}) {`);
|
|
24510
24761
|
let ordinal = 0;
|
|
@@ -25286,7 +25537,8 @@ function generateTemplateOnlyMount(ir, ctx) {
|
|
|
25286
25537
|
lines.push(`function ${initName}() {}`);
|
|
25287
25538
|
lines.push("");
|
|
25288
25539
|
const nameField = registryKey !== name ? `, name: '${name}'` : "";
|
|
25289
|
-
const
|
|
25540
|
+
const transparentFlag = isTransparentFragmentRoot(ir.root) ? ["transparent: true"] : [];
|
|
25541
|
+
const scopeFlags = [...componentDefScopeFlags(ir.root), ...transparentFlag].map((f) => `, ${f}`).join("");
|
|
25290
25542
|
lines.push(`hydrate('${registryKey}', { init: ${initName}, template: (${PROPS_PARAM}) => \`${templateHtml}\`${scopeFlags}${nameField} })`);
|
|
25291
25543
|
lines.push(`export function ${name}(${PROPS_PARAM}, __bfKey) { return createComponent('${registryKey}', ${PROPS_PARAM}, __bfKey) }`);
|
|
25292
25544
|
const generatedCode = lines.join(`
|
|
@@ -28684,6 +28936,17 @@ function isStringTypedOperand(expr, isStringName) {
|
|
|
28684
28936
|
function isStringConcatBinary(op, left, right, isStringName) {
|
|
28685
28937
|
return op === "+" && (isStringTypedOperand(left, isStringName) || isStringTypedOperand(right, isStringName));
|
|
28686
28938
|
}
|
|
28939
|
+
function isNumericArithmeticResult(expr, isStringName) {
|
|
28940
|
+
if (!expr)
|
|
28941
|
+
return false;
|
|
28942
|
+
if (expr.kind === "unary")
|
|
28943
|
+
return expr.op === "-";
|
|
28944
|
+
if (expr.kind !== "binary")
|
|
28945
|
+
return false;
|
|
28946
|
+
if (expr.op === "+")
|
|
28947
|
+
return !isStringConcatBinary(expr.op, expr.left, expr.right, isStringName);
|
|
28948
|
+
return expr.op === "-" || expr.op === "*" || expr.op === "/" || expr.op === "%";
|
|
28949
|
+
}
|
|
28687
28950
|
function groupBinaryOperand(operand, emitted) {
|
|
28688
28951
|
return operand.kind === "binary" || operand.kind === "logical" || operand.kind === "conditional" ? `(${emitted})` : emitted;
|
|
28689
28952
|
}
|
|
@@ -28832,6 +29095,171 @@ function collectLoopBoundNames(ir) {
|
|
|
28832
29095
|
visit3(ir.root);
|
|
28833
29096
|
return names;
|
|
28834
29097
|
}
|
|
29098
|
+
// src/adapters/filter-capture-collisions.ts
|
|
29099
|
+
function filterCaptureCollisions(loop) {
|
|
29100
|
+
const filter = loop.filterPredicate;
|
|
29101
|
+
if (!filter?.predicate)
|
|
29102
|
+
return [];
|
|
29103
|
+
const free = freeIdentifiers(filter.predicate);
|
|
29104
|
+
if (!free)
|
|
29105
|
+
return [];
|
|
29106
|
+
free.delete(filter.param);
|
|
29107
|
+
const rowBound = new Set(loop.paramBindings && loop.paramBindings.length > 0 ? loop.paramBindings.map((b) => b.name) : [loop.param]);
|
|
29108
|
+
if (loop.index)
|
|
29109
|
+
rowBound.add(loop.index);
|
|
29110
|
+
return [...free].filter((name) => rowBound.has(name)).sort();
|
|
29111
|
+
}
|
|
29112
|
+
// src/adapters/template-name-collisions.ts
|
|
29113
|
+
function templateNameCollisionErrors(ir, propNames, ident, adapterName, componentName) {
|
|
29114
|
+
const { metadata } = ir;
|
|
29115
|
+
const rootNames = new Set([
|
|
29116
|
+
...propNames,
|
|
29117
|
+
...metadata.localConstants.map((c) => c.name),
|
|
29118
|
+
...metadata.localFunctions.map((f) => f.name),
|
|
29119
|
+
...metadata.signals.flatMap((s) => s.setter ? [s.getter, s.setter] : [s.getter]),
|
|
29120
|
+
...metadata.memos.map((m) => m.name)
|
|
29121
|
+
]);
|
|
29122
|
+
const errors = [];
|
|
29123
|
+
const reported = new Set;
|
|
29124
|
+
const check = (scope) => {
|
|
29125
|
+
const byTarget = new Map;
|
|
29126
|
+
for (const name of new Set([...rootNames, ...scope.boundNames()])) {
|
|
29127
|
+
const target = ident(name);
|
|
29128
|
+
const group = byTarget.get(target);
|
|
29129
|
+
if (group)
|
|
29130
|
+
group.push(name);
|
|
29131
|
+
else
|
|
29132
|
+
byTarget.set(target, [name]);
|
|
29133
|
+
}
|
|
29134
|
+
for (const [target, group] of byTarget) {
|
|
29135
|
+
if (group.length < 2)
|
|
29136
|
+
continue;
|
|
29137
|
+
const key = `${target}\x00${[...group].sort().join("\x00")}`;
|
|
29138
|
+
if (reported.has(key))
|
|
29139
|
+
continue;
|
|
29140
|
+
reported.add(key);
|
|
29141
|
+
const list = group.map((n) => `\`${n}\``).join(" and ");
|
|
29142
|
+
errors.push({
|
|
29143
|
+
code: "BF105",
|
|
29144
|
+
severity: "error",
|
|
29145
|
+
message: `${list} both become the ${adapterName} template variable \`${target}\`, so they would read the same value. ${adapterName} reserves some names and renames them, and the new name collides with another name in this component.`,
|
|
29146
|
+
loc: { file: `${componentName}.tsx`, start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
29147
|
+
suggestion: {
|
|
29148
|
+
message: `Rename one of ${list} so the two names stay distinct after the ${adapterName} renaming.`,
|
|
29149
|
+
escape: [{ kind: "rewrite" }]
|
|
29150
|
+
}
|
|
29151
|
+
});
|
|
29152
|
+
}
|
|
29153
|
+
};
|
|
29154
|
+
const visit3 = (node, scope) => {
|
|
29155
|
+
if (!node)
|
|
29156
|
+
return;
|
|
29157
|
+
switch (node.type) {
|
|
29158
|
+
case "element":
|
|
29159
|
+
case "component":
|
|
29160
|
+
case "fragment":
|
|
29161
|
+
case "provider":
|
|
29162
|
+
for (const child of node.children)
|
|
29163
|
+
visit3(child, scope);
|
|
29164
|
+
break;
|
|
29165
|
+
case "async":
|
|
29166
|
+
visit3(node.fallback, scope);
|
|
29167
|
+
for (const child of node.children)
|
|
29168
|
+
visit3(child, scope);
|
|
29169
|
+
break;
|
|
29170
|
+
case "loop": {
|
|
29171
|
+
if (node.filterPredicate)
|
|
29172
|
+
check(scope.enterCallback([node.filterPredicate.param]));
|
|
29173
|
+
const row = scope.enterLoopRow(node);
|
|
29174
|
+
check(row);
|
|
29175
|
+
for (const child of node.children)
|
|
29176
|
+
visit3(child, row);
|
|
29177
|
+
if (node.childComponent) {
|
|
29178
|
+
for (const child of node.childComponent.children)
|
|
29179
|
+
visit3(child, row);
|
|
29180
|
+
}
|
|
29181
|
+
for (const nested of node.nestedComponents ?? []) {
|
|
29182
|
+
for (const child of nested.children)
|
|
29183
|
+
visit3(child, row);
|
|
29184
|
+
}
|
|
29185
|
+
for (const seg of node.flatMapCallback?.segments ?? []) {
|
|
29186
|
+
if (seg.kind === "jsx")
|
|
29187
|
+
visit3(seg.ir, row);
|
|
29188
|
+
}
|
|
29189
|
+
for (const seg of node.preamble?.segments ?? []) {
|
|
29190
|
+
if (seg.kind === "jsx")
|
|
29191
|
+
visit3(seg.ir, row);
|
|
29192
|
+
}
|
|
29193
|
+
break;
|
|
29194
|
+
}
|
|
29195
|
+
case "conditional":
|
|
29196
|
+
visit3(node.whenTrue, scope);
|
|
29197
|
+
visit3(node.whenFalse, scope);
|
|
29198
|
+
break;
|
|
29199
|
+
case "if-statement":
|
|
29200
|
+
visit3(node.consequent, scope);
|
|
29201
|
+
if (node.alternate)
|
|
29202
|
+
visit3(node.alternate, scope);
|
|
29203
|
+
break;
|
|
29204
|
+
case "text":
|
|
29205
|
+
case "expression":
|
|
29206
|
+
case "slot":
|
|
29207
|
+
break;
|
|
29208
|
+
}
|
|
29209
|
+
};
|
|
29210
|
+
check(BindingScope.EMPTY);
|
|
29211
|
+
visit3(ir.root, BindingScope.EMPTY);
|
|
29212
|
+
return errors;
|
|
29213
|
+
}
|
|
29214
|
+
// src/adapters/boolean-result.ts
|
|
29215
|
+
var COMPARISON_OPS = new Set([
|
|
29216
|
+
"<",
|
|
29217
|
+
">",
|
|
29218
|
+
"<=",
|
|
29219
|
+
">=",
|
|
29220
|
+
"==",
|
|
29221
|
+
"===",
|
|
29222
|
+
"!=",
|
|
29223
|
+
"!=="
|
|
29224
|
+
]);
|
|
29225
|
+
function isBooleanResultParsed(node) {
|
|
29226
|
+
switch (node.kind) {
|
|
29227
|
+
case "literal":
|
|
29228
|
+
return node.literalType === "boolean";
|
|
29229
|
+
case "binary":
|
|
29230
|
+
return COMPARISON_OPS.has(node.op);
|
|
29231
|
+
case "unary":
|
|
29232
|
+
return node.op === "!";
|
|
29233
|
+
case "logical":
|
|
29234
|
+
return isBooleanResultParsed(node.left) && isBooleanResultParsed(node.right);
|
|
29235
|
+
case "conditional":
|
|
29236
|
+
return isBooleanResultParsed(node.consequent) && isBooleanResultParsed(node.alternate);
|
|
29237
|
+
default:
|
|
29238
|
+
return false;
|
|
29239
|
+
}
|
|
29240
|
+
}
|
|
29241
|
+
function stringifyBooleanTernaryBranches(node) {
|
|
29242
|
+
if (node.kind !== "conditional" || isBooleanResultParsed(node))
|
|
29243
|
+
return node;
|
|
29244
|
+
return {
|
|
29245
|
+
...node,
|
|
29246
|
+
consequent: stringifyBooleanBranch(node.consequent),
|
|
29247
|
+
alternate: stringifyBooleanBranch(node.alternate)
|
|
29248
|
+
};
|
|
29249
|
+
}
|
|
29250
|
+
function stringifyBooleanBranch(branch) {
|
|
29251
|
+
if (!isBooleanResultParsed(branch))
|
|
29252
|
+
return stringifyBooleanTernaryBranches(branch);
|
|
29253
|
+
if (branch.kind === "literal") {
|
|
29254
|
+
return { kind: "literal", value: String(branch.value), literalType: "string" };
|
|
29255
|
+
}
|
|
29256
|
+
return {
|
|
29257
|
+
kind: "conditional",
|
|
29258
|
+
test: branch,
|
|
29259
|
+
consequent: { kind: "literal", value: "true", literalType: "string" },
|
|
29260
|
+
alternate: { kind: "literal", value: "false", literalType: "string" }
|
|
29261
|
+
};
|
|
29262
|
+
}
|
|
28835
29263
|
// src/static-literal.ts
|
|
28836
29264
|
function evaluateStaticLiteral(expr, bindings) {
|
|
28837
29265
|
switch (expr.kind) {
|
|
@@ -28967,8 +29395,11 @@ function nullableSignalAttrGetter(parsed, nullable) {
|
|
|
28967
29395
|
return getter !== null && nullable.has(getter) ? getter : null;
|
|
28968
29396
|
}
|
|
28969
29397
|
function collectNullishAttrContext(ir) {
|
|
29398
|
+
const signals = ir.metadata.signals ?? [];
|
|
28970
29399
|
return {
|
|
28971
29400
|
nullableSignals: collectNullableSignalGetters(ir),
|
|
29401
|
+
nullSeededSignals: new Set(signals.filter((s) => s.parsed?.kind === "literal" && s.parsed.literalType === "null").map((s) => s.getter)),
|
|
29402
|
+
undefinedSeededSignals: new Set(signals.filter((s) => s.parsed?.kind === "identifier" && s.parsed.name === "undefined").map((s) => s.getter)),
|
|
28972
29403
|
memos: new Map((ir.metadata.memos ?? []).map((m) => [m.name, m]))
|
|
28973
29404
|
};
|
|
28974
29405
|
}
|
|
@@ -29010,6 +29441,37 @@ function attrValueMayBeNullish(parsed, ctx, isShadowed = () => false) {
|
|
|
29010
29441
|
};
|
|
29011
29442
|
return parsed !== undefined && walk(parsed, isShadowed);
|
|
29012
29443
|
}
|
|
29444
|
+
function arithmeticOperandIsNull(parsed, ctx, isShadowed = () => false) {
|
|
29445
|
+
return arithmeticOperandSeed(parsed, ctx, isShadowed) === "null";
|
|
29446
|
+
}
|
|
29447
|
+
function arithmeticOperandIsUndefined(parsed, ctx, isShadowed = () => false) {
|
|
29448
|
+
return arithmeticOperandSeed(parsed, ctx, isShadowed) === "undefined";
|
|
29449
|
+
}
|
|
29450
|
+
function arithmeticOperandSeed(parsed, ctx, isShadowed) {
|
|
29451
|
+
const visiting = new Set;
|
|
29452
|
+
const walk = (expr, shadowed) => {
|
|
29453
|
+
if (expr.kind === "literal")
|
|
29454
|
+
return expr.literalType === "null" ? "null" : null;
|
|
29455
|
+
if (expr.kind === "identifier" && expr.name === "undefined" && !shadowed("undefined"))
|
|
29456
|
+
return "undefined";
|
|
29457
|
+
const getter = expr.kind === "identifier" ? expr.name : bareGetterCallName(expr);
|
|
29458
|
+
if (getter === null || shadowed(getter))
|
|
29459
|
+
return null;
|
|
29460
|
+
if (ctx.nullSeededSignals?.has(getter))
|
|
29461
|
+
return "null";
|
|
29462
|
+
if (ctx.undefinedSeededSignals?.has(getter))
|
|
29463
|
+
return "undefined";
|
|
29464
|
+
const memo = ctx.memos.get(getter);
|
|
29465
|
+
if (!memo?.parsed || visiting.has(getter))
|
|
29466
|
+
return null;
|
|
29467
|
+
visiting.add(getter);
|
|
29468
|
+
const result = walk(memo.parsed, () => false);
|
|
29469
|
+
visiting.delete(getter);
|
|
29470
|
+
return result;
|
|
29471
|
+
};
|
|
29472
|
+
return parsed === undefined ? null : walk(parsed, isShadowed);
|
|
29473
|
+
}
|
|
29474
|
+
var NULL_COERCING_ARITHMETIC_OPS = new Set(["-", "*", "/", "%", "**"]);
|
|
29013
29475
|
// src/query-href-lowering.ts
|
|
29014
29476
|
function matchQueryHrefCall(callee, args, localNames) {
|
|
29015
29477
|
if (callee.kind !== "identifier" || !localNames.has(callee.name))
|
|
@@ -31313,6 +31775,32 @@ function buildIdIndex(graph) {
|
|
|
31313
31775
|
}
|
|
31314
31776
|
return index;
|
|
31315
31777
|
}
|
|
31778
|
+
function buildRestHandlerSites(componentName, ir) {
|
|
31779
|
+
const sites = new Map;
|
|
31780
|
+
walkIR(ir.root, undefined, {
|
|
31781
|
+
element({ node, descend }) {
|
|
31782
|
+
const spread = node.slotId ? node.attrs.find((a) => a.name === "...") : undefined;
|
|
31783
|
+
if (spread && node.slotId) {
|
|
31784
|
+
const loc = spread.loc ?? node.loc;
|
|
31785
|
+
sites.set(`${componentName}#handler:${node.slotId}`, {
|
|
31786
|
+
kind: "handler",
|
|
31787
|
+
name: `@${node.slotId} {...}`,
|
|
31788
|
+
loc: { file: loc.file, line: loc.start.line }
|
|
31789
|
+
});
|
|
31790
|
+
}
|
|
31791
|
+
descend();
|
|
31792
|
+
},
|
|
31793
|
+
component({ descend, descendJsxChildren }) {
|
|
31794
|
+
descend();
|
|
31795
|
+
descendJsxChildren();
|
|
31796
|
+
}
|
|
31797
|
+
});
|
|
31798
|
+
return sites;
|
|
31799
|
+
}
|
|
31800
|
+
function restSiteOf(handlerId, sites) {
|
|
31801
|
+
const colon = handlerId.lastIndexOf(":");
|
|
31802
|
+
return colon < 0 ? undefined : sites.get(handlerId.slice(0, colon));
|
|
31803
|
+
}
|
|
31316
31804
|
function isRuntimeBookkeepingId(id) {
|
|
31317
31805
|
return /^[serm]\d+$/.test(id);
|
|
31318
31806
|
}
|
|
@@ -31784,7 +32272,8 @@ function buildProfileReport(input) {
|
|
|
31784
32272
|
const allSources = [{ source, filePath }, ...input.extraSources ?? []];
|
|
31785
32273
|
const index = new Map;
|
|
31786
32274
|
const turnBindings = new Map;
|
|
31787
|
-
|
|
32275
|
+
const staticHandlerIds = new Set;
|
|
32276
|
+
const restSites = new Map;
|
|
31788
32277
|
const instrumentedEffectLines = new Map;
|
|
31789
32278
|
for (const s of allSources) {
|
|
31790
32279
|
const program = createProgramForFile(s.source, s.filePath)?.program;
|
|
@@ -31798,13 +32287,19 @@ function buildProfileReport(input) {
|
|
|
31798
32287
|
componentNames = [undefined];
|
|
31799
32288
|
for (const name of componentNames) {
|
|
31800
32289
|
let graph;
|
|
32290
|
+
let ir;
|
|
31801
32291
|
try {
|
|
31802
|
-
graph = buildComponentAnalysis(s.source, s.filePath, name, program)
|
|
32292
|
+
({ graph, ir } = buildComponentAnalysis(s.source, s.filePath, name, program));
|
|
31803
32293
|
} catch {
|
|
31804
32294
|
continue;
|
|
31805
32295
|
}
|
|
31806
|
-
for (const [k, v] of buildIdIndex(graph))
|
|
32296
|
+
for (const [k, v] of buildIdIndex(graph)) {
|
|
31807
32297
|
index.set(k, v);
|
|
32298
|
+
if (v.kind === "handler")
|
|
32299
|
+
staticHandlerIds.add(k);
|
|
32300
|
+
}
|
|
32301
|
+
for (const [k, v] of buildRestHandlerSites(graph.componentName, ir))
|
|
32302
|
+
restSites.set(k, v);
|
|
31808
32303
|
for (const e of graph.effects) {
|
|
31809
32304
|
const set = instrumentedEffectLines.get(e.loc.file) ?? new Set;
|
|
31810
32305
|
set.add(e.loc.line);
|
|
@@ -31812,13 +32307,19 @@ function buildProfileReport(input) {
|
|
|
31812
32307
|
}
|
|
31813
32308
|
try {
|
|
31814
32309
|
const summary = buildEventSummary(s.source, s.filePath, name, program);
|
|
31815
|
-
handlersTotal += summary.events.length;
|
|
31816
32310
|
for (const [turn, binding] of turnToEventBinding(graph, summary.events)) {
|
|
31817
32311
|
turnBindings.set(turn, { binding, graph });
|
|
31818
32312
|
}
|
|
31819
32313
|
} catch {}
|
|
31820
32314
|
}
|
|
31821
32315
|
}
|
|
32316
|
+
for (const e of events) {
|
|
32317
|
+
if (e.turn === null || index.has(e.turn))
|
|
32318
|
+
continue;
|
|
32319
|
+
const site = restSiteOf(e.turn, restSites);
|
|
32320
|
+
if (site)
|
|
32321
|
+
index.set(e.turn, { ...site, name: `${e.turn.slice(e.turn.lastIndexOf(":") + 1)}${site.name}` });
|
|
32322
|
+
}
|
|
31822
32323
|
const hasFallbackEffectId = events.some((e) => e.subscriber !== undefined && isFallbackEffectId(e.subscriber));
|
|
31823
32324
|
const uninstrumentedCandidates = [];
|
|
31824
32325
|
if (hasFallbackEffectId) {
|
|
@@ -31854,9 +32355,10 @@ function buildProfileReport(input) {
|
|
|
31854
32355
|
handlerIds.add(e.turn);
|
|
31855
32356
|
}
|
|
31856
32357
|
}
|
|
32358
|
+
const handlersTotal = new Set([...staticHandlerIds, ...handlerIds]).size;
|
|
31857
32359
|
const findings = buildAgentFindings(primary.componentName, hotSubscribers, wastedReReruns, batchAdvisor, unattributed);
|
|
31858
32360
|
const status = findings.some((f) => f.severity === "warning" || f.severity === "error") ? "warning" : "ok";
|
|
31859
|
-
const ratio = handlersTotal > 0 ?
|
|
32361
|
+
const ratio = handlersTotal > 0 ? handlerIds.size / handlersTotal : 1;
|
|
31860
32362
|
let guidance;
|
|
31861
32363
|
if (turnSeqs.size === 0) {
|
|
31862
32364
|
guidance = handlersTotal === 0 ? {
|
|
@@ -32320,7 +32822,9 @@ export {
|
|
|
32320
32822
|
traceableNames,
|
|
32321
32823
|
traceUpdatePath,
|
|
32322
32824
|
testAdapter,
|
|
32825
|
+
templateNameCollisionErrors,
|
|
32323
32826
|
stringifyParsedExpr,
|
|
32827
|
+
stringifyBooleanTernaryBranches,
|
|
32324
32828
|
sortComparatorFromArrow,
|
|
32325
32829
|
serializeParsedExpr,
|
|
32326
32830
|
searchParamsLocalNames,
|
|
@@ -32337,6 +32841,7 @@ export {
|
|
|
32337
32841
|
resolveDangerousInnerHtml,
|
|
32338
32842
|
resolveBodyDestructuredPropAliases,
|
|
32339
32843
|
resetCompilerCounters,
|
|
32844
|
+
renameFreeIdentifiers,
|
|
32340
32845
|
registerLoweringPlugin,
|
|
32341
32846
|
registerBuiltinLoweringPlugins,
|
|
32342
32847
|
queryHrefPlugin,
|
|
@@ -32375,6 +32880,7 @@ export {
|
|
|
32375
32880
|
isStringTypedOperand,
|
|
32376
32881
|
isStringConcatBinary,
|
|
32377
32882
|
isOpaqueLocalAccessorName,
|
|
32883
|
+
isNumericArithmeticResult,
|
|
32378
32884
|
isNullishLiteral,
|
|
32379
32885
|
isNullableSignal,
|
|
32380
32886
|
isLowerableObjectRestDestructure,
|
|
@@ -32385,6 +32891,7 @@ export {
|
|
|
32385
32891
|
isEventHandlerName,
|
|
32386
32892
|
isElidedFactoryGetter,
|
|
32387
32893
|
isDangerousInnerHtmlAttr,
|
|
32894
|
+
isBooleanResultParsed,
|
|
32388
32895
|
isBooleanAttr,
|
|
32389
32896
|
importsSearchParams,
|
|
32390
32897
|
identifierPath,
|
|
@@ -32423,6 +32930,7 @@ export {
|
|
|
32423
32930
|
foldBlockToExpr,
|
|
32424
32931
|
findUninstrumentedEffects,
|
|
32425
32932
|
findReachableNames,
|
|
32933
|
+
filterCaptureCollisions,
|
|
32426
32934
|
extractSsrDefaults,
|
|
32427
32935
|
extractFunctionParams,
|
|
32428
32936
|
extractArrowBodyExpression,
|
|
@@ -32479,9 +32987,12 @@ export {
|
|
|
32479
32987
|
buildComponentSummary,
|
|
32480
32988
|
buildComponentGraph,
|
|
32481
32989
|
buildComponentAnalysis,
|
|
32990
|
+
bareGetterCallName,
|
|
32482
32991
|
augmentInheritedPropAccesses,
|
|
32483
32992
|
attrValueMayBeNullish,
|
|
32484
32993
|
asCallbackMethodCall,
|
|
32994
|
+
arithmeticOperandIsUndefined,
|
|
32995
|
+
arithmeticOperandIsNull,
|
|
32485
32996
|
applyCssLayerPrefix,
|
|
32486
32997
|
analyzeWastedReReruns,
|
|
32487
32998
|
analyzeHotSubscribers,
|
|
@@ -32498,6 +33009,7 @@ export {
|
|
|
32498
33009
|
REACTIVE_PRIMITIVES,
|
|
32499
33010
|
PROFILE_SCHEMA_VERSION,
|
|
32500
33011
|
PARSED_EXPR_KINDS,
|
|
33012
|
+
NULL_COERCING_ARITHMETIC_OPS,
|
|
32501
33013
|
JsxAdapter,
|
|
32502
33014
|
ErrorCodes,
|
|
32503
33015
|
ESCAPE_SSR_COST,
|