@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/src/jsx-to-ir.ts
CHANGED
|
@@ -4561,6 +4561,128 @@ function applyLoopKeyAttr(node: IRNode, name: string, value: string): void {
|
|
|
4561
4561
|
}
|
|
4562
4562
|
}
|
|
4563
4563
|
|
|
4564
|
+
/**
|
|
4565
|
+
* Give every SSR-portal element (`ssrPortalOwnerScope`) in a `.map()` row
|
|
4566
|
+
* the row's key attribute (#3318). SSR places such an element at its portal
|
|
4567
|
+
* outlet, outside the row, so its slot and owner scope alone cannot say
|
|
4568
|
+
* which row it belongs to; the row key on the element itself lets
|
|
4569
|
+
* hydration pair it with its row (`claimRowPortals`) and lets the loop's
|
|
4570
|
+
* delegated listener resolve the row from the element
|
|
4571
|
+
* (`closest('[data-key]')`). Every SSR adapter renders `IRElement.keyAttr`,
|
|
4572
|
+
* and the client templates render it from a `key` attribute, so the element
|
|
4573
|
+
* also gets a copy of the row root's `key` attribute; no adapter changes
|
|
4574
|
+
* are needed.
|
|
4575
|
+
*
|
|
4576
|
+
* Only a keyed top-level loop (`depth === 0`) is supported. A nested loop's
|
|
4577
|
+
* row key is not unique on its own and an unkeyed row has none, so a
|
|
4578
|
+
* portal element there is refused (BF064) rather than rendered at an
|
|
4579
|
+
* outlet nothing can pair. So is one forwarded as a child component's
|
|
4580
|
+
* `children` (or inside a provider / `<Async>`), where the row's key is not
|
|
4581
|
+
* this element's to render; one inside a reactive conditional in the row,
|
|
4582
|
+
* whose `ref` the conditional's branch runs rather than the row; and the
|
|
4583
|
+
* row root itself, whose move leaves no inline row for hydration to find.
|
|
4584
|
+
* Nested loops are skipped: their own construction applies this to their
|
|
4585
|
+
* rows (a nested loop's portaled row root is refused here, as it already
|
|
4586
|
+
* carries its `keyAttr`).
|
|
4587
|
+
*/
|
|
4588
|
+
function applyRowPortalKeyAttrs(
|
|
4589
|
+
children: IRNode[],
|
|
4590
|
+
key: string | null,
|
|
4591
|
+
depth: number,
|
|
4592
|
+
ctx: TransformContext,
|
|
4593
|
+
): void {
|
|
4594
|
+
const refuse = (el: IRElement, reason: string): void => {
|
|
4595
|
+
ctx.analyzer.errors.push(
|
|
4596
|
+
createError(ErrorCodes.ROW_PORTAL_UNPAIRABLE, el.loc, {
|
|
4597
|
+
message:
|
|
4598
|
+
`A ref callback portals <${el.tag}> out of a .map() row, but ${reason}, so hydration cannot pair the ` +
|
|
4599
|
+
'portaled element with its row and its event handlers would stop running after hydration.',
|
|
4600
|
+
suggestion: {
|
|
4601
|
+
message:
|
|
4602
|
+
'Portal an element inside the root of a keyed top-level .map() row (`key={…}` on the row root), ' +
|
|
4603
|
+
"outside reactive conditionals and child components' children, or move the portal outside the loop.",
|
|
4604
|
+
escape: [{ kind: 'rewrite' }],
|
|
4605
|
+
},
|
|
4606
|
+
}),
|
|
4607
|
+
)
|
|
4608
|
+
}
|
|
4609
|
+
// `blocked` names why an element at this position cannot be paired with
|
|
4610
|
+
// its row; `null` means it can.
|
|
4611
|
+
const visit = (node: IRNode, blocked: string | null): void => {
|
|
4612
|
+
switch (node.type) {
|
|
4613
|
+
case 'element':
|
|
4614
|
+
if (node.ssrPortalOwnerScope) {
|
|
4615
|
+
// `applyLoopKeyAttr` stamps the row root (of this loop, or of a
|
|
4616
|
+
// nested loop already built) before this pass: a portaled row root
|
|
4617
|
+
// leaves no inline row for hydration to find.
|
|
4618
|
+
if (node.keyAttr) refuse(node, 'it is the root element of the row')
|
|
4619
|
+
else if (blocked) refuse(node, blocked)
|
|
4620
|
+
else if (key === null) refuse(node, 'the loop has no `key`')
|
|
4621
|
+
else if (depth > 0) refuse(node, 'the loop is nested inside another loop')
|
|
4622
|
+
else {
|
|
4623
|
+
node.keyAttr = { name: keyAttrName(depth), value: key }
|
|
4624
|
+
// The client templates render the row key from a `key` attribute
|
|
4625
|
+
// gated on `keyAttr`, as they do for the row root, so the element
|
|
4626
|
+
// carries a copy of the row root's.
|
|
4627
|
+
if (!node.attrs.some((a) => a.name === 'key')) {
|
|
4628
|
+
node.attrs.push(rowKeyAttribute(children) ?? { name: 'key', value: { kind: 'expression', expr: key }, loc: node.loc })
|
|
4629
|
+
}
|
|
4630
|
+
}
|
|
4631
|
+
}
|
|
4632
|
+
for (const c of node.children) visit(c, blocked)
|
|
4633
|
+
return
|
|
4634
|
+
case 'fragment':
|
|
4635
|
+
for (const c of node.children) visit(c, blocked)
|
|
4636
|
+
return
|
|
4637
|
+
case 'conditional': {
|
|
4638
|
+
// A reactive conditional (`slotId`) owns its branch's refs, which
|
|
4639
|
+
// the row's ref collection skips, so the row cannot adopt them.
|
|
4640
|
+
const inner = blocked ?? (node.slotId ? 'it is rendered inside a reactive conditional in the row' : null)
|
|
4641
|
+
visit(node.whenTrue, inner)
|
|
4642
|
+
visit(node.whenFalse, inner)
|
|
4643
|
+
return
|
|
4644
|
+
}
|
|
4645
|
+
case 'if-statement':
|
|
4646
|
+
visit(node.consequent, blocked)
|
|
4647
|
+
if (node.alternate) visit(node.alternate, blocked)
|
|
4648
|
+
return
|
|
4649
|
+
case 'component':
|
|
4650
|
+
case 'provider':
|
|
4651
|
+
for (const c of node.children) visit(c, blocked ?? "it is rendered inside another component's children")
|
|
4652
|
+
return
|
|
4653
|
+
case 'async':
|
|
4654
|
+
visit(node.fallback, blocked ?? "it is rendered inside another component's children")
|
|
4655
|
+
for (const c of node.children) visit(c, blocked ?? "it is rendered inside another component's children")
|
|
4656
|
+
return
|
|
4657
|
+
default:
|
|
4658
|
+
return
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4661
|
+
for (const c of children) visit(c, null)
|
|
4662
|
+
}
|
|
4663
|
+
|
|
4664
|
+
/** The `key` attribute the row's key was read from (`extractLoopKey`), when it is on an element. */
|
|
4665
|
+
function rowKeyAttribute(children: IRNode[]): IRAttribute | null {
|
|
4666
|
+
const find = (node: IRNode): IRAttribute | null => {
|
|
4667
|
+
switch (node.type) {
|
|
4668
|
+
case 'element':
|
|
4669
|
+
return node.attrs.find((a) => a.name === 'key') ?? null
|
|
4670
|
+
case 'conditional':
|
|
4671
|
+
return find(node.whenTrue)
|
|
4672
|
+
case 'fragment': {
|
|
4673
|
+
const first = node.children.find(
|
|
4674
|
+
(c) => !(c.type === 'text' && typeof c.value === 'string' && !c.value.trim())
|
|
4675
|
+
)
|
|
4676
|
+
return first ? find(first) : null
|
|
4677
|
+
}
|
|
4678
|
+
default:
|
|
4679
|
+
return null
|
|
4680
|
+
}
|
|
4681
|
+
}
|
|
4682
|
+
const first = children.find((c) => !(c.type === 'text' && typeof c.value === 'string' && !c.value.trim()))
|
|
4683
|
+
return first ? find(first) : null
|
|
4684
|
+
}
|
|
4685
|
+
|
|
4564
4686
|
function loopBodyItemConditional(children: IRNode[]): IRConditional | null {
|
|
4565
4687
|
const real = children.filter(
|
|
4566
4688
|
(c) => !(c.type === 'text' && typeof c.value === 'string' && !c.value.trim())
|
|
@@ -5419,6 +5541,7 @@ function transformMapCall(
|
|
|
5419
5541
|
applyLoopKeyAttr(children[0], resolvedKeyAttrName, key)
|
|
5420
5542
|
}
|
|
5421
5543
|
}
|
|
5544
|
+
applyRowPortalKeyAttrs(children, key, depth, ctx)
|
|
5422
5545
|
|
|
5423
5546
|
// Stage 3 / D5 (spec/callback-fidelity.md) — the keyFn is hoisted: `mapArray`
|
|
5424
5547
|
// computes it from the raw item BEFORE the callback body runs, so the key must
|
|
@@ -7092,14 +7215,6 @@ interface LocalCallback {
|
|
|
7092
7215
|
interface RefCallback extends LocalCallback {
|
|
7093
7216
|
/** Bound by name (`ref={handleMount}`) rather than written inline. */
|
|
7094
7217
|
named: boolean
|
|
7095
|
-
/**
|
|
7096
|
-
* True only for a named callback declared in the `ref`'s innermost
|
|
7097
|
-
* enclosing function scope; false for an inline callback and for one
|
|
7098
|
-
* `findNamedCallback`'s outward walk found further out (e.g. a `ref` in a
|
|
7099
|
-
* `.map()` row naming a component-body handler). BF063 ignores this;
|
|
7100
|
-
* `isSsrPortalRefCallback` requires it.
|
|
7101
|
-
*/
|
|
7102
|
-
innermostScope: boolean
|
|
7103
7218
|
}
|
|
7104
7219
|
|
|
7105
7220
|
/**
|
|
@@ -7111,11 +7226,11 @@ interface RefCallback extends LocalCallback {
|
|
|
7111
7226
|
function resolveRefCallback(refExpr: ts.Expression): RefCallback | undefined {
|
|
7112
7227
|
const expr = unwrapTransparentTsWrappers(refExpr)
|
|
7113
7228
|
if (ts.isArrowFunction(expr) || ts.isFunctionExpression(expr)) {
|
|
7114
|
-
return { param: firstSimpleParamName(expr), body: expr.body, named: false
|
|
7229
|
+
return { param: firstSimpleParamName(expr), body: expr.body, named: false }
|
|
7115
7230
|
}
|
|
7116
7231
|
if (!ts.isIdentifier(expr)) return undefined
|
|
7117
|
-
const
|
|
7118
|
-
return
|
|
7232
|
+
const callback = findNamedCallback(expr)
|
|
7233
|
+
return callback && { ...callback, named: true }
|
|
7119
7234
|
}
|
|
7120
7235
|
|
|
7121
7236
|
type FunctionLike = ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration
|
|
@@ -7147,20 +7262,13 @@ function findEnclosingFunctionLike(node: ts.Node): FunctionLike | undefined {
|
|
|
7147
7262
|
* Never searches a nested function's own body: two sibling components in the
|
|
7148
7263
|
* same file can each declare their own, unrelated `handleMount`, and reaching
|
|
7149
7264
|
* into the wrong one's closure would misattribute its behavior to this `ref`.
|
|
7150
|
-
* `innermostScope` reports whether the deciding scope was the `ref`'s own
|
|
7151
|
-
* innermost one: BF063 accepts any scope, the SSR-portal recognition only
|
|
7152
|
-
* that one (see `isSsrPortalRefCallback`).
|
|
7153
7265
|
*/
|
|
7154
|
-
function findNamedCallback(
|
|
7155
|
-
ident
|
|
7156
|
-
): { callback: LocalCallback; innermostScope: boolean } | undefined {
|
|
7157
|
-
const innermost = findEnclosingFunctionLike(ident)
|
|
7158
|
-
for (let fn = innermost; fn; fn = findEnclosingFunctionLike(fn)) {
|
|
7266
|
+
function findNamedCallback(ident: ts.Identifier): LocalCallback | undefined {
|
|
7267
|
+
for (let fn = findEnclosingFunctionLike(ident); fn; fn = findEnclosingFunctionLike(fn)) {
|
|
7159
7268
|
if (fn.parameters.some(p => bindingDeclares(p.name, ident.text))) return undefined
|
|
7160
7269
|
const decl = fn.body && findScopeDeclaration(ident.text, fn.body)
|
|
7161
7270
|
if (!decl) continue
|
|
7162
|
-
|
|
7163
|
-
return callback && { callback, innermostScope: fn === innermost }
|
|
7271
|
+
return localCallbackOf(decl)
|
|
7164
7272
|
}
|
|
7165
7273
|
return undefined
|
|
7166
7274
|
}
|
|
@@ -7238,24 +7346,22 @@ function bindingDeclares(binding: ts.BindingName, name: string): boolean {
|
|
|
7238
7346
|
* (the "worth the scope-walk?" open question from #3059) is therefore
|
|
7239
7347
|
* left for when a real caller needs it.
|
|
7240
7348
|
*
|
|
7241
|
-
* The callback
|
|
7242
|
-
*
|
|
7243
|
-
*
|
|
7244
|
-
*
|
|
7245
|
-
*
|
|
7246
|
-
*
|
|
7247
|
-
* either way (a row-declared callback is still recognized, and still
|
|
7248
|
-
* breaks) — the known limitation `loop-row-ref-portal`
|
|
7249
|
-
* (`packages/adapter-tests/limitations/loop-row-ref-portal.ts`).
|
|
7349
|
+
* The callback may be declared in any enclosing function scope
|
|
7350
|
+
* (`findNamedCallback`, shared with BF063): a `ref` in a `.map()` row
|
|
7351
|
+
* naming a handler declared in the component body is recognized too. The
|
|
7352
|
+
* resolution never crosses into a sibling function's body and stops at a
|
|
7353
|
+
* shadowing parameter or non-function binding, so the callback found is
|
|
7354
|
+
* the one that runs.
|
|
7250
7355
|
*
|
|
7251
7356
|
* A match makes `element.ssrPortalOwnerScope` true, which every adapter
|
|
7252
7357
|
* (#3119) uses to place the element's SSR markup at its own portal
|
|
7253
|
-
* outlet instead of inline.
|
|
7358
|
+
* outlet instead of inline. Inside a keyed top-level `.map()` row the
|
|
7359
|
+
* element also carries the row key (`applyRowPortalKeyAttrs`, #3318), so
|
|
7360
|
+
* hydration pairs it with its row; a nested or unkeyed row refuses (BF064).
|
|
7254
7361
|
*/
|
|
7255
7362
|
function isSsrPortalRefCallback(callback: RefCallback | undefined): boolean {
|
|
7256
7363
|
return (
|
|
7257
7364
|
!!callback?.named &&
|
|
7258
|
-
callback.innermostScope &&
|
|
7259
7365
|
!!callback.param &&
|
|
7260
7366
|
containsSsrPortalPlacementCall(callback.body, callback.param)
|
|
7261
7367
|
)
|
|
@@ -81,12 +81,26 @@ export function nullableSignalAttrGetter(
|
|
|
81
81
|
*/
|
|
82
82
|
export interface NullishAttrContext {
|
|
83
83
|
readonly nullableSignals: ReadonlySet<string>
|
|
84
|
+
/** Signals seeded with a literal `null`: their SSR value is `null`, not
|
|
85
|
+
* `undefined` (`arithmeticOperandIsNull`). */
|
|
86
|
+
readonly nullSeededSignals?: ReadonlySet<string>
|
|
87
|
+
/** Signals seeded with `undefined` (`createSignal(undefined)` or a
|
|
88
|
+
* zero-arg `createSignal()`): their SSR value is `undefined`, not `null`
|
|
89
|
+
* (`arithmeticOperandIsUndefined`). */
|
|
90
|
+
readonly undefinedSeededSignals?: ReadonlySet<string>
|
|
84
91
|
readonly memos: ReadonlyMap<string, MemoInfo>
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
export function collectNullishAttrContext(ir: ComponentIR): NullishAttrContext {
|
|
95
|
+
const signals = ir.metadata.signals ?? []
|
|
88
96
|
return {
|
|
89
97
|
nullableSignals: collectNullableSignalGetters(ir),
|
|
98
|
+
nullSeededSignals: new Set(
|
|
99
|
+
signals.filter(s => s.parsed?.kind === 'literal' && s.parsed.literalType === 'null').map(s => s.getter),
|
|
100
|
+
),
|
|
101
|
+
undefinedSeededSignals: new Set(
|
|
102
|
+
signals.filter(s => s.parsed?.kind === 'identifier' && s.parsed.name === 'undefined').map(s => s.getter),
|
|
103
|
+
),
|
|
90
104
|
memos: new Map((ir.metadata.memos ?? []).map(m => [m.name, m])),
|
|
91
105
|
}
|
|
92
106
|
}
|
|
@@ -154,3 +168,67 @@ export function attrValueMayBeNullish(
|
|
|
154
168
|
}
|
|
155
169
|
return parsed !== undefined && walk(parsed, isShadowed)
|
|
156
170
|
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Whether an arithmetic operand's SSR value is certainly `null` — a literal
|
|
174
|
+
* `null`, a read of a signal seeded with `null`, or a memo whose body is
|
|
175
|
+
* such a read (`same = () => s()`). JS `ToNumber(null)` is `0` but
|
|
176
|
+
* `ToNumber(undefined)` is `NaN`, and a template engine holds both as one
|
|
177
|
+
* nil, so only a value known to be `null` may be coerced to `0` (#3350).
|
|
178
|
+
* A bare identifier is read as the getter call: a memo seed lowers `s()` to
|
|
179
|
+
* `s` before the adapter sees it.
|
|
180
|
+
*/
|
|
181
|
+
export function arithmeticOperandIsNull(
|
|
182
|
+
parsed: ParsedExpr | undefined,
|
|
183
|
+
ctx: NullishAttrContext,
|
|
184
|
+
isShadowed: (name: string) => boolean = () => false,
|
|
185
|
+
): boolean {
|
|
186
|
+
return arithmeticOperandSeed(parsed, ctx, isShadowed) === 'null'
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Whether an arithmetic operand's SSR value is certainly `undefined` — the
|
|
191
|
+
* literal `undefined`, a read of a signal seeded with `undefined` (or a
|
|
192
|
+
* zero-arg `createSignal()`), or a memo whose body is such a read. JS
|
|
193
|
+
* `ToNumber(undefined)` is `NaN`, so adapters coerce such an operand with
|
|
194
|
+
* their JS `Number()` helper, which maps the engine's nil to `NaN` (#3390).
|
|
195
|
+
*/
|
|
196
|
+
export function arithmeticOperandIsUndefined(
|
|
197
|
+
parsed: ParsedExpr | undefined,
|
|
198
|
+
ctx: NullishAttrContext,
|
|
199
|
+
isShadowed: (name: string) => boolean = () => false,
|
|
200
|
+
): boolean {
|
|
201
|
+
return arithmeticOperandSeed(parsed, ctx, isShadowed) === 'undefined'
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function arithmeticOperandSeed(
|
|
205
|
+
parsed: ParsedExpr | undefined,
|
|
206
|
+
ctx: NullishAttrContext,
|
|
207
|
+
isShadowed: (name: string) => boolean,
|
|
208
|
+
): 'null' | 'undefined' | null {
|
|
209
|
+
const visiting = new Set<string>()
|
|
210
|
+
const walk = (expr: ParsedExpr, shadowed: (name: string) => boolean): 'null' | 'undefined' | null => {
|
|
211
|
+
if (expr.kind === 'literal') return expr.literalType === 'null' ? 'null' : null
|
|
212
|
+
if (expr.kind === 'identifier' && expr.name === 'undefined' && !shadowed('undefined')) return 'undefined'
|
|
213
|
+
const getter = expr.kind === 'identifier' ? expr.name : bareGetterCallName(expr)
|
|
214
|
+
if (getter === null || shadowed(getter)) return null
|
|
215
|
+
if (ctx.nullSeededSignals?.has(getter)) return 'null'
|
|
216
|
+
if (ctx.undefinedSeededSignals?.has(getter)) return 'undefined'
|
|
217
|
+
const memo = ctx.memos.get(getter)
|
|
218
|
+
if (!memo?.parsed || visiting.has(getter)) return null
|
|
219
|
+
visiting.add(getter)
|
|
220
|
+
const result = walk(memo.parsed, () => false)
|
|
221
|
+
visiting.delete(getter)
|
|
222
|
+
return result
|
|
223
|
+
}
|
|
224
|
+
return parsed === undefined ? null : walk(parsed, isShadowed)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Arithmetic operators JS applies `ToNumber` to, so a `null` operand reads
|
|
229
|
+
* as `0` (`null * 2` is `0`). A template engine's native operator rejects a
|
|
230
|
+
* nil operand instead and the render throws (#3350), so adapters coerce an
|
|
231
|
+
* operand that `arithmeticOperandIsNull` matches. `+` is excluded: it
|
|
232
|
+
* concatenates when either side is a string.
|
|
233
|
+
*/
|
|
234
|
+
export const NULL_COERCING_ARITHMETIC_OPS: ReadonlySet<string> = new Set(['-', '*', '/', '%', '**'])
|
package/src/profiler.ts
CHANGED
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
type UpdatePathEntry,
|
|
31
31
|
} from './debug.ts'
|
|
32
32
|
import { listComponentFunctions, createProgramForFile } from './analyzer.ts'
|
|
33
|
+
import { walkIR } from './ir-to-client-js/walker.ts'
|
|
34
|
+
import type { ComponentIR } from './types.ts'
|
|
33
35
|
import type { ProfilerEvent } from '@barefootjs/shared'
|
|
34
36
|
|
|
35
37
|
/**
|
|
@@ -509,6 +511,46 @@ export function buildIdIndex(graph: ComponentGraph): IdIndex {
|
|
|
509
511
|
return index
|
|
510
512
|
}
|
|
511
513
|
|
|
514
|
+
/**
|
|
515
|
+
* Handler sites behind a rest/props spread on an intrinsic element
|
|
516
|
+
* (`<button {...props}>`), keyed by their turn-id prefix
|
|
517
|
+
* `<Component>#handler:<slotId>` (#3376). The compiler wires the event handlers
|
|
518
|
+
* such a spread carries at runtime (`applyRestAttrs`), so which events they are
|
|
519
|
+
* is only known once a caller passes them — the turn id appends the DOM event
|
|
520
|
+
* name the runtime saw. Resolving a recorded turn id to its spread site needs
|
|
521
|
+
* only the prefix, so every spread with a slot is listed: one the compiler
|
|
522
|
+
* applies statically never produces such a turn id, and its entry stays unused.
|
|
523
|
+
*/
|
|
524
|
+
function buildRestHandlerSites(componentName: string, ir: ComponentIR): Map<string, ResolvedNode> {
|
|
525
|
+
const sites = new Map<string, ResolvedNode>()
|
|
526
|
+
walkIR(ir.root, undefined, {
|
|
527
|
+
element({ node, descend }) {
|
|
528
|
+
const spread = node.slotId ? node.attrs.find(a => a.name === '...') : undefined
|
|
529
|
+
if (spread && node.slotId) {
|
|
530
|
+
const loc = spread.loc ?? node.loc
|
|
531
|
+
sites.set(`${componentName}#handler:${node.slotId}`, {
|
|
532
|
+
kind: 'handler',
|
|
533
|
+
// Completed with the event name per turn id: `click@s0 {...}`.
|
|
534
|
+
name: `@${node.slotId} {...}`,
|
|
535
|
+
loc: { file: loc.file, line: loc.start.line },
|
|
536
|
+
})
|
|
537
|
+
}
|
|
538
|
+
descend()
|
|
539
|
+
},
|
|
540
|
+
component({ descend, descendJsxChildren }) {
|
|
541
|
+
descend()
|
|
542
|
+
descendJsxChildren()
|
|
543
|
+
},
|
|
544
|
+
})
|
|
545
|
+
return sites
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** The spread site a rest-forwarded turn id (`<site>:<event>`) belongs to. */
|
|
549
|
+
function restSiteOf(handlerId: string, sites: ReadonlyMap<string, ResolvedNode>): ResolvedNode | undefined {
|
|
550
|
+
const colon = handlerId.lastIndexOf(':')
|
|
551
|
+
return colon < 0 ? undefined : sites.get(handlerId.slice(0, colon))
|
|
552
|
+
}
|
|
553
|
+
|
|
512
554
|
/** A profiler id that no IR node could be found for (SR4 coverage gap). */
|
|
513
555
|
export interface UnattributedId {
|
|
514
556
|
id: string
|
|
@@ -1358,7 +1400,15 @@ export interface DiagnosticsSummary {
|
|
|
1358
1400
|
export interface ProfileCoverage {
|
|
1359
1401
|
/** Distinct handlers exercised (turns observed). */
|
|
1360
1402
|
handlersFired: number
|
|
1361
|
-
/**
|
|
1403
|
+
/**
|
|
1404
|
+
* DOM handler sites in the run (#3377): one per instrumented DOM listener —
|
|
1405
|
+
* every `<el on*={…}>` event binding the IR knows about, plus each
|
|
1406
|
+
* rest-forwarded listener (`<el {...props}>`, #3376) the run observed (its
|
|
1407
|
+
* events are decided by the caller, so it is known only once wired). The same
|
|
1408
|
+
* unit the numerator counts — a turn is recorded per DOM listener — so a
|
|
1409
|
+
* callback prop a parent hands a child (`<Child onClick={…}>`) is not a unit
|
|
1410
|
+
* of its own: it runs inside the child's DOM turn.
|
|
1411
|
+
*/
|
|
1362
1412
|
handlersTotal: number
|
|
1363
1413
|
/**
|
|
1364
1414
|
* `handlersFired / handlersTotal` in `[0,1]` — the fraction of known handlers
|
|
@@ -1607,7 +1657,11 @@ export function buildProfileReport(input: ProfileReportInput): ProfileReport {
|
|
|
1607
1657
|
// turn id → the handler binding + the component graph that owns it (so the
|
|
1608
1658
|
// safety oracle reasons over the right component's memos).
|
|
1609
1659
|
const turnBindings = new Map<string, { binding: EventBinding; graph: ComponentGraph }>()
|
|
1610
|
-
|
|
1660
|
+
// Coverage inventory (#3377): the turn ids of every DOM event binding — the
|
|
1661
|
+
// same inventory the auto scenario fires and the static budget lists.
|
|
1662
|
+
const staticHandlerIds = new Set<string>()
|
|
1663
|
+
// Spread sites whose runtime-wired handlers carry their own turn ids (#3376).
|
|
1664
|
+
const restSites = new Map<string, ResolvedNode>()
|
|
1611
1665
|
// Per-file lines of the `createEffect` calls the compiler instrumented (top
|
|
1612
1666
|
// level, carry a `__bfId`). Subtracted from a source scan to find the
|
|
1613
1667
|
// uninstrumented ones behind anonymous `e<n>` ids (#1849 B6).
|
|
@@ -1628,12 +1682,17 @@ export function buildProfileReport(input: ProfileReportInput): ProfileReport {
|
|
|
1628
1682
|
if (componentNames.length === 0) componentNames = [undefined as unknown as string]
|
|
1629
1683
|
for (const name of componentNames) {
|
|
1630
1684
|
let graph: ComponentGraph
|
|
1685
|
+
let ir: ComponentIR
|
|
1631
1686
|
try {
|
|
1632
|
-
graph = buildComponentAnalysis(s.source, s.filePath, name, program)
|
|
1687
|
+
;({ graph, ir } = buildComponentAnalysis(s.source, s.filePath, name, program))
|
|
1633
1688
|
} catch {
|
|
1634
1689
|
continue
|
|
1635
1690
|
}
|
|
1636
|
-
for (const [k, v] of buildIdIndex(graph))
|
|
1691
|
+
for (const [k, v] of buildIdIndex(graph)) {
|
|
1692
|
+
index.set(k, v)
|
|
1693
|
+
if (v.kind === 'handler') staticHandlerIds.add(k)
|
|
1694
|
+
}
|
|
1695
|
+
for (const [k, v] of buildRestHandlerSites(graph.componentName, ir)) restSites.set(k, v)
|
|
1637
1696
|
for (const e of graph.effects) {
|
|
1638
1697
|
const set = instrumentedEffectLines.get(e.loc.file) ?? new Set<number>()
|
|
1639
1698
|
set.add(e.loc.line)
|
|
@@ -1641,7 +1700,6 @@ export function buildProfileReport(input: ProfileReportInput): ProfileReport {
|
|
|
1641
1700
|
}
|
|
1642
1701
|
try {
|
|
1643
1702
|
const summary = buildEventSummary(s.source, s.filePath, name, program)
|
|
1644
|
-
handlersTotal += summary.events.length
|
|
1645
1703
|
for (const [turn, binding] of turnToEventBinding(graph, summary.events)) {
|
|
1646
1704
|
turnBindings.set(turn, { binding, graph })
|
|
1647
1705
|
}
|
|
@@ -1651,6 +1709,14 @@ export function buildProfileReport(input: ProfileReportInput): ProfileReport {
|
|
|
1651
1709
|
}
|
|
1652
1710
|
}
|
|
1653
1711
|
|
|
1712
|
+
// A rest-forwarded turn id resolves to its spread site (#3376), so its batch
|
|
1713
|
+
// candidate and findings cite source like any explicit handler's.
|
|
1714
|
+
for (const e of events) {
|
|
1715
|
+
if (e.turn === null || index.has(e.turn)) continue
|
|
1716
|
+
const site = restSiteOf(e.turn, restSites)
|
|
1717
|
+
if (site) index.set(e.turn, { ...site, name: `${e.turn.slice(e.turn.lastIndexOf(':') + 1)}${site.name}` })
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1654
1720
|
// Candidate sites for uninstrumented `createEffect` ids, across every source
|
|
1655
1721
|
// in the run (a compound scenario spans several files), so an `e<n>` row can
|
|
1656
1722
|
// cite where to look (#1849 B6). The per-file AST scan is only ever consumed
|
|
@@ -1701,6 +1767,11 @@ export function buildProfileReport(input: ProfileReportInput): ProfileReport {
|
|
|
1701
1767
|
handlerIds.add(e.turn)
|
|
1702
1768
|
}
|
|
1703
1769
|
}
|
|
1770
|
+
// The inventory is every static DOM handler site plus every one the run
|
|
1771
|
+
// observed — a turn id the IR could not list (a rest-forwarded listener) is
|
|
1772
|
+
// still a DOM handler that exists. Numerator and denominator count the same
|
|
1773
|
+
// unit, so a fully exercised component reads 1 and the ratio can't pass 1.
|
|
1774
|
+
const handlersTotal = new Set([...staticHandlerIds, ...handlerIds]).size
|
|
1704
1775
|
|
|
1705
1776
|
const findings = buildAgentFindings(primary.componentName, hotSubscribers, wastedReReruns, batchAdvisor, unattributed)
|
|
1706
1777
|
// Status is measurement-only here: any warning/error finding ⇒ `warning`. A
|
|
@@ -1709,11 +1780,9 @@ export function buildProfileReport(input: ProfileReportInput): ProfileReport {
|
|
|
1709
1780
|
const status: ProfileStatus = findings.some(f => f.severity === 'warning' || f.severity === 'error') ? 'warning' : 'ok'
|
|
1710
1781
|
|
|
1711
1782
|
// Coverage ratio: 1 when there is nothing to cover (no handlers), else the
|
|
1712
|
-
// exercised fraction
|
|
1713
|
-
//
|
|
1714
|
-
|
|
1715
|
-
// `--min-coverage` and the guidance below.
|
|
1716
|
-
const ratio = handlersTotal > 0 ? Math.min(1, handlerIds.size / handlersTotal) : 1
|
|
1783
|
+
// exercised fraction — in `[0,1]` by construction, since every exercised id
|
|
1784
|
+
// is in the inventory. Drives `--min-coverage` and the guidance below.
|
|
1785
|
+
const ratio = handlersTotal > 0 ? handlerIds.size / handlersTotal : 1
|
|
1717
1786
|
let guidance: ScenarioGuidance | undefined
|
|
1718
1787
|
if (turnSeqs.size === 0) {
|
|
1719
1788
|
guidance =
|
|
@@ -148,6 +148,25 @@ export class BindingScope {
|
|
|
148
148
|
return new BindingScope([frame, ...this.frames])
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Child scope with a `'callback'` frame binding each alias to the binding
|
|
153
|
+
* its original name resolves to here (same source and string typing). An
|
|
154
|
+
* adapter that rewrites a `.filter()` predicate's captured names to
|
|
155
|
+
* loop-scoped aliases enters this while emitting the predicate, so the
|
|
156
|
+
* aliases render and type exactly like the names they stand for (#3402).
|
|
157
|
+
* Aliases whose original is unbound are skipped; returns `this` when none
|
|
158
|
+
* bind. Parent is not mutated.
|
|
159
|
+
*/
|
|
160
|
+
enterAliases(aliasToOriginal: ReadonlyMap<string, string>): BindingScope {
|
|
161
|
+
const bindings = new Map<string, ScopeBinding>()
|
|
162
|
+
for (const [alias, original] of aliasToOriginal) {
|
|
163
|
+
const hit = this.lookup(original)
|
|
164
|
+
if (hit) bindings.set(alias, hit.binding)
|
|
165
|
+
}
|
|
166
|
+
if (bindings.size === 0) return this
|
|
167
|
+
return new BindingScope([{ kind: 'callback', bindings }, ...this.frames])
|
|
168
|
+
}
|
|
169
|
+
|
|
151
170
|
/** Innermost-first membership check across every frame in the stack. */
|
|
152
171
|
isBound(name: string): boolean {
|
|
153
172
|
for (const frame of this.frames) {
|
package/src/types.ts
CHANGED
|
@@ -1130,6 +1130,13 @@ export interface LoopParamBinding {
|
|
|
1130
1130
|
* reading it as "binding at the loop root".
|
|
1131
1131
|
*/
|
|
1132
1132
|
segments?: readonly LoopBindingPathSegment[]
|
|
1133
|
+
/**
|
|
1134
|
+
* Client JS only: the row accessor call this binding reads through
|
|
1135
|
+
* (`__bfItem_l0()`), set on the bindings of a nested destructured `.map()`
|
|
1136
|
+
* row so its render callback does not shadow an enclosing row's
|
|
1137
|
+
* `__bfItem` (#3397). Absent for a top-level row, which reads `__bfItem()`.
|
|
1138
|
+
*/
|
|
1139
|
+
accessor?: string
|
|
1133
1140
|
}
|
|
1134
1141
|
|
|
1135
1142
|
export interface IRComponent {
|