@barefootjs/jsx 0.39.7 → 0.39.8
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/callback-method.d.ts +17 -0
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +80 -13
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +151 -0
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -0
- package/dist/adapters/jsx-adapter.d.ts +4 -0
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/adapters/literal-value.d.ts +2 -2
- package/dist/adapters/literal-value.d.ts.map +1 -1
- package/dist/adapters/parsed-expr-emitter.d.ts +27 -0
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/style-object.d.ts +33 -0
- package/dist/adapters/style-object.d.ts.map +1 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/children-nullish.d.ts +22 -0
- package/dist/children-nullish.d.ts.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +9 -19
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/free-refs.d.ts +6 -0
- package/dist/free-refs.d.ts.map +1 -1
- package/dist/index.d.ts +14 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14685 -14000
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts +2 -1
- package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -2
- package/dist/ir-to-client-js/control-flow/plan/insert.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/event-listener.d.ts +10 -9
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-registration.d.ts +10 -8
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +0 -9
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/identifiers.d.ts +6 -8
- package/dist/ir-to-client-js/identifiers.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +23 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -2
- package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +1 -1
- package/dist/ir-to-client-js/rewrite-destructured-props.d.ts.map +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts +20 -2
- package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +3 -3
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +2 -11
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +40 -10
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/prop-rewrite.d.ts +18 -0
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +9 -1
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/scanner/js-scanner.d.ts.map +1 -1
- package/dist/scanner/js-scanner.js +30 -2
- package/dist/signal-prop-name-collision.d.ts +6 -5
- package/dist/signal-prop-name-collision.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +28 -0
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +39 -14
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/types.d.ts +108 -18
- package/dist/types.d.ts.map +1 -1
- package/dist/value-references.d.ts +21 -0
- package/dist/value-references.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +18 -18
- package/src/__tests__/adapter-output.test.ts +5 -3
- package/src/__tests__/analyzer.test.ts +33 -0
- package/src/__tests__/arithmetic-lowering.test.ts +44 -0
- package/src/__tests__/children-read.test.ts +226 -0
- package/src/__tests__/client-template-escape-soundness.test.ts +31 -1
- package/src/__tests__/component-props.test.ts +68 -1
- package/src/__tests__/constant-inlining-tree.test.ts +136 -0
- package/src/__tests__/destructure-default-reads-earlier-param.test.ts +138 -0
- package/src/__tests__/dsl-template-adapter.test.ts +173 -0
- package/src/__tests__/event-handler-verbatim.test.ts +73 -0
- package/src/__tests__/expression-parser.test.ts +1 -44
- package/src/__tests__/nullable-signal-attr.test.ts +67 -3
- package/src/__tests__/reference-graph-identifiers.test.ts +161 -0
- package/src/__tests__/runtime-import-detection.test.ts +134 -0
- package/src/__tests__/signal-prop-name-collision.test.ts +30 -0
- package/src/__tests__/ssr-defaults.test.ts +19 -1
- package/src/__tests__/ssr-seed-plan.test.ts +119 -0
- package/src/__tests__/style-object-plan.test.ts +54 -0
- package/src/__tests__/zero-param-helper-inline.test.ts +57 -0
- package/src/adapters/callback-method.ts +23 -0
- package/src/adapters/component-props.ts +130 -12
- package/src/adapters/dsl-template-adapter.ts +248 -0
- package/src/adapters/jsx-adapter.ts +12 -6
- package/src/adapters/literal-value.ts +2 -2
- package/src/adapters/parsed-expr-emitter.ts +34 -0
- package/src/adapters/style-object.ts +61 -0
- package/src/analyzer.ts +114 -15
- package/src/children-nullish.ts +33 -0
- package/src/debug.ts +2 -2
- package/src/errors.ts +12 -0
- package/src/expression-parser.ts +56 -53
- package/src/free-refs.ts +28 -17
- package/src/index.ts +18 -8
- package/src/ir-to-client-js/compute-inlinability.ts +29 -2
- package/src/ir-to-client-js/control-flow/plan/event-collision.ts +2 -1
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +3 -2
- package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +13 -12
- package/src/ir-to-client-js/csr-substitute.ts +12 -2
- package/src/ir-to-client-js/emit-reactive.ts +2 -2
- package/src/ir-to-client-js/emit-registration.ts +28 -57
- package/src/ir-to-client-js/generate-init.ts +17 -1
- package/src/ir-to-client-js/html-template.ts +30 -50
- package/src/ir-to-client-js/identifiers.ts +75 -24
- package/src/ir-to-client-js/imports.ts +56 -19
- package/src/ir-to-client-js/index.ts +2 -1
- package/src/ir-to-client-js/phases/event-handlers.ts +2 -2
- package/src/ir-to-client-js/phases/props-extraction.ts +16 -15
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +2 -2
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +7 -4
- package/src/ir-to-client-js/reactivity.ts +2 -2
- package/src/ir-to-client-js/rewrite-destructured-props.ts +21 -4
- package/src/ir-to-client-js/safe-html.ts +29 -35
- package/src/ir-to-client-js/types.ts +3 -2
- package/src/ir-to-client-js/utils.ts +2 -26
- package/src/jsx-to-ir.ts +279 -78
- package/src/nullable-signal-attr.ts +149 -33
- package/src/prop-rewrite.ts +41 -0
- package/src/props-binding.ts +17 -2
- package/src/scanner/__tests__/js-scanner.test.ts +37 -0
- package/src/scanner/js-scanner.ts +64 -4
- package/src/signal-prop-name-collision.ts +50 -24
- package/src/ssr-defaults.ts +47 -20
- package/src/ssr-seed-plan.ts +103 -23
- package/src/types.ts +115 -19
- package/src/value-references.ts +132 -0
package/src/analyzer.ts
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
import ts from 'typescript'
|
|
10
10
|
import { foldRenderReassignmentsInSource } from './fold-render-reassignments.ts'
|
|
11
11
|
import { CLIENT_DIRECTIVE_INTERIOR_RE, USE_CLIENT_DIRECTIVE, isUseClientDirectiveText } from './directives.ts'
|
|
12
|
-
import type { ImportSpecifier, TypeInfo, ParamInfo, ReactiveFactoryInfo, DeclinedReactiveFactory, RequiredFactoryImport, FactoryRenameSite, SourceLocation, SignalFactoryCall, MemoInfo } from './types.ts'
|
|
12
|
+
import type { ImportSpecifier, TypeInfo, ParamInfo, PropDefaultPart, PropDefaultRead, ReactiveFactoryInfo, DeclinedReactiveFactory, RequiredFactoryImport, FactoryRenameSite, SourceLocation, SignalFactoryCall, MemoInfo } from './types.ts'
|
|
13
13
|
import { parseExpression, parseBlockBodyTolerant, foldBlockToExpr, tsNodeToParsedExpr, stringifyParsedExpr, type ParsedExpr } from './expression-parser.ts'
|
|
14
14
|
import type { CallbackBodyAcceptor } from './adapters/interface.ts'
|
|
15
|
-
import { rewriteBarePropRefs } from './prop-rewrite.ts'
|
|
16
|
-
import { buildPropAliasMap, coalesceDefaultText, signalPropSeed } from './props-binding.ts'
|
|
15
|
+
import { rewriteBarePropRefs, splitScopedValueRefs } from './prop-rewrite.ts'
|
|
16
|
+
import { buildPropAliasMap, coalesceDefaultText, livePropReadExpr, signalPropSeed } from './props-binding.ts'
|
|
17
17
|
import { incrementCounter } from './instrumentation.ts'
|
|
18
18
|
import {
|
|
19
19
|
type AnalyzerContext,
|
|
@@ -33,7 +33,7 @@ import { CATALOGUED_RICH_TYPE_NAMES } from './date-lowering.ts'
|
|
|
33
33
|
import path from 'node:path'
|
|
34
34
|
import fs from 'node:fs'
|
|
35
35
|
import { signalSecondBinding } from './signal-initializer.ts'
|
|
36
|
-
import {
|
|
36
|
+
import { separateSignalPropBindings, programWithSeparatedSource } from './signal-prop-name-collision.ts'
|
|
37
37
|
|
|
38
38
|
// =============================================================================
|
|
39
39
|
// TypeScript Program Creation
|
|
@@ -399,7 +399,7 @@ export function analyzeComponent(
|
|
|
399
399
|
// so imported signals are covered too.
|
|
400
400
|
for (const signal of ctx.signals) parseSignalInitializer(signal, ctx)
|
|
401
401
|
|
|
402
|
-
const separatedSource =
|
|
402
|
+
const separatedSource = separateSignalPropBindings(ctx, isNonReferenceIdentifierPosition)
|
|
403
403
|
if (separatedSource !== null) {
|
|
404
404
|
// The checker supplied by the caller names the old AST. Re-analyze the
|
|
405
405
|
// structurally renamed source, preserving the shared-program contract
|
|
@@ -502,10 +502,13 @@ function collectNamedExports(sourceFile: ts.SourceFile): Set<string> {
|
|
|
502
502
|
* declarations of a module-level `const f = (…) => { … }` were collected
|
|
503
503
|
* as module-level declarations of the FILE — hoisted into the init body
|
|
504
504
|
* and into the marked template, where their references to the helper's
|
|
505
|
-
* own parameters are unbound (#2986).
|
|
505
|
+
* own parameters are unbound (#2986). A class static block is its own scope
|
|
506
|
+
* too: `class { static { var $ } }` declares `$` in the block, not in the
|
|
507
|
+
* component body.
|
|
506
508
|
*/
|
|
507
509
|
function isFunctionScope(node: ts.Node): boolean {
|
|
508
|
-
return ts.
|
|
510
|
+
return ts.isClassStaticBlockDeclaration(node)
|
|
511
|
+
|| ts.isArrowFunction(node)
|
|
509
512
|
|| ts.isFunctionExpression(node)
|
|
510
513
|
|| ts.isFunctionDeclaration(node)
|
|
511
514
|
|| ts.isMethodDeclaration(node)
|
|
@@ -1535,7 +1538,7 @@ function collectSignal(node: ts.VariableDeclaration, ctx: AnalyzerContext): void
|
|
|
1535
1538
|
const propNames = new Set(ctx.propsParams.map(p => p.name))
|
|
1536
1539
|
if (propNames.size > 0) {
|
|
1537
1540
|
const propAliases = buildPropAliasMap(ctx.propsParams)
|
|
1538
|
-
templateInitialValue = rewriteBarePropRefs(initialValue, callExpr.arguments[0], propNames, undefined, propAliases)
|
|
1541
|
+
templateInitialValue = rewriteBarePropRefs(initialValue, callExpr.arguments[0], propNames, undefined, propAliases, destructuredPropTemplateRead(ctx))
|
|
1539
1542
|
}
|
|
1540
1543
|
}
|
|
1541
1544
|
|
|
@@ -1627,7 +1630,7 @@ function collectFactorySignal(
|
|
|
1627
1630
|
const propNames = new Set(ctx.propsParams.map(p => p.name))
|
|
1628
1631
|
if (propNames.size > 0) {
|
|
1629
1632
|
const propAliases = buildPropAliasMap(ctx.propsParams)
|
|
1630
|
-
templateInitialValue = rewriteBarePropRefs(initialValue, initialNode.node, propNames, undefined, propAliases)
|
|
1633
|
+
templateInitialValue = rewriteBarePropRefs(initialValue, initialNode.node, propNames, undefined, propAliases, destructuredPropTemplateRead(ctx))
|
|
1631
1634
|
}
|
|
1632
1635
|
}
|
|
1633
1636
|
|
|
@@ -2080,7 +2083,7 @@ function memoBodyFields(
|
|
|
2080
2083
|
const propNames = new Set(ctx.propsParams.map(p => p.name))
|
|
2081
2084
|
if (propNames.size > 0) {
|
|
2082
2085
|
const propAliases = buildPropAliasMap(ctx.propsParams)
|
|
2083
|
-
const rewritten = rewriteBarePropRefs(ctx.getJS(body.node), body.node, propNames, undefined, propAliases)
|
|
2086
|
+
const rewritten = rewriteBarePropRefs(ctx.getJS(body.node), body.node, propNames, undefined, propAliases, destructuredPropTemplateRead(ctx))
|
|
2084
2087
|
templateBodyExpr = rewritten === undefined ? undefined : asBodyExpr(rewritten)
|
|
2085
2088
|
}
|
|
2086
2089
|
}
|
|
@@ -2780,15 +2783,34 @@ function collectTypeAliasDefinition(
|
|
|
2780
2783
|
const properties = ts.isTypeLiteralNode(node.type)
|
|
2781
2784
|
? membersToProperties(node.type.members, ctx.sourceFile)
|
|
2782
2785
|
: undefined
|
|
2786
|
+
const stringLiteralUnion = stringLiteralMembers(node.type)
|
|
2783
2787
|
ctx.typeDefinitions.push({
|
|
2784
2788
|
kind: 'type',
|
|
2785
2789
|
name: node.name.text,
|
|
2786
2790
|
definition: node.getText(ctx.sourceFile),
|
|
2787
2791
|
properties,
|
|
2792
|
+
...(stringLiteralUnion ? { stringLiteralUnion } : {}),
|
|
2788
2793
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
|
|
2789
2794
|
})
|
|
2790
2795
|
}
|
|
2791
2796
|
|
|
2797
|
+
/**
|
|
2798
|
+
* The values of a type that is a string literal or a union of string
|
|
2799
|
+
* literals only, or `undefined` for any other type.
|
|
2800
|
+
*/
|
|
2801
|
+
function stringLiteralMembers(type: ts.TypeNode): string[] | undefined {
|
|
2802
|
+
if (ts.isParenthesizedTypeNode(type)) return stringLiteralMembers(type.type)
|
|
2803
|
+
if (ts.isLiteralTypeNode(type)) return ts.isStringLiteral(type.literal) ? [type.literal.text] : undefined
|
|
2804
|
+
if (!ts.isUnionTypeNode(type)) return undefined
|
|
2805
|
+
const values: string[] = []
|
|
2806
|
+
for (const member of type.types) {
|
|
2807
|
+
const nested = stringLiteralMembers(member)
|
|
2808
|
+
if (!nested) return undefined
|
|
2809
|
+
values.push(...nested)
|
|
2810
|
+
}
|
|
2811
|
+
return values
|
|
2812
|
+
}
|
|
2813
|
+
|
|
2792
2814
|
// =============================================================================
|
|
2793
2815
|
// Function Collection
|
|
2794
2816
|
// =============================================================================
|
|
@@ -3641,6 +3663,18 @@ function getSystemConstructKind(node: ts.Node): 'createContext' | 'weakMap' | un
|
|
|
3641
3663
|
return undefined
|
|
3642
3664
|
}
|
|
3643
3665
|
|
|
3666
|
+
/**
|
|
3667
|
+
* The CSR `template:` read of a destructured prop a signal seed or memo body
|
|
3668
|
+
* names (#2265): the live read every client site shares
|
|
3669
|
+
* (`livePropReadExpr`), so the module-scope arrow applies the prop's
|
|
3670
|
+
* destructure default too, including one that reads an earlier prop
|
|
3671
|
+
* (`{ off = false, on = off }` → `(_p.on ?? (_p.off ?? false))`, #3531).
|
|
3672
|
+
*/
|
|
3673
|
+
function destructuredPropTemplateRead(ctx: AnalyzerContext): (localName: string, callerKey: string) => string {
|
|
3674
|
+
const byName = new Map(ctx.propsParams.filter(p => !p.isRest).map(p => [p.name, p]))
|
|
3675
|
+
return (localName, callerKey) => livePropReadExpr(byName.get(localName) ?? { name: localName, sourceName: callerKey }, undefined, false)
|
|
3676
|
+
}
|
|
3677
|
+
|
|
3644
3678
|
/**
|
|
3645
3679
|
* The default-value-shaped fields a binding element's own `initializer`
|
|
3646
3680
|
* contributes to a `ParamInfo` — `defaultValue`'s source text, `parsed`'s
|
|
@@ -3654,14 +3688,70 @@ function getSystemConstructKind(node: ts.Node): 'createContext' | 'weakMap' | un
|
|
|
3654
3688
|
function bindingElementDefaultFields(
|
|
3655
3689
|
initializer: ts.Expression | undefined,
|
|
3656
3690
|
ctx: AnalyzerContext,
|
|
3657
|
-
|
|
3691
|
+
earlier: ReadonlyMap<string, PropDefaultRead> = new Map(),
|
|
3692
|
+
): Pick<ParamInfo, 'defaultValue' | 'parsed' | 'defaultContainsArrow' | 'defaultParts'> {
|
|
3658
3693
|
const defaultValue = initializer ? ctx.getJS(initializer) : undefined
|
|
3659
3694
|
const defaultContainsArrow = initializer ? nodeContainsArrow(initializer) : false
|
|
3660
3695
|
const parsedDefault = initializer ? tsNodeToParsedExpr(initializer) : undefined
|
|
3696
|
+
const defaultParts = initializer && defaultValue !== undefined
|
|
3697
|
+
? defaultPartsReadingEarlierBindings(initializer, defaultValue, earlier)
|
|
3698
|
+
: undefined
|
|
3661
3699
|
return {
|
|
3662
3700
|
defaultValue,
|
|
3663
3701
|
...(parsedDefault && parsedDefault.kind !== 'unsupported' && { parsed: parsedDefault }),
|
|
3664
3702
|
defaultContainsArrow: defaultContainsArrow || undefined,
|
|
3703
|
+
...(defaultParts && { defaultParts }),
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
/**
|
|
3708
|
+
* A destructure default split at its reads of EARLIER bindings of the same
|
|
3709
|
+
* pattern (`ParamInfo.defaultParts`, #3531), or undefined when it reads none.
|
|
3710
|
+
* JS puts each earlier binding in scope for a later default
|
|
3711
|
+
* (`{ off = false, on = off }`), so a free `off` there is that binding, not an
|
|
3712
|
+
* outer name; a later binding is still in its TDZ and is left alone. The split
|
|
3713
|
+
* runs on the default's JS text with the same scope-aware walk the client
|
|
3714
|
+
* prop rewrite uses, so a nested callback parameter of the same name is not a
|
|
3715
|
+
* read.
|
|
3716
|
+
*/
|
|
3717
|
+
function defaultPartsReadingEarlierBindings(
|
|
3718
|
+
initializer: ts.Expression,
|
|
3719
|
+
defaultValue: string,
|
|
3720
|
+
earlier: ReadonlyMap<string, PropDefaultRead>,
|
|
3721
|
+
): PropDefaultPart[] | undefined {
|
|
3722
|
+
if (earlier.size === 0) return undefined
|
|
3723
|
+
const names = new Set([...extractFreeIdentifiersFromNode(initializer)].filter(n => earlier.has(n)))
|
|
3724
|
+
if (names.size === 0) return undefined
|
|
3725
|
+
const pieces = splitScopedValueRefs(defaultValue, names)
|
|
3726
|
+
if (pieces === null || !pieces.some(p => p.kind === 'ref')) return undefined
|
|
3727
|
+
return pieces.map((piece): PropDefaultPart =>
|
|
3728
|
+
piece.kind === 'text'
|
|
3729
|
+
? { kind: 'text', text: piece.text }
|
|
3730
|
+
: { kind: 'param', param: earlier.get(piece.name)! },
|
|
3731
|
+
)
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3734
|
+
/** {@link propDefaultReadOf} for a body destructure's binding (`const { label: text = 'x' } = props`). */
|
|
3735
|
+
function bodyBindingRead(
|
|
3736
|
+
localName: string,
|
|
3737
|
+
sourceKey: string,
|
|
3738
|
+
defaultFields: Pick<ParamInfo, 'defaultValue' | 'defaultContainsArrow' | 'defaultParts'> | undefined,
|
|
3739
|
+
): PropDefaultRead {
|
|
3740
|
+
return propDefaultReadOf({
|
|
3741
|
+
name: localName,
|
|
3742
|
+
...(sourceKey !== localName && { sourceName: sourceKey }),
|
|
3743
|
+
...defaultFields,
|
|
3744
|
+
})
|
|
3745
|
+
}
|
|
3746
|
+
|
|
3747
|
+
/** The fields a later default's `param` part needs to read `p` (`PropDefaultRead`). */
|
|
3748
|
+
function propDefaultReadOf(p: PropDefaultRead): PropDefaultRead {
|
|
3749
|
+
return {
|
|
3750
|
+
name: p.name,
|
|
3751
|
+
...(p.sourceName !== undefined && { sourceName: p.sourceName }),
|
|
3752
|
+
...(p.defaultValue !== undefined && { defaultValue: p.defaultValue }),
|
|
3753
|
+
...(p.defaultContainsArrow && { defaultContainsArrow: p.defaultContainsArrow }),
|
|
3754
|
+
...(p.defaultParts && { defaultParts: p.defaultParts }),
|
|
3665
3755
|
}
|
|
3666
3756
|
}
|
|
3667
3757
|
|
|
@@ -3688,6 +3778,9 @@ function collectConstant(
|
|
|
3688
3778
|
ctx.propsObjectName === node.initializer.text
|
|
3689
3779
|
) {
|
|
3690
3780
|
const propsName = node.initializer.text
|
|
3781
|
+
// Bindings already destructured by this pattern, by local name: a later
|
|
3782
|
+
// default reads them (`const { off = false, on = off } = props`, #3531).
|
|
3783
|
+
const earlier = new Map<string, PropDefaultRead>()
|
|
3691
3784
|
for (const el of node.name.elements) {
|
|
3692
3785
|
if (!ts.isBindingElement(el) || !ts.isIdentifier(el.name) || el.dotDotDotToken) continue
|
|
3693
3786
|
const localName = el.name.text
|
|
@@ -3695,7 +3788,8 @@ function collectConstant(
|
|
|
3695
3788
|
// Shared with the #2943 `ParamInfo` overlay below so "what does this
|
|
3696
3789
|
// default look like" (source text, `defaultContainsArrow`) has one
|
|
3697
3790
|
// computation, not two independently-drifting ones.
|
|
3698
|
-
const defaultFields = el.initializer ? bindingElementDefaultFields(el.initializer, ctx) : undefined
|
|
3791
|
+
const defaultFields = el.initializer ? bindingElementDefaultFields(el.initializer, ctx, earlier) : undefined
|
|
3792
|
+
earlier.set(localName, bodyBindingRead(localName, sourceKey, defaultFields))
|
|
3699
3793
|
const baseValue = `${propsName}.${sourceKey}`
|
|
3700
3794
|
// Parenthesize an arrow/function-expression default (#2940) — `??`
|
|
3701
3795
|
// binds tighter than an arrow head, so a bare `props.fmt ?? (v) =>
|
|
@@ -4045,6 +4139,9 @@ function extractProps(param: ts.ParameterDeclaration, ctx: AnalyzerContext): voi
|
|
|
4045
4139
|
// `props: Props` path instead of degrading to `unknown` (which typed
|
|
4046
4140
|
// adapters emit as `interface{}` + an unchecked assertion). See issue #2150.
|
|
4047
4141
|
const memberTypes = param.type ? collectMemberTypes(param.type, ctx) : null
|
|
4142
|
+
// Bindings already destructured, by local name: a later default reads
|
|
4143
|
+
// them (`{ off = false, on = off }`, #3531).
|
|
4144
|
+
const earlier = new Map<string, PropDefaultRead>()
|
|
4048
4145
|
|
|
4049
4146
|
for (const element of param.name.elements) {
|
|
4050
4147
|
if (ts.isBindingElement(element) && ts.isIdentifier(element.name)) {
|
|
@@ -4065,16 +4162,18 @@ function extractProps(param: ts.ParameterDeclaration, ctx: AnalyzerContext): voi
|
|
|
4065
4162
|
const member = memberTypes?.get(sourcePropName)
|
|
4066
4163
|
const resolvedType: TypeInfo = member?.type ?? { kind: 'unknown', raw: 'unknown' }
|
|
4067
4164
|
|
|
4068
|
-
|
|
4165
|
+
const info: ParamInfo = {
|
|
4069
4166
|
name: localName,
|
|
4070
4167
|
type: resolvedType,
|
|
4071
4168
|
// The type's `?` and a destructure default (`{ x = 1 }`) both mean
|
|
4072
4169
|
// the caller may omit the prop.
|
|
4073
4170
|
optional: !!member?.optional || !!element.initializer,
|
|
4074
|
-
...bindingElementDefaultFields(element.initializer, ctx),
|
|
4171
|
+
...bindingElementDefaultFields(element.initializer, ctx, earlier),
|
|
4075
4172
|
// Only aliased bindings carry the source key — see ParamInfo.sourceName.
|
|
4076
4173
|
...(sourcePropName !== localName && { sourceName: sourcePropName }),
|
|
4077
|
-
}
|
|
4174
|
+
}
|
|
4175
|
+
ctx.propsParams.push(info)
|
|
4176
|
+
earlier.set(localName, propDefaultReadOf(info))
|
|
4078
4177
|
}
|
|
4079
4178
|
}
|
|
4080
4179
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parts of a `??` / `||` read of the children prop, shared by the Phase 1
|
|
3
|
+
* classifier (`IRExpression.childrenRead`, #3539, #3554) and the emitters
|
|
4
|
+
* that splice the children markup and escape only the fallback.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ParsedExpr } from './expression-parser.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Split a left-nested chain of one fallback operator (`??` or `||`) into the
|
|
11
|
+
* value it reads first and the fallback taken when that value is nullish
|
|
12
|
+
* (`??`) or falsy (`||`): `(c ?? x) ?? y` reads `c`, else `x ?? y`, the same
|
|
13
|
+
* as `c ?? (x ?? y)`. `null` when `parsed` is not a `op` chain.
|
|
14
|
+
*/
|
|
15
|
+
export function fallbackChainParts(
|
|
16
|
+
parsed: ParsedExpr,
|
|
17
|
+
op: '??' | '||',
|
|
18
|
+
): { head: ParsedExpr; fallback: ParsedExpr } | null {
|
|
19
|
+
if (parsed.kind !== 'logical' || parsed.op !== op) return null
|
|
20
|
+
const fallbacks: ParsedExpr[] = []
|
|
21
|
+
let head: ParsedExpr = parsed
|
|
22
|
+
while (head.kind === 'logical' && head.op === op) {
|
|
23
|
+
fallbacks.unshift(head.right)
|
|
24
|
+
head = head.left
|
|
25
|
+
}
|
|
26
|
+
const fallback = fallbacks.reduceRight((right, left) => ({ kind: 'logical', op, left, right }))
|
|
27
|
+
return { head, fallback }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** {@link fallbackChainParts} of a `??` chain. */
|
|
31
|
+
export function nullishChainParts(parsed: ParsedExpr): { head: ParsedExpr; fallback: ParsedExpr } | null {
|
|
32
|
+
return fallbackChainParts(parsed, '??')
|
|
33
|
+
}
|
package/src/debug.ts
CHANGED
|
@@ -23,7 +23,7 @@ import type {
|
|
|
23
23
|
SourceLocation,
|
|
24
24
|
OriginInfo,
|
|
25
25
|
} from './types.ts'
|
|
26
|
-
import { isElidedFactoryGetter } from './types.ts'
|
|
26
|
+
import { isElidedFactoryGetter, isChildrenPropParam } from './types.ts'
|
|
27
27
|
import { analyzeComponent, listComponentFunctions } from './analyzer.ts'
|
|
28
28
|
import { jsxToIR } from './jsx-to-ir.ts'
|
|
29
29
|
import { buildMetadata } from './compiler.ts'
|
|
@@ -411,7 +411,7 @@ export function buildGraphFromIR(ir: ComponentIR): ComponentGraph {
|
|
|
411
411
|
// `reactive: true` (#2903). The collector therefore returns the prop NAMES
|
|
412
412
|
// (not a boolean), so a prop read lands in `DomBinding.deps` on the same
|
|
413
413
|
// footing as a signal or memo read.
|
|
414
|
-
const destructuredPropNames = new Set(meta.propsParams.
|
|
414
|
+
const destructuredPropNames = new Set(meta.propsParams.filter(p => !isChildrenPropParam(p)).map(p => p.name))
|
|
415
415
|
const propsObjectName = meta.propsObjectName
|
|
416
416
|
const propMemberDep = (member: string): string => `${propsObjectName}.${member}`
|
|
417
417
|
|
package/src/errors.ts
CHANGED
|
@@ -127,6 +127,14 @@ export const ErrorCodes = {
|
|
|
127
127
|
// adapter including Hono. See `format-date-refusal.ts`.
|
|
128
128
|
FORMAT_DATE_AUTHORED_CALL: 'BF056',
|
|
129
129
|
|
|
130
|
+
// A module-level declaration or a value import binds the name of a
|
|
131
|
+
// `@barefootjs/client/runtime` helper (`insert`, `hydrate`, `qsa`, …) and
|
|
132
|
+
// the compiled client JS calls that name (#3537). The call may be the
|
|
133
|
+
// compiler's own, which the user's binding would capture. Before import
|
|
134
|
+
// detection resolved scopes, this shape emitted the binding next to a
|
|
135
|
+
// runtime import of the same name: a duplicate-declaration SyntaxError.
|
|
136
|
+
RUNTIME_HELPER_NAME_COLLISION: 'BF057',
|
|
137
|
+
|
|
130
138
|
// Init statement errors (BF052)
|
|
131
139
|
UNDECLARED_INIT_STATEMENT_REFERENCE: 'BF052',
|
|
132
140
|
|
|
@@ -281,6 +289,10 @@ const errorMessages: Record<ErrorCode, string> = {
|
|
|
281
289
|
[ErrorCodes.FORMAT_DATE_AUTHORED_CALL]:
|
|
282
290
|
'formatDate cannot be called directly — it is compiler ABI, not an authored API.',
|
|
283
291
|
|
|
292
|
+
[ErrorCodes.RUNTIME_HELPER_NAME_COLLISION]:
|
|
293
|
+
'This module-level name is also a BarefootJS runtime helper, and the compiled client JS calls it. ' +
|
|
294
|
+
'Rename the declaration, or import it under an alias.',
|
|
295
|
+
|
|
284
296
|
[ErrorCodes.BUILTIN_REQUIRES_IMPORT]:
|
|
285
297
|
"Built-in <Async> / <Region> must be imported from '@barefootjs/client'. " +
|
|
286
298
|
'The compiler recognises these tags by their import (not by tag name), ' +
|
package/src/expression-parser.ts
CHANGED
|
@@ -61,8 +61,10 @@ export type ParsedExpr =
|
|
|
61
61
|
// callbacks (`.filter`/`.sort`/`.reduce`/`.flatMap`) arrive as a generic
|
|
62
62
|
// `call` whose argument is this kind; the adapter serializes `body` to the
|
|
63
63
|
// runtime evaluator (#2018). Block bodies with locals / multiple statements,
|
|
64
|
-
// and array-binding-pattern params, stay `unsupported`.
|
|
65
|
-
|
|
64
|
+
// and array-binding-pattern params, stay `unsupported`. `callKind` marks an
|
|
65
|
+
// async arrow / function or a generator function: calling one returns a
|
|
66
|
+
// Promise or an iterator, not `body`'s value (#3562 review).
|
|
67
|
+
| { kind: 'arrow'; params: string[]; body: ParsedExpr; callKind?: 'async' | 'generator' }
|
|
66
68
|
// A regex literal carried as its exact source text (`/\/+$/`), so the Go
|
|
67
69
|
// ctor lowering matches the one trailing-slash-strip pattern it recognises
|
|
68
70
|
// (`String.replace`). Outside that narrow surface a regex resolves to
|
|
@@ -707,10 +709,6 @@ export function parseProviderObjectLiteral(source: string): ProviderObjectMember
|
|
|
707
709
|
* either a static string literal or a raw JS expression for the adapter to
|
|
708
710
|
* lower (`color` → its template interpolation).
|
|
709
711
|
*/
|
|
710
|
-
export type StyleObjectEntry =
|
|
711
|
-
| { cssKey: string; kind: 'literal'; value: string }
|
|
712
|
-
| { cssKey: string; kind: 'expr'; expr: string }
|
|
713
|
-
|
|
714
712
|
/** camelCase → kebab-case for CSS property names (`backgroundColor` →
|
|
715
713
|
* `background-color`, `WebkitTransform` → `-webkit-transform`). The `ms`
|
|
716
714
|
* vendor prefix is lowercase in React style keys (`msTransform`) yet the CSS
|
|
@@ -772,40 +770,6 @@ export function hasUnsafeStyleValue(value: string): boolean {
|
|
|
772
770
|
return quote !== 0 || blockStack.length !== 0 // unterminated quote/bracket
|
|
773
771
|
}
|
|
774
772
|
|
|
775
|
-
/**
|
|
776
|
-
* Parse a JSX `style={{ … }}` object-literal source into CSS entries, or
|
|
777
|
-
* `null` when the shape isn't a plain object of static-keyed properties
|
|
778
|
-
* (spread, computed key, shorthand, method, getter) — the adapter then keeps
|
|
779
|
-
* refusing it. A bare `{…}` parses as a block statement, so the source is
|
|
780
|
-
* wrapped in parens to force expression context. Used by the template adapters
|
|
781
|
-
* to lower `style={{ backgroundColor: color, padding: '8px' }}` to a CSS
|
|
782
|
-
* string instead of emitting BF101.
|
|
783
|
-
*/
|
|
784
|
-
export function parseStyleObjectEntries(source: string): StyleObjectEntry[] | null {
|
|
785
|
-
const sf = ts.createSourceFile('__style__.ts', `(${source})`, ts.ScriptTarget.Latest, true)
|
|
786
|
-
const stmt = sf.statements[0]
|
|
787
|
-
if (!stmt || !ts.isExpressionStatement(stmt) || sf.statements.length !== 1) return null
|
|
788
|
-
let expr: ts.Expression = stmt.expression
|
|
789
|
-
while (ts.isParenthesizedExpression(expr)) expr = expr.expression
|
|
790
|
-
if (!ts.isObjectLiteralExpression(expr)) return null
|
|
791
|
-
const entries: StyleObjectEntry[] = []
|
|
792
|
-
for (const prop of expr.properties) {
|
|
793
|
-
if (!ts.isPropertyAssignment(prop)) return null // shorthand/spread/method/getter
|
|
794
|
-
let key: string
|
|
795
|
-
if (ts.isIdentifier(prop.name)) key = prop.name.text
|
|
796
|
-
else if (ts.isStringLiteral(prop.name)) key = prop.name.text
|
|
797
|
-
else return null // computed / numeric key
|
|
798
|
-
const cssKey = cssKebabCase(key)
|
|
799
|
-
const init = prop.initializer
|
|
800
|
-
if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {
|
|
801
|
-
entries.push({ cssKey, kind: 'literal', value: init.text })
|
|
802
|
-
} else {
|
|
803
|
-
entries.push({ cssKey, kind: 'expr', expr: init.getText(sf).trim() })
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
return entries.length > 0 ? entries : null
|
|
807
|
-
}
|
|
808
|
-
|
|
809
773
|
/**
|
|
810
774
|
* Parse a JavaScript expression string into a ParsedExpr tree.
|
|
811
775
|
*/
|
|
@@ -1159,6 +1123,7 @@ function convertNode(node: ts.Node, raw: string): ParsedExpr {
|
|
|
1159
1123
|
// a generic `call` whose argument is this kind; the adapter serializes
|
|
1160
1124
|
// `body` to the runtime evaluator.
|
|
1161
1125
|
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
1126
|
+
const callKind = arrowCallKind(node)
|
|
1162
1127
|
// Resolve the body expression: an expression-bodied arrow carries it
|
|
1163
1128
|
// directly; a block body (arrow `=> { … }` or a function expression)
|
|
1164
1129
|
// must reduce to exactly one `return <expr>;`. Multi-statement /
|
|
@@ -1287,7 +1252,7 @@ function convertNode(node: ts.Node, raw: string): ParsedExpr {
|
|
|
1287
1252
|
}
|
|
1288
1253
|
const syntheticParam = pickSyntheticParam(fieldMap, body)
|
|
1289
1254
|
const rewritten = substituteDestructuredFields(body, fieldMap, syntheticParam, restName)
|
|
1290
|
-
return { kind: 'arrow', params: [syntheticParam], body: rewritten }
|
|
1255
|
+
return { kind: 'arrow', params: [syntheticParam], body: rewritten, ...callKind }
|
|
1291
1256
|
}
|
|
1292
1257
|
|
|
1293
1258
|
// Every (remaining) parameter must be a plain identifier. Multi-param
|
|
@@ -1300,7 +1265,7 @@ function convertNode(node: ts.Node, raw: string): ParsedExpr {
|
|
|
1300
1265
|
}
|
|
1301
1266
|
params.push(p.name.text)
|
|
1302
1267
|
}
|
|
1303
|
-
return { kind: 'arrow', params, body }
|
|
1268
|
+
return { kind: 'arrow', params, body, ...callKind }
|
|
1304
1269
|
}
|
|
1305
1270
|
|
|
1306
1271
|
// Default: unsupported
|
|
@@ -2961,6 +2926,30 @@ function usesPerPath(name: string, expr: ParsedExpr): { min: number; max: number
|
|
|
2961
2926
|
return walk(expr)
|
|
2962
2927
|
}
|
|
2963
2928
|
|
|
2929
|
+
/** `{ callKind }` for an async or generator function, else nothing (see the `arrow` kind). */
|
|
2930
|
+
function arrowCallKind(node: ts.ArrowFunction | ts.FunctionExpression): { callKind?: 'async' | 'generator' } {
|
|
2931
|
+
if (ts.isFunctionExpression(node) && node.asteriskToken) return { callKind: 'generator' }
|
|
2932
|
+
if (node.modifiers?.some(m => m.kind === ts.SyntaxKind.AsyncKeyword)) return { callKind: 'async' }
|
|
2933
|
+
return {}
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
/**
|
|
2937
|
+
* The value a call of `value` with no arguments evaluates to, when that is
|
|
2938
|
+
* just its body: a zero-param, synchronous, non-generator arrow whose body
|
|
2939
|
+
* is a pure value expression. Null otherwise (an async call returns a
|
|
2940
|
+
* Promise, a generator an iterator, and a body that mutates state, like
|
|
2941
|
+
* `++nextId`, must run where it is declared).
|
|
2942
|
+
*/
|
|
2943
|
+
export function zeroArgCallBody(value: ParsedExpr): ParsedExpr | null {
|
|
2944
|
+
if (value.kind !== 'arrow' || value.params.length !== 0 || value.callKind) return null
|
|
2945
|
+
return isSupportedValue(value.body).supported ? value.body : null
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
/** `name()` with no arguments, where `name` is not shadowed by an enclosing param. */
|
|
2949
|
+
function isBareCallOf(e: Extract<ParsedExpr, { kind: 'call' }>, name: string, enclosing: ReadonlySet<string>): boolean {
|
|
2950
|
+
return e.args.length === 0 && e.callee.kind === 'identifier' && e.callee.name === name && !enclosing.has(name)
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2964
2953
|
/**
|
|
2965
2954
|
* Inline `name → value` everywhere it appears free in `expr` (the let-inline
|
|
2966
2955
|
* step). Returns `null` if the substitution would capture a free variable of
|
|
@@ -2989,6 +2978,27 @@ export function inlineBinding(
|
|
|
2989
2978
|
const valueFree = new Set<string>()
|
|
2990
2979
|
collectIdentifiers(value, valueFree)
|
|
2991
2980
|
let captured = false
|
|
2981
|
+
// A zero-param arrow (`const isWide = () => props.mode === 'wide'`) called
|
|
2982
|
+
// with no arguments inlines as its body, so `isWide()` reads what the call
|
|
2983
|
+
// returns (#3562; `zeroArgCallBody` says which arrows qualify). Calling it
|
|
2984
|
+
// evaluates the body in the same scope the substitution resolves it in;
|
|
2985
|
+
// the capture check covers the body's free variables, which are `value`'s.
|
|
2986
|
+
const callBody = zeroArgCallBody(value)
|
|
2987
|
+
// Inlining here: does any enclosing param capture a free var of `value`?
|
|
2988
|
+
const capturesValueFree = (enclosing: ReadonlySet<string>): boolean => {
|
|
2989
|
+
for (const p of enclosing) {
|
|
2990
|
+
if (valueFree.has(p)) {
|
|
2991
|
+
captured = true
|
|
2992
|
+
return true
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
return false
|
|
2996
|
+
}
|
|
2997
|
+
|
|
2998
|
+
const walkCall = (e: Extract<ParsedExpr, { kind: 'call' }>, enclosing: ReadonlySet<string>): ParsedExpr => {
|
|
2999
|
+
if (callBody && isBareCallOf(e, name, enclosing)) return capturesValueFree(enclosing) ? e : callBody
|
|
3000
|
+
return { kind: 'call', callee: walk(e.callee, enclosing), args: e.args.map(a => walk(a, enclosing)) }
|
|
3001
|
+
}
|
|
2992
3002
|
|
|
2993
3003
|
const walk = (e: ParsedExpr, enclosing: ReadonlySet<string>): ParsedExpr => {
|
|
2994
3004
|
switch (e.kind) {
|
|
@@ -2997,17 +3007,10 @@ export function inlineBinding(
|
|
|
2997
3007
|
// Shadowed by an enclosing callback param → this is the parameter, not
|
|
2998
3008
|
// the binding; leave it.
|
|
2999
3009
|
if (enclosing.has(e.name)) return e
|
|
3000
|
-
|
|
3001
|
-
for (const p of enclosing) {
|
|
3002
|
-
if (valueFree.has(p)) {
|
|
3003
|
-
captured = true
|
|
3004
|
-
return e
|
|
3005
|
-
}
|
|
3006
|
-
}
|
|
3007
|
-
return value
|
|
3010
|
+
return capturesValueFree(enclosing) ? e : value
|
|
3008
3011
|
}
|
|
3009
3012
|
case 'call':
|
|
3010
|
-
return
|
|
3013
|
+
return walkCall(e, enclosing)
|
|
3011
3014
|
case 'member':
|
|
3012
3015
|
return { kind: 'member', object: walk(e.object, enclosing), property: e.property, computed: e.computed, optional: e.optional }
|
|
3013
3016
|
case 'index-access':
|
|
@@ -3029,7 +3032,7 @@ export function inlineBinding(
|
|
|
3029
3032
|
}
|
|
3030
3033
|
case 'arrow': {
|
|
3031
3034
|
const innerEnclosing = e.params.length === 0 ? enclosing : new Set([...enclosing, ...e.params])
|
|
3032
|
-
return {
|
|
3035
|
+
return { ...e, body: walk(e.body, innerEnclosing) }
|
|
3033
3036
|
}
|
|
3034
3037
|
case 'array-literal':
|
|
3035
3038
|
return { kind: 'array-literal', elements: e.elements.map(el => walk(el, enclosing)) }
|
|
@@ -3425,7 +3428,7 @@ export function materializeGetterCalls(expr: ParsedExpr, names: ReadonlySet<stri
|
|
|
3425
3428
|
properties: expr.properties.map(p => (p.kind === 'spread' ? { ...p, expr: rw(p.expr) } : { ...p, value: rw(p.value) })),
|
|
3426
3429
|
}
|
|
3427
3430
|
case 'arrow':
|
|
3428
|
-
return {
|
|
3431
|
+
return { ...expr, body: rw(expr.body) }
|
|
3429
3432
|
// Leaves / opaque shapes — nothing to rewrite.
|
|
3430
3433
|
case 'identifier':
|
|
3431
3434
|
case 'literal':
|
package/src/free-refs.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
ConstantInfo,
|
|
24
24
|
FunctionInfo,
|
|
25
25
|
} from './types.ts'
|
|
26
|
+
import { isChildrenPropParam } from './types.ts'
|
|
26
27
|
import { isReactiveType } from './reactivity-checker.ts'
|
|
27
28
|
import { incrementCounter } from './instrumentation.ts'
|
|
28
29
|
|
|
@@ -36,6 +37,12 @@ export interface BindingEnvironment {
|
|
|
36
37
|
memos: readonly MemoInfo[]
|
|
37
38
|
propsParams: readonly ParamInfo[]
|
|
38
39
|
propsObjectName: string | null
|
|
40
|
+
/**
|
|
41
|
+
* Component-scope consts that alias the props object (`const p = props`,
|
|
42
|
+
* through any number of hops). A `.children` read through one of them is
|
|
43
|
+
* the children prop, the same as `props.children` (#3572).
|
|
44
|
+
*/
|
|
45
|
+
propsObjectAliases?: ReadonlySet<string>
|
|
39
46
|
restPropsName: string | null
|
|
40
47
|
localConstants: readonly ConstantInfo[]
|
|
41
48
|
localFunctions: readonly FunctionInfo[]
|
|
@@ -106,7 +113,7 @@ function buildBindingMap(env: BindingEnvironment): Map<string, BindingKind> {
|
|
|
106
113
|
// the OR-combined `reactive` flag promotes it to a text slot,
|
|
107
114
|
// breaking SSR hydration on every UI component that forwards
|
|
108
115
|
// children.
|
|
109
|
-
if (p
|
|
116
|
+
if (isChildrenPropParam(p)) continue
|
|
110
117
|
map.set(p.name, 'prop')
|
|
111
118
|
}
|
|
112
119
|
if (env.propsObjectName !== null) {
|
|
@@ -298,6 +305,25 @@ function resolveConstantInitializerRefs(
|
|
|
298
305
|
* the transitive-taint expansion path. `visited` tracks identifier names
|
|
299
306
|
* already expanded to break cycles like `const a = b; const b = a`.
|
|
300
307
|
*/
|
|
308
|
+
/**
|
|
309
|
+
* `props.children` is rendered into the server-side HTML (it is the child
|
|
310
|
+
* slot, not a reactive value). The `props` identifier is a non-reactive
|
|
311
|
+
* reference *only* in this position, so consumers don't wrap the
|
|
312
|
+
* surrounding expression in createEffect just because it touches `props`.
|
|
313
|
+
* Matches the legacy `isPropsReference` semantics. A const alias of the
|
|
314
|
+
* props object (`const p = props; p.children`) reads the same prop (#3572).
|
|
315
|
+
*/
|
|
316
|
+
function isPropsChildrenRead(ident: ts.Identifier, env: BindingEnvironment): boolean {
|
|
317
|
+
if (env.propsObjectName !== ident.text && !env.propsObjectAliases?.has(ident.text)) return false
|
|
318
|
+
const parent = ident.parent
|
|
319
|
+
return (
|
|
320
|
+
!!parent &&
|
|
321
|
+
ts.isPropertyAccessExpression(parent) &&
|
|
322
|
+
parent.expression === ident &&
|
|
323
|
+
parent.name.text === 'children'
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
|
|
301
327
|
function resolveFreeRefsInternal(
|
|
302
328
|
node: ts.Node,
|
|
303
329
|
env: BindingEnvironment,
|
|
@@ -312,22 +338,7 @@ function resolveFreeRefsInternal(
|
|
|
312
338
|
for (const ident of idents) {
|
|
313
339
|
const name = ident.text
|
|
314
340
|
|
|
315
|
-
|
|
316
|
-
// child slot, not a reactive value). Treat the `props` identifier as
|
|
317
|
-
// a non-reactive reference *only* in this position so consumers don't
|
|
318
|
-
// wrap the surrounding expression in createEffect just because it
|
|
319
|
-
// touches `props`. Matches the legacy `isPropsReference` semantics.
|
|
320
|
-
if (env.propsObjectName === name) {
|
|
321
|
-
const parent = ident.parent
|
|
322
|
-
if (
|
|
323
|
-
parent &&
|
|
324
|
-
ts.isPropertyAccessExpression(parent) &&
|
|
325
|
-
parent.expression === ident &&
|
|
326
|
-
parent.name.text === 'children'
|
|
327
|
-
) {
|
|
328
|
-
continue
|
|
329
|
-
}
|
|
330
|
-
}
|
|
341
|
+
if (isPropsChildrenRead(ident, env)) continue
|
|
331
342
|
|
|
332
343
|
let kind: BindingKind | undefined = bindingMap.get(name)
|
|
333
344
|
|