@barefootjs/jsx 0.39.4 → 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/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/expression-parser.d.ts +10 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +358 -132
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +8 -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/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.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 +12 -0
- package/dist/nullable-signal-attr.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__/compile-without-node-process.test.ts +78 -0
- package/src/__tests__/doc-examples.test.ts +1 -0
- package/src/__tests__/nested-row-shadowing.test.ts +57 -0
- package/src/__tests__/rename-free-identifiers.test.ts +26 -0
- package/src/__tests__/template-name-collisions.test.ts +81 -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/expression-parser.ts +32 -0
- package/src/index.ts +6 -2
- package/src/ir-to-client-js/collect-elements.ts +11 -7
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +31 -10
- 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/shared.ts +4 -1
- package/src/ir-to-client-js/html-template.ts +13 -7
- package/src/ir-to-client-js/index.ts +7 -2
- package/src/ir-to-client-js/utils.ts +81 -7
- package/src/nullable-signal-attr.ts +38 -6
- package/src/scope/binding-scope.ts +19 -0
- package/src/types.ts +7 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type { AttrValue, FlatMapCallback, IRAttribute, IRElement, IRExpression, IRNode, IRProp, MapCallbackPreamble } from '../types.ts'
|
|
6
6
|
import { isBooleanAttr } from '../html-constants.ts'
|
|
7
|
-
import { toHtmlAttrName, attrValueToString, quotePropName, PROPS_PARAM, DATA_BF_PH, keyAttrName, loopStartMarker, loopEndMarker, loopItemMarker, freeIdsFromRefs, setIntersects, wrapExprWithLoopParams } from './utils.ts'
|
|
7
|
+
import { toHtmlAttrName, attrValueToString, quotePropName, PROPS_PARAM, DATA_BF_PH, keyAttrName, loopStartMarker, loopEndMarker, loopItemMarker, freeIdsFromRefs, setIntersects, wrapExprWithLoopParams, specsInsideRow } from './utils.ts'
|
|
8
8
|
import type { LoopParamSpec } from './utils.ts'
|
|
9
9
|
import { nameForRegistryRef } from './component-scope.ts'
|
|
10
10
|
import { assertNever } from './walker.ts'
|
|
@@ -965,7 +965,10 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
965
965
|
// Increment loopDepth so inner key attrs become data-key-N
|
|
966
966
|
// Forward loopParams so expressions referencing outer/inner loop params
|
|
967
967
|
// get wrapped as signal accessors (e.g., task.title → task().title).
|
|
968
|
-
|
|
968
|
+
// Inside the row, a name the row rebinds is no longer an enclosing
|
|
969
|
+
// loop's binding (#3394).
|
|
970
|
+
const rowLoopParams = specsInsideRow(loopParams, node)
|
|
971
|
+
const innerRecurse = (n: IRNode): string => irToHtmlTemplate(n, restSpreadNames, loopDepth + 1, rowLoopParams, branchSlotsVar)
|
|
969
972
|
let childTemplate = node.children.map(innerRecurse).join('')
|
|
970
973
|
// Whole-item conditional loops (#1665): prepend an always-present
|
|
971
974
|
// `<!--bf-loop-i:KEY-->` anchor before each item's (possibly empty)
|
|
@@ -1001,13 +1004,13 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
1001
1004
|
// `mapArray` stamps on adoption/creation, so SSR, hydrate template and
|
|
1002
1005
|
// csr-mount agree on it (see `leafKeyAsDataKeyAttr`).
|
|
1003
1006
|
const body = renderPreamble(node.flatMapCallback, {
|
|
1004
|
-
renderLeaf: (ir) => irToHtmlTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1,
|
|
1007
|
+
renderLeaf: (ir) => irToHtmlTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1, rowLoopParams, branchSlotsVar),
|
|
1005
1008
|
})
|
|
1006
1009
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, 'flatMap', node.flatMapCallback.params, body))
|
|
1007
1010
|
} else if (node.preamble) {
|
|
1008
1011
|
// Stage 3 / D4 — render JSX leaves in an arbitrary array-builder
|
|
1009
1012
|
// preamble (the hydrate-template context uses the bare loop param).
|
|
1010
|
-
const preamble = renderPreamble(node.preamble, { textVariant: 'client', renderLeaf: (ir) => irToHtmlTemplate(ir, restSpreadNames, loopDepth + 1,
|
|
1013
|
+
const preamble = renderPreamble(node.preamble, { textVariant: 'client', renderLeaf: (ir) => irToHtmlTemplate(ir, restSpreadNames, loopDepth + 1, rowLoopParams, branchSlotsVar) })
|
|
1011
1014
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, iterMethod, callbackParam, `{ ${preamble} return \`${childTemplate}\` }`))
|
|
1012
1015
|
} else {
|
|
1013
1016
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, iterMethod, callbackParam, `\`${childTemplate}\``))
|
|
@@ -1455,7 +1458,10 @@ export function irToPlaceholderTemplate(node: IRNode, restSpreadNames?: Readonly
|
|
|
1455
1458
|
case 'loop': {
|
|
1456
1459
|
// Inner loops: generate inline .map().join('') with placeholders for components
|
|
1457
1460
|
// Forward loopParams so inner loop param expressions get wrapped as signal accessors.
|
|
1458
|
-
|
|
1461
|
+
// Inside the row, a name the row rebinds is no longer an enclosing
|
|
1462
|
+
// loop's binding (#3394).
|
|
1463
|
+
const rowLoopParams = specsInsideRow(loopParams, node)
|
|
1464
|
+
const innerRecurse = (n: IRNode): string => irToPlaceholderTemplate(n, restSpreadNames, loopDepth + 1, rowLoopParams)
|
|
1459
1465
|
const childTemplate = node.children.map(innerRecurse).join('')
|
|
1460
1466
|
const indexParam = node.index ? `, ${node.index}` : ''
|
|
1461
1467
|
// Apply sort / filter chain (#1448 Tier B) — same shape as the
|
|
@@ -1468,12 +1474,12 @@ export function irToPlaceholderTemplate(node: IRNode, restSpreadNames?: Readonly
|
|
|
1468
1474
|
if (node.flatMapCallback) {
|
|
1469
1475
|
const body = renderPreamble(node.flatMapCallback, {
|
|
1470
1476
|
// Leaf `key` → `data-key` — see the irToHtmlTemplate site above.
|
|
1471
|
-
renderLeaf: (ir) => irToPlaceholderTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1,
|
|
1477
|
+
renderLeaf: (ir) => irToPlaceholderTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1, rowLoopParams),
|
|
1472
1478
|
})
|
|
1473
1479
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, 'flatMap', node.flatMapCallback.params, body))
|
|
1474
1480
|
} else if (node.preamble) {
|
|
1475
1481
|
// Stage 3 / D4 — render JSX leaves in an arbitrary array-builder preamble.
|
|
1476
|
-
const preamble = renderPreamble(node.preamble, { textVariant: 'client', renderLeaf: (ir) => irToPlaceholderTemplate(ir, restSpreadNames, loopDepth + 1,
|
|
1482
|
+
const preamble = renderPreamble(node.preamble, { textVariant: 'client', renderLeaf: (ir) => irToPlaceholderTemplate(ir, restSpreadNames, loopDepth + 1, rowLoopParams) })
|
|
1477
1483
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, iterMethod, callbackParam, `{ ${preamble} return \`${childTemplate}\` }`))
|
|
1478
1484
|
} else {
|
|
1479
1485
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, iterMethod, callbackParam, `\`${childTemplate}\``))
|
|
@@ -16,7 +16,7 @@ import { buildReferencesGraph, graphUsedIdentifiers } from './build-references.t
|
|
|
16
16
|
import { addConstantPropRefsToSet } from './init-declarations.ts'
|
|
17
17
|
import { canGenerateStaticTemplate, irToComponentTemplate, generateCsrTemplate } from './html-template.ts'
|
|
18
18
|
import { markupSlotIdsOf } from './markup-slots.ts'
|
|
19
|
-
import { PROPS_PARAM, initFunctionName, componentDefScopeFlags } from './utils.ts'
|
|
19
|
+
import { PROPS_PARAM, initFunctionName, componentDefScopeFlags, isTransparentFragmentRoot } from './utils.ts'
|
|
20
20
|
import { buildInlinableConstants, csrInlinableConstantsFromCtx } from './emit-registration.ts'
|
|
21
21
|
import { buildEnvFromCtx } from './compute-inlinability.ts'
|
|
22
22
|
import { nameForRegistryRef, buildImportAliasMap, setActiveImportAliases } from './component-scope.ts'
|
|
@@ -367,7 +367,12 @@ function generateTemplateOnlyMount(ir: ComponentIR, ctx: ClientJsContext): strin
|
|
|
367
367
|
// uses — a fragment-rooted stateless child must declare `comment` /
|
|
368
368
|
// `fragmentRoot` too, or `renderChild()` stamps `bf-s` onto its first
|
|
369
369
|
// element while SSR scopes it with a comment pair.
|
|
370
|
-
|
|
370
|
+
// A stateless transparent root (`<>{children}</>`) owns no scope at all —
|
|
371
|
+
// SSR renders the caller's content unmarked — so `renderChild()` must not
|
|
372
|
+
// stamp one either (#3355). Only the template-only path declares it: a
|
|
373
|
+
// stateful child still needs a scope for its init to bind against.
|
|
374
|
+
const transparentFlag = isTransparentFragmentRoot(ir.root) ? ['transparent: true'] : []
|
|
375
|
+
const scopeFlags = [...componentDefScopeFlags(ir.root), ...transparentFlag].map((f) => `, ${f}`).join('')
|
|
371
376
|
lines.push(`hydrate('${registryKey}', { init: ${initName}, template: (${PROPS_PARAM}) => \`${templateHtml}\`${scopeFlags}${nameField} })`)
|
|
372
377
|
// See `emitRegistrationAndHydration` (./emit-registration.ts) for the
|
|
373
378
|
// rationale on why the component is also emitted as a callable
|
|
@@ -7,6 +7,7 @@ import ts from 'typescript'
|
|
|
7
7
|
import type { AttrValue, IRTemplatePart, LoopParamBinding, FreeReference, IRNode, IRFragment, ComponentIR } from '../types.ts'
|
|
8
8
|
import type { TopLevelLoop, BranchLoop, LoopOffset } from './types.ts'
|
|
9
9
|
import { isNonReferenceIdentifierPosition } from '../analyzer.ts'
|
|
10
|
+
import { BindingScope, type LoopBindingSource } from '../scope/binding-scope.ts'
|
|
10
11
|
import { buildLoopChainExpr } from '../loop-chain.ts'
|
|
11
12
|
import { templatePartsToJsExpr } from '../template-parts.ts'
|
|
12
13
|
import {
|
|
@@ -96,6 +97,16 @@ export function isScopeCommentFragmentRoot(root: ComponentIR['root']): boolean {
|
|
|
96
97
|
return root.type === 'fragment' && !!(root as IRFragment).needsScopeComment
|
|
97
98
|
}
|
|
98
99
|
|
|
100
|
+
/**
|
|
101
|
+
* True for a transparent fragment root (`<>{children}</>`). SSR renders it
|
|
102
|
+
* with no scope marker of any kind, so a stateless component of this shape
|
|
103
|
+
* declares `transparent: true` and `renderChild()` emits its markup as-is
|
|
104
|
+
* (#3355).
|
|
105
|
+
*/
|
|
106
|
+
export function isTransparentFragmentRoot(root: ComponentIR['root']): boolean {
|
|
107
|
+
return root.type === 'fragment' && !!(root as IRFragment).transparent
|
|
108
|
+
}
|
|
109
|
+
|
|
99
110
|
/**
|
|
100
111
|
* The scope-shape flags (`comment: true` / `fragmentRoot: true`) a
|
|
101
112
|
* component's `hydrate()` def declares — the ONE answer both registration
|
|
@@ -655,7 +666,7 @@ function scanForIdentifiers(expr: string, predicate: (token: string) => boolean)
|
|
|
655
666
|
* native array method (no runtime helper required).
|
|
656
667
|
*/
|
|
657
668
|
function renderLoopBindingAccess(b: LoopParamBinding, base: string): string {
|
|
658
|
-
const parent = `${base}${b.path}`
|
|
669
|
+
const parent = `${b.accessor ?? base}${b.path}`
|
|
659
670
|
if (b.rest?.kind === 'object') {
|
|
660
671
|
if (b.rest.exclude.length === 0) {
|
|
661
672
|
// No sibling keys to omit. A fresh shallow clone — not a direct alias
|
|
@@ -714,19 +725,48 @@ export function wrapLoopParamAsAccessor(
|
|
|
714
725
|
paramName: string,
|
|
715
726
|
bindings?: readonly LoopParamBinding[],
|
|
716
727
|
indexParam?: string | null,
|
|
728
|
+
shadowed?: ReadonlySet<string>,
|
|
717
729
|
): string {
|
|
730
|
+
// `shadowed`: names a nearer row rebinds (`rowBoundNames`), so inside that
|
|
731
|
+
// row they mean the nearer binding and keep their plain spelling (#3394).
|
|
732
|
+
const destructured = !!bindings && bindings.length > 0
|
|
733
|
+
const liveBindings = destructured && shadowed ? bindings.filter(b => !shadowed.has(b.name)) : bindings
|
|
734
|
+
const liveIndex = indexParam && shadowed?.has(indexParam) ? null : indexParam
|
|
718
735
|
let result: string
|
|
719
|
-
if (
|
|
720
|
-
result = rewriteLoopBindingRefs(expr,
|
|
736
|
+
if (destructured) {
|
|
737
|
+
result = liveBindings && liveBindings.length > 0 ? rewriteLoopBindingRefs(expr, liveBindings, '__bfItem()') : expr
|
|
721
738
|
} else {
|
|
722
|
-
result = rewriteIdentifierAsAccessor(expr, paramName)
|
|
739
|
+
result = shadowed?.has(paramName) ? expr : rewriteIdentifierAsAccessor(expr, paramName)
|
|
723
740
|
}
|
|
724
|
-
if (
|
|
725
|
-
result = wrapIndexParamAsAccessor(result,
|
|
741
|
+
if (liveIndex && liveIndex !== paramName) {
|
|
742
|
+
result = wrapIndexParamAsAccessor(result, liveIndex)
|
|
726
743
|
}
|
|
727
744
|
return result
|
|
728
745
|
}
|
|
729
746
|
|
|
747
|
+
/**
|
|
748
|
+
* A loop-param accessor rewrite that can be told which names a nearer row
|
|
749
|
+
* rebinds (#3394). Each wrap passes `shadowed` on to the enclosing loops'
|
|
750
|
+
* wraps it composes, so every ancestor rewrite skips them too.
|
|
751
|
+
*/
|
|
752
|
+
export type ShadowableWrap = (expr: string, shadowed?: ReadonlySet<string>) => string
|
|
753
|
+
|
|
754
|
+
/** `a` and `b` together; `a` alone when `b` is empty or absent. */
|
|
755
|
+
export function unionNames(a: ReadonlySet<string>, b?: ReadonlySet<string>): ReadonlySet<string> {
|
|
756
|
+
return b && b.size > 0 ? new Set([...a, ...b]) : a
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Every name the row of `loop` binds — its item (or destructure bindings),
|
|
761
|
+
* index and preamble locals — via `BindingScope.enterLoopRow`. Inside that
|
|
762
|
+
* row an enclosing loop's accessor rewrite must skip these names, or an
|
|
763
|
+
* inner `const name = …` that shadows an outer destructure binding becomes
|
|
764
|
+
* `const __bfItem().name = …` (#3394).
|
|
765
|
+
*/
|
|
766
|
+
export function rowBoundNames(loop: LoopBindingSource): ReadonlySet<string> {
|
|
767
|
+
return BindingScope.EMPTY.enterLoopRow(loop).boundNames()
|
|
768
|
+
}
|
|
769
|
+
|
|
730
770
|
/**
|
|
731
771
|
* The index-only half of `wrapLoopParamAsAccessor` — same AST-aware
|
|
732
772
|
* identifier rewrite (`rewriteIdentifierAsAccessor`), own identifier.
|
|
@@ -962,6 +1002,8 @@ export interface LoopParamSpec {
|
|
|
962
1002
|
bindings?: readonly LoopParamBinding[]
|
|
963
1003
|
/** This loop's index parameter name, when it declares one (#2859). */
|
|
964
1004
|
index?: string | null
|
|
1005
|
+
/** Names a nearer row rebinds, left as written (#3394). */
|
|
1006
|
+
shadowed?: ReadonlySet<string>
|
|
965
1007
|
}
|
|
966
1008
|
|
|
967
1009
|
/**
|
|
@@ -991,8 +1033,40 @@ export function wrapExprWithLoopParams(expr: string, loopParams?: ReadonlyArray<
|
|
|
991
1033
|
let result = expr
|
|
992
1034
|
for (const p of loopParams) {
|
|
993
1035
|
const spec = typeof p === 'string' ? { param: p } : p
|
|
994
|
-
result = wrapLoopParamAsAccessor(result, spec.param, spec.bindings, spec.index)
|
|
1036
|
+
result = wrapLoopParamAsAccessor(result, spec.param, spec.bindings, spec.index, spec.shadowed)
|
|
995
1037
|
}
|
|
996
1038
|
return result
|
|
997
1039
|
}
|
|
998
1040
|
|
|
1041
|
+
/**
|
|
1042
|
+
* Enclosing loop specs as seen inside the row of `loop`: each spec also
|
|
1043
|
+
* skips the names that row rebinds (`rowBoundNames`, #3394).
|
|
1044
|
+
*/
|
|
1045
|
+
export function specsInsideRow(
|
|
1046
|
+
specs: ReadonlyArray<string | LoopParamSpec> | undefined,
|
|
1047
|
+
loop: LoopBindingSource,
|
|
1048
|
+
): ReadonlyArray<string | LoopParamSpec> | undefined {
|
|
1049
|
+
if (!specs) return specs
|
|
1050
|
+
const names = rowBoundNames(loop)
|
|
1051
|
+
if (names.size === 0) return specs
|
|
1052
|
+
return specs.map(p => {
|
|
1053
|
+
const spec = typeof p === 'string' ? { param: p } : p
|
|
1054
|
+
const shadowed = spec.shadowed ? new Set([...spec.shadowed, ...names]) : names
|
|
1055
|
+
return { ...spec, shadowed }
|
|
1056
|
+
})
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* The bindings of a nested destructured `.map()` row, each reading through
|
|
1061
|
+
* the row's own accessor `__bfItem_<markerId>()` (#3397). Every nested row
|
|
1062
|
+
* then names its render callback's item accessor differently, so a row
|
|
1063
|
+
* inside another destructured row can still read the outer row's bindings.
|
|
1064
|
+
*/
|
|
1065
|
+
export function withRowAccessor(
|
|
1066
|
+
bindings: readonly LoopParamBinding[] | undefined,
|
|
1067
|
+
markerId: string,
|
|
1068
|
+
): readonly LoopParamBinding[] | undefined {
|
|
1069
|
+
if (!bindings || bindings.length === 0) return bindings
|
|
1070
|
+
const accessor = `__bfItem_${markerId}()`
|
|
1071
|
+
return bindings.map(b => ({ ...b, accessor }))
|
|
1072
|
+
}
|
|
@@ -84,6 +84,10 @@ export interface NullishAttrContext {
|
|
|
84
84
|
/** Signals seeded with a literal `null`: their SSR value is `null`, not
|
|
85
85
|
* `undefined` (`arithmeticOperandIsNull`). */
|
|
86
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>
|
|
87
91
|
readonly memos: ReadonlyMap<string, MemoInfo>
|
|
88
92
|
}
|
|
89
93
|
|
|
@@ -94,6 +98,9 @@ export function collectNullishAttrContext(ir: ComponentIR): NullishAttrContext {
|
|
|
94
98
|
nullSeededSignals: new Set(
|
|
95
99
|
signals.filter(s => s.parsed?.kind === 'literal' && s.parsed.literalType === 'null').map(s => s.getter),
|
|
96
100
|
),
|
|
101
|
+
undefinedSeededSignals: new Set(
|
|
102
|
+
signals.filter(s => s.parsed?.kind === 'identifier' && s.parsed.name === 'undefined').map(s => s.getter),
|
|
103
|
+
),
|
|
97
104
|
memos: new Map((ir.metadata.memos ?? []).map(m => [m.name, m])),
|
|
98
105
|
}
|
|
99
106
|
}
|
|
@@ -176,20 +183,45 @@ export function arithmeticOperandIsNull(
|
|
|
176
183
|
ctx: NullishAttrContext,
|
|
177
184
|
isShadowed: (name: string) => boolean = () => false,
|
|
178
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 {
|
|
179
209
|
const visiting = new Set<string>()
|
|
180
|
-
const walk = (expr: ParsedExpr, shadowed: (name: string) => boolean):
|
|
181
|
-
if (expr.kind === 'literal') return expr.literalType === 'null'
|
|
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'
|
|
182
213
|
const getter = expr.kind === 'identifier' ? expr.name : bareGetterCallName(expr)
|
|
183
|
-
if (getter === null || shadowed(getter)) return
|
|
184
|
-
if (ctx.nullSeededSignals?.has(getter)) return
|
|
214
|
+
if (getter === null || shadowed(getter)) return null
|
|
215
|
+
if (ctx.nullSeededSignals?.has(getter)) return 'null'
|
|
216
|
+
if (ctx.undefinedSeededSignals?.has(getter)) return 'undefined'
|
|
185
217
|
const memo = ctx.memos.get(getter)
|
|
186
|
-
if (!memo?.parsed || visiting.has(getter)) return
|
|
218
|
+
if (!memo?.parsed || visiting.has(getter)) return null
|
|
187
219
|
visiting.add(getter)
|
|
188
220
|
const result = walk(memo.parsed, () => false)
|
|
189
221
|
visiting.delete(getter)
|
|
190
222
|
return result
|
|
191
223
|
}
|
|
192
|
-
return parsed
|
|
224
|
+
return parsed === undefined ? null : walk(parsed, isShadowed)
|
|
193
225
|
}
|
|
194
226
|
|
|
195
227
|
/**
|
|
@@ -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 {
|