@barefootjs/jsx 0.39.6 → 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/attr-plan.d.ts +8 -1
- package/dist/adapters/attr-plan.d.ts.map +1 -1
- package/dist/adapters/callback-method.d.ts +44 -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/computed-const.d.ts +52 -0
- package/dist/adapters/computed-const.d.ts.map +1 -0
- package/dist/adapters/dangerous-inner-html.d.ts +10 -0
- package/dist/adapters/dangerous-inner-html.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/element-shell.d.ts +44 -0
- package/dist/adapters/element-shell.d.ts.map +1 -0
- package/dist/adapters/interface.d.ts +2 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- 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/augment-inherited-props.d.ts +7 -0
- package/dist/augment-inherited-props.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/fold-render-reassignments.d.ts +43 -0
- package/dist/fold-render-reassignments.d.ts.map +1 -0
- package/dist/free-refs.d.ts +15 -0
- package/dist/free-refs.d.ts.map +1 -1
- package/dist/index.d.ts +21 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24620 -23233
- 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 +0 -13
- 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 +9 -19
- 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/index.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/plan/declaration-emit.d.ts +5 -0
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts +11 -12
- package/dist/ir-to-client-js/prop-handling.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 +15 -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 +43 -12
- 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 +43 -6
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/relocate.d.ts +16 -0
- package/dist/relocate.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 +37 -18
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/types.d.ts +162 -20
- 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__/block-memo-type.test.ts +51 -0
- package/src/__tests__/callback-method.test.ts +75 -0
- package/src/__tests__/children-read.test.ts +226 -0
- package/src/__tests__/client-only-date-lowering.test.ts +2 -2
- package/src/__tests__/client-template-escape-soundness.test.ts +31 -1
- package/src/__tests__/component-props.test.ts +68 -1
- package/src/__tests__/computed-const.test.ts +101 -0
- 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__/element-shell.test.ts +78 -0
- package/src/__tests__/event-handler-verbatim.test.ts +73 -0
- package/src/__tests__/expression-parser.test.ts +1 -44
- package/src/__tests__/fold-render-reassignments.test.ts +96 -0
- package/src/__tests__/inlinable-local-method-call.test.ts +81 -0
- package/src/__tests__/memo-body-expr.test.ts +120 -0
- package/src/__tests__/nullable-signal-attr.test.ts +67 -3
- package/src/__tests__/prop-handling.test.ts +35 -16
- package/src/__tests__/props-alias-const.test.ts +65 -0
- 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__/signal-prop-seed.test.ts +90 -0
- package/src/__tests__/ssr-defaults.test.ts +19 -1
- package/src/__tests__/ssr-seed-plan.test.ts +173 -1
- package/src/__tests__/static-template-reachability.test.ts +137 -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/attr-plan.ts +29 -1
- package/src/adapters/callback-method.ts +85 -0
- package/src/adapters/component-props.ts +130 -12
- package/src/adapters/computed-const.ts +185 -0
- package/src/adapters/dangerous-inner-html.ts +33 -0
- package/src/adapters/dsl-template-adapter.ts +248 -0
- package/src/adapters/element-shell.ts +160 -0
- package/src/adapters/interface.ts +8 -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 +382 -94
- package/src/augment-inherited-props.ts +12 -0
- 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/fold-render-reassignments.ts +314 -0
- package/src/free-refs.ts +77 -17
- package/src/index.ts +27 -10
- package/src/ir-to-client-js/compute-inlinability.ts +122 -19
- 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 +25 -37
- package/src/ir-to-client-js/emit-reactive.ts +2 -2
- package/src/ir-to-client-js/emit-registration.ts +31 -59
- package/src/ir-to-client-js/generate-init.ts +17 -1
- package/src/ir-to-client-js/html-template.ts +56 -120
- 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 +5 -3
- package/src/ir-to-client-js/init-declarations.ts +1 -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 +26 -52
- package/src/ir-to-client-js/plan/declaration-emit.ts +5 -0
- package/src/ir-to-client-js/prop-handling.ts +13 -54
- 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 +27 -9
- package/src/ir-to-client-js/safe-html.ts +29 -35
- package/src/ir-to-client-js/stringify/declaration-emit.ts +1 -1
- package/src/ir-to-client-js/types.ts +3 -2
- package/src/ir-to-client-js/utils.ts +13 -26
- package/src/jsx-to-ir.ts +318 -130
- package/src/nullable-signal-attr.ts +156 -37
- package/src/prop-rewrite.ts +41 -0
- package/src/props-binding.ts +117 -7
- package/src/relocate.ts +40 -8
- 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 +121 -29
- package/src/types.ts +165 -21
- package/src/value-references.ts +132 -0
package/src/jsx-to-ir.ts
CHANGED
|
@@ -33,16 +33,19 @@ import {
|
|
|
33
33
|
type PreambleRegionSource,
|
|
34
34
|
type PreambleValueDeclaration,
|
|
35
35
|
tsxSourceText, type TsxSourceText,
|
|
36
|
+
type TypedExprSource,
|
|
36
37
|
type SourceLocation,
|
|
37
38
|
type TypeInfo,
|
|
38
39
|
type OriginInfo,
|
|
39
40
|
type IRMetadata,
|
|
40
41
|
isReactiveOrigin,
|
|
42
|
+
isChildrenPropParam,
|
|
41
43
|
AttrValueOf,
|
|
42
44
|
} from './types.ts'
|
|
43
45
|
import { type AnalyzerContext, type MultiReturnJsxInfo, getSourceLocation, collectReactiveGetterNames, tsTypeToTypeInfo } from './analyzer-context.ts'
|
|
44
46
|
import { parseExpression, isSupported, parseBlockBody, foldBlockToExpr, predicateTernaryToLogical, tsNodeToParsedExpr, sortComparatorFromArrow, stringifyParsedExpr, cssKebabCase, CALLBACK_METHODS, unboundCallbackParamRead, unboundCallbackParamReason, type ParsedExpr } from './expression-parser.ts'
|
|
45
|
-
import
|
|
47
|
+
import { fallbackChainParts, nullishChainParts } from './children-nullish.ts'
|
|
48
|
+
import type { IRLoopSort, FunctionInfo, ConstantInfo, ParamInfo, FreeReference } from './types.ts'
|
|
46
49
|
import { formatParamWithType } from './module-exports.ts'
|
|
47
50
|
import { createError, ErrorCodes, internalInvariant } from './errors.ts'
|
|
48
51
|
import { CLIENT_BUILTIN_SOURCE, isClientBuiltinName, type ClientBuiltinTag } from './builtins.ts'
|
|
@@ -52,10 +55,10 @@ import {
|
|
|
52
55
|
collectAstPropRefs,
|
|
53
56
|
rewriteScopedValueRefs,
|
|
54
57
|
} from './prop-rewrite.ts'
|
|
55
|
-
import { boundPropLocalNames, buildPropAliasMap, resolveAliasOrigin, resolveRestSpreadOriginCore, livePropReadExpr } from './props-binding.ts'
|
|
58
|
+
import { boundPropLocalNames, buildPropAliasMap, isPropsAliasConst, resolveAliasOrigin, resolveRestSpreadOriginCore, livePropReadExpr } from './props-binding.ts'
|
|
56
59
|
import { PROPS_PARAM } from './ir-to-client-js/utils.ts'
|
|
57
60
|
import { walkIR } from './ir-to-client-js/walker.ts'
|
|
58
|
-
import { resolveFreeRefs, isNameBound as isNameBoundInEnv, type BindingEnvironment } from './free-refs.ts'
|
|
61
|
+
import { resolveFreeRefs, rebindHelperParamRefs, isNameBound as isNameBoundInEnv, type BindingEnvironment } from './free-refs.ts'
|
|
59
62
|
import { computeFileScope } from './ir-to-client-js/component-scope.ts'
|
|
60
63
|
import { createTemplateAwareStringProtector } from './ir-to-client-js/html-template.ts'
|
|
61
64
|
import { extractFreeIdentifiersFromText } from './ir-to-client-js/csr-substitute.ts'
|
|
@@ -64,7 +67,7 @@ import { toLocaleDatePlugin, foldedArgToClientJs } from './to-locale-date-loweri
|
|
|
64
67
|
import type { LoweringMatcher } from './lowering-registry.ts'
|
|
65
68
|
import { extractFreeIdentifiersFromNode, initializerShapeContainsJsx, extractMultiReturnJsxBranches, rootIdentifierOf, type MultiReturnJsxBranches } from './analyzer.ts'
|
|
66
69
|
import { iterateJsTokens, replaceInExprContexts } from './scanner/js-scanner.ts'
|
|
67
|
-
import { reconstructAsSegments } from './strip-types.ts'
|
|
70
|
+
import { reconstructAsSegments, reconstructWithoutTypes } from './strip-types.ts'
|
|
68
71
|
import { templatePartsToJsExpr } from './template-parts.ts'
|
|
69
72
|
import { toHTMLAttrName, decodeEntities, BF_KEY, keyAttrName } from '@barefootjs/shared'
|
|
70
73
|
import { BindingScope } from './scope/binding-scope.ts'
|
|
@@ -414,7 +417,7 @@ function exprReferencesModuleClientSignal(expr: ts.Expression, ctx: TransformCon
|
|
|
414
417
|
/**
|
|
415
418
|
* Walk an expression AST to check if it contains any CallExpression.
|
|
416
419
|
* Catches all call patterns: identifier(), obj.method(), fn?.(), IIFEs, etc.
|
|
417
|
-
*
|
|
420
|
+
* Recorded on the IR as `hasFunctionCalls`.
|
|
418
421
|
*/
|
|
419
422
|
function exprHasFunctionCalls(expr: ts.Expression): boolean {
|
|
420
423
|
let found = false
|
|
@@ -750,11 +753,7 @@ function getDestructuredPropNames(ctx: TransformContext): Set<string> | null {
|
|
|
750
753
|
}
|
|
751
754
|
for (const m of ctx.analyzer.memos) shadowed.add(m.name)
|
|
752
755
|
for (const c of ctx.analyzer.localConstants) {
|
|
753
|
-
|
|
754
|
-
typeof c.value === 'string' &&
|
|
755
|
-
(c.value === `${ctx.analyzer.propsObjectName}.${c.name}` ||
|
|
756
|
-
c.value.startsWith(`${ctx.analyzer.propsObjectName}.${c.name} ??`))
|
|
757
|
-
if (!isDestructureFromProps) shadowed.add(c.name)
|
|
756
|
+
if (!isPropsAliasConst(c, ctx.analyzer.propsObjectName)) shadowed.add(c.name)
|
|
758
757
|
}
|
|
759
758
|
}
|
|
760
759
|
const eligible = ctx.analyzer.propsParams.filter(p => !shadowed.has(p.name))
|
|
@@ -799,7 +798,7 @@ export function createTransformContext(analyzer: AnalyzerContext): TransformCont
|
|
|
799
798
|
// Shared by `patterns.props` (regex matching) and `boundPropNames`
|
|
800
799
|
// (exact-name binding checks, #2835) so both agree on which prop
|
|
801
800
|
// params are in play — `children` excluded from both the same way.
|
|
802
|
-
const propsParamsForMatching = analyzer.propsParams.filter(p => p
|
|
801
|
+
const propsParamsForMatching = analyzer.propsParams.filter(p => !isChildrenPropParam(p))
|
|
803
802
|
return {
|
|
804
803
|
analyzer,
|
|
805
804
|
sourceFile: analyzer.sourceFile,
|
|
@@ -969,6 +968,7 @@ function makeBindingEnv(ctx: TransformContext): BindingEnvironment {
|
|
|
969
968
|
memos: a.memos,
|
|
970
969
|
propsParams: a.propsParams,
|
|
971
970
|
propsObjectName: a.propsObjectName,
|
|
971
|
+
propsObjectAliases: propsObjectAliasNames(a, ctx.scope),
|
|
972
972
|
restPropsName: a.restPropsName,
|
|
973
973
|
localConstants: a.localConstants,
|
|
974
974
|
localFunctions: a.localFunctions,
|
|
@@ -1004,8 +1004,193 @@ function parseValueExpr(trimmed: string): ParsedExpr {
|
|
|
1004
1004
|
return parseExpression(trimmed.startsWith('{') ? `(${trimmed})` : trimmed)
|
|
1005
1005
|
}
|
|
1006
1006
|
|
|
1007
|
-
|
|
1008
|
-
const
|
|
1007
|
+
const childrenHopCache = new WeakMap<AnalyzerContext, ReadonlyMap<string, ParsedExpr | undefined>>()
|
|
1008
|
+
const childrenAliasHopCache = new WeakMap<AnalyzerContext, ReadonlyMap<string, string | undefined>>()
|
|
1009
|
+
|
|
1010
|
+
/**
|
|
1011
|
+
* The component-scope consts a read of the children prop may hop through,
|
|
1012
|
+
* by name, with their parsed initializers: a `const` that is not module
|
|
1013
|
+
* scope and is not mutated after its declaration, so it holds the one value
|
|
1014
|
+
* it was declared with (`const c = children`, `const p = props`,
|
|
1015
|
+
* `const { children: kids } = props`).
|
|
1016
|
+
*/
|
|
1017
|
+
function childrenHopConstants(analyzer: AnalyzerContext): ReadonlyMap<string, ParsedExpr | undefined> {
|
|
1018
|
+
let consts = childrenHopCache.get(analyzer)
|
|
1019
|
+
if (!consts) {
|
|
1020
|
+
const map = new Map<string, ParsedExpr | undefined>()
|
|
1021
|
+
for (const c of analyzer.localConstants) {
|
|
1022
|
+
if (c.isModule || c.declarationKind !== 'const' || c.mutatedAfterDeclaration || map.has(c.name)) continue
|
|
1023
|
+
map.set(c.name, c.parsed)
|
|
1024
|
+
}
|
|
1025
|
+
consts = map
|
|
1026
|
+
childrenHopCache.set(analyzer, consts)
|
|
1027
|
+
}
|
|
1028
|
+
return consts
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* {@link childrenHopConstants} as the identifier hops `resolveAliasOrigin`
|
|
1033
|
+
* walks (`const c = children` → `children`). Every hop is a component-scope
|
|
1034
|
+
* initializer, so it resolves in the component scope: a loop row that
|
|
1035
|
+
* shadows a name at a use site does not shadow it inside an outer const's
|
|
1036
|
+
* initializer (`const c = props.children` read in
|
|
1037
|
+
* `rows.map(props => …{c}…)` still reads the props object).
|
|
1038
|
+
*/
|
|
1039
|
+
function childrenAliasHops(analyzer: AnalyzerContext): ReadonlyMap<string, string | undefined> {
|
|
1040
|
+
let hops = childrenAliasHopCache.get(analyzer)
|
|
1041
|
+
if (!hops) {
|
|
1042
|
+
const map = new Map<string, string | undefined>()
|
|
1043
|
+
for (const [name, parsed] of childrenHopConstants(analyzer)) {
|
|
1044
|
+
map.set(name, parsed?.kind === 'identifier' ? parsed.name : undefined)
|
|
1045
|
+
}
|
|
1046
|
+
hops = map
|
|
1047
|
+
childrenAliasHopCache.set(analyzer, hops)
|
|
1048
|
+
}
|
|
1049
|
+
return hops
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
/** Whether the component-scope name `name` holds the props object: the props param, or a const alias of it (`const p = props`). */
|
|
1053
|
+
function isPropsObjectBinding(name: string, analyzer: AnalyzerContext): boolean {
|
|
1054
|
+
const propsObjectName = analyzer.propsObjectName
|
|
1055
|
+
if (propsObjectName === null) return false
|
|
1056
|
+
return resolveAliasOrigin(childrenAliasHops(analyzer), name, n => (n === propsObjectName ? true : null)) === true
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* The component-scope consts that alias the props object (`const p =
|
|
1061
|
+
* props`), for the free-reference walk's `p.children` exemption
|
|
1062
|
+
* (`BindingEnvironment.propsObjectAliases`). Leaves out a name the
|
|
1063
|
+
* enclosing loop rows bind at the use site.
|
|
1064
|
+
*/
|
|
1065
|
+
function propsObjectAliasNames(analyzer: AnalyzerContext, scope: BindingScope): ReadonlySet<string> {
|
|
1066
|
+
const names = new Set<string>()
|
|
1067
|
+
if (analyzer.propsObjectName === null) return names
|
|
1068
|
+
for (const name of childrenHopConstants(analyzer).keys()) {
|
|
1069
|
+
if (!scope.isBound(name) && isPropsObjectBinding(name, analyzer)) names.add(name)
|
|
1070
|
+
}
|
|
1071
|
+
return names
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
/**
|
|
1075
|
+
* Whether `parsed`, read in the component scope, is `<props object>.children`
|
|
1076
|
+
* (`props.children`, `p.children` for `const p = props`).
|
|
1077
|
+
*/
|
|
1078
|
+
function isPropsChildrenMember(parsed: ParsedExpr | undefined, analyzer: AnalyzerContext): boolean {
|
|
1079
|
+
return (
|
|
1080
|
+
parsed?.kind === 'member' &&
|
|
1081
|
+
!parsed.computed &&
|
|
1082
|
+
parsed.property === 'children' &&
|
|
1083
|
+
parsed.object.kind === 'identifier' &&
|
|
1084
|
+
isPropsObjectBinding(parsed.object.name, analyzer)
|
|
1085
|
+
)
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Whether the component-scope name `name` holds the component's own
|
|
1090
|
+
* children prop with no default: the props param that binds it, renamed or
|
|
1091
|
+
* not (`{ children }`, `{ children: kids }`, `isChildrenPropParam`), a body
|
|
1092
|
+
* destructure or member read of it (`const { children: kids } = props`,
|
|
1093
|
+
* `const kids = p.children`), or a const alias hop of any of these
|
|
1094
|
+
* (`const c = children`, #3572). A use site checks its own shadowing first
|
|
1095
|
+
* (`childrenReadOf`); the hops and initializers resolve in the component
|
|
1096
|
+
* scope they were declared in.
|
|
1097
|
+
*/
|
|
1098
|
+
function isChildrenBinding(name: string, analyzer: AnalyzerContext): boolean {
|
|
1099
|
+
const consts = childrenHopConstants(analyzer)
|
|
1100
|
+
const terminal = (n: string): true | null => {
|
|
1101
|
+
if (consts.has(n)) return isPropsChildrenMember(consts.get(n), analyzer) ? true : null
|
|
1102
|
+
return analyzer.propsParams.some(p => p.name === n && isChildrenPropParam(p)) ? true : null
|
|
1103
|
+
}
|
|
1104
|
+
return resolveAliasOrigin(childrenAliasHops(analyzer), name, terminal) === true
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* Whether the expression text reads nothing but the component's own
|
|
1109
|
+
* children prop (`childrenReadOf`: bare, or under `?? ''`). That read is
|
|
1110
|
+
* content the parent renders, never a reactive value, so it takes no text
|
|
1111
|
+
* slot — even where the regex reactivity classifier would match a local
|
|
1112
|
+
* that shares the prop's name (`const { children: kids, label: children } =
|
|
1113
|
+
* props`, where `kids` holds `props.children`, #3572).
|
|
1114
|
+
*/
|
|
1115
|
+
function isWholeChildrenRead(exprText: string, ctx: TransformContext): boolean {
|
|
1116
|
+
const read = childrenReadOf(parseExpression(exprText.trim()), ctx.analyzer, ctx.scope)
|
|
1117
|
+
return read === 'bare' || read === 'nullish-empty'
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/** Whether a text-position expression is reactive: not a whole children read (`isWholeChildrenRead`), and reactive by the regex/checker or origin classifier. */
|
|
1121
|
+
function isReactiveTextRead(exprText: string, ctx: TransformContext, expr: ts.Expression, origin: OriginInfo): boolean {
|
|
1122
|
+
if (isWholeChildrenRead(exprText, ctx)) return false
|
|
1123
|
+
return isReactiveExpression(exprText, ctx, expr) || isReactiveOrigin(origin)
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
/** `''`, or a `??` chain of `''` (`'' ?? ''`). */
|
|
1127
|
+
function isEmptyStringFallback(fallback: ParsedExpr): boolean {
|
|
1128
|
+
if (fallback.kind === 'logical' && fallback.op === '??') {
|
|
1129
|
+
return isEmptyStringFallback(fallback.left) && isEmptyStringFallback(fallback.right)
|
|
1130
|
+
}
|
|
1131
|
+
return fallback.kind === 'literal' && fallback.value === ''
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
* How `parsed` reads the component's own `children` prop
|
|
1136
|
+
* (`IRExpression.childrenRead`, #3539): a name holding the prop
|
|
1137
|
+
* (`isChildrenBinding`: `children`, a renamed `{ children: kids }`, a body
|
|
1138
|
+
* alias, or a const alias hop of one, #3572) or `<propsObject>.children`
|
|
1139
|
+
* (through a const alias of the props object too), that read on the left of
|
|
1140
|
+
* `?? ''`, on the left of another `?? fallback`, or on the left of
|
|
1141
|
+
* `|| fallback` (#3554). A chained
|
|
1142
|
+
* `(children ?? '<b>x</b>') ?? ''` reads as `children ?? ('<b>x</b>' ?? '')`
|
|
1143
|
+
* (`nullishChainParts`), so its inner fallback stays escaped text. A name the enclosing loop rows bind
|
|
1144
|
+
* (item, index, destructured names and preamble locals, through `scope`)
|
|
1145
|
+
* shadows the prop; a component-body `const children` cannot coexist with a
|
|
1146
|
+
* destructured `children` param, so the destructure is the binding when it
|
|
1147
|
+
* lists the name.
|
|
1148
|
+
*/
|
|
1149
|
+
function childrenReadOf(
|
|
1150
|
+
parsed: ParsedExpr,
|
|
1151
|
+
analyzer: AnalyzerContext,
|
|
1152
|
+
scope: BindingScope,
|
|
1153
|
+
): IRExpression['childrenRead'] | null {
|
|
1154
|
+
const chain = nullishChainParts(parsed)
|
|
1155
|
+
if (chain) {
|
|
1156
|
+
if (childrenReadOf(chain.head, analyzer, scope) !== 'bare') return null
|
|
1157
|
+
return isEmptyStringFallback(chain.fallback) ? 'nullish-empty' : 'nullish-fallback'
|
|
1158
|
+
}
|
|
1159
|
+
const orChain = fallbackChainParts(parsed, '||')
|
|
1160
|
+
if (orChain) return childrenReadOf(orChain.head, analyzer, scope) === 'bare' ? 'or-fallback' : null
|
|
1161
|
+
// Shadowing is checked once, for the name the expression itself reads.
|
|
1162
|
+
if (parsed.kind === 'identifier') {
|
|
1163
|
+
return !scope.isBound(parsed.name) && isChildrenBinding(parsed.name, analyzer) ? 'bare' : null
|
|
1164
|
+
}
|
|
1165
|
+
const readsProps =
|
|
1166
|
+
parsed.kind === 'member' && parsed.object.kind === 'identifier' && !scope.isBound(parsed.object.name)
|
|
1167
|
+
return readsProps && isPropsChildrenMember(parsed, analyzer) ? 'bare' : null
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* Attach `parsed` to every expression-valued attribute / prop so adapters can
|
|
1172
|
+
* lower from the tree instead of re-parsing the string. Element attrs,
|
|
1173
|
+
* component props (e.g. `opts={{ … }}` → Go map), and a provider's `value`
|
|
1174
|
+
* prop all carry it; only `expression` values do (a `spread` / `template`
|
|
1175
|
+
* value can't be the inline object literal the consumers read).
|
|
1176
|
+
*/
|
|
1177
|
+
function attachParsedAttrValues(
|
|
1178
|
+
node: IRNode,
|
|
1179
|
+
parse: (trimmed: string) => ParsedExpr,
|
|
1180
|
+
parseValue: (trimmed: string) => ParsedExpr,
|
|
1181
|
+
): void {
|
|
1182
|
+
const attach = (value: { kind: string; expr?: string; parsed?: ParsedExpr }, spreads: boolean): void => {
|
|
1183
|
+
const trimmed = value.kind === 'expression' || (spreads && value.kind === 'spread') ? value.expr?.trim() : undefined
|
|
1184
|
+
if (trimmed) value.parsed = value.kind === 'spread' ? parse(trimmed) : parseValue(trimmed)
|
|
1185
|
+
}
|
|
1186
|
+
if (node.type === 'element') {
|
|
1187
|
+
for (const attr of node.attrs) attach(attr.value, true)
|
|
1188
|
+
} else if (node.type === 'component') {
|
|
1189
|
+
for (const prop of node.props) attach(prop.value, false)
|
|
1190
|
+
} else if (node.type === 'provider') {
|
|
1191
|
+
attach(node.valueProp.value, false)
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1009
1194
|
|
|
1010
1195
|
/**
|
|
1011
1196
|
* Attach `parsed` (`parseExpression(expr.trim())`) to every `expression` node
|
|
@@ -1018,59 +1203,35 @@ const EMPTY_BOUND: ReadonlySet<string> = new Set()
|
|
|
1018
1203
|
* (#2206) so a bare-identifier `.map`/`.filter`/… callback (`tags.map(format)`)
|
|
1019
1204
|
* resolves to its declaration wherever it can appear — text/attr/prop/provider
|
|
1020
1205
|
* expressions and the loop-array expression alike — not just one hardcoded
|
|
1021
|
-
* spot. `
|
|
1022
|
-
*
|
|
1023
|
-
*
|
|
1024
|
-
*
|
|
1206
|
+
* spot. `scope` carries the enclosing loop rows' bindings down into that
|
|
1207
|
+
* resolution (Fable review, #2214) so a loop item variable that happens to
|
|
1208
|
+
* share a name with a module-scope const/function shadows it, same as real
|
|
1209
|
+
* JS scoping — resolution stays off within that loop's body.
|
|
1025
1210
|
*/
|
|
1026
|
-
function attachParsedExpressions(node: IRNode, analyzer: AnalyzerContext,
|
|
1211
|
+
function attachParsedExpressions(node: IRNode, analyzer: AnalyzerContext, scope: BindingScope = BindingScope.EMPTY): void {
|
|
1212
|
+
const bound = scope.boundNames()
|
|
1027
1213
|
const parse = (trimmed: string) => resolveCallbackMethodFunctionReferences(parseExpression(trimmed), analyzer, bound)
|
|
1028
1214
|
const parseValue = (trimmed: string) => resolveCallbackMethodFunctionReferences(parseValueExpr(trimmed), analyzer, bound)
|
|
1029
1215
|
if (node.type === 'expression') {
|
|
1030
1216
|
const trimmed = node.expr.trim()
|
|
1031
1217
|
if (trimmed) node.parsed = parse(trimmed)
|
|
1218
|
+
const childrenRead = node.parsed ? childrenReadOf(node.parsed, analyzer, scope) : null
|
|
1219
|
+
if (childrenRead) node.childrenRead = childrenRead
|
|
1032
1220
|
} else if (node.type === 'conditional' || node.type === 'if-statement') {
|
|
1033
1221
|
const trimmed = node.condition.trim()
|
|
1034
1222
|
if (trimmed) node.parsedCondition = parse(trimmed)
|
|
1035
1223
|
}
|
|
1036
|
-
|
|
1037
|
-
// lower from the tree instead of re-parsing the string. Element attrs,
|
|
1038
|
-
// component props (e.g. `opts={{ … }}` → Go map), and a provider's `value`
|
|
1039
|
-
// prop all carry it; only `expression` values do (a `spread` / `template`
|
|
1040
|
-
// value can't be the inline object literal the consumers read).
|
|
1041
|
-
if (node.type === 'element') {
|
|
1042
|
-
for (const attr of node.attrs) {
|
|
1043
|
-
if (attr.value.kind === 'expression') {
|
|
1044
|
-
const trimmed = attr.value.expr.trim()
|
|
1045
|
-
if (trimmed) attr.value.parsed = parseValue(trimmed)
|
|
1046
|
-
} else if (attr.value.kind === 'spread') {
|
|
1047
|
-
const trimmed = attr.value.expr.trim()
|
|
1048
|
-
if (trimmed) attr.value.parsed = parse(trimmed)
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
} else if (node.type === 'component') {
|
|
1052
|
-
for (const prop of node.props) {
|
|
1053
|
-
if (prop.value.kind === 'expression') {
|
|
1054
|
-
const trimmed = prop.value.expr.trim()
|
|
1055
|
-
if (trimmed) prop.value.parsed = parseValue(trimmed)
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
} else if (node.type === 'provider') {
|
|
1059
|
-
if (node.valueProp.value.kind === 'expression') {
|
|
1060
|
-
const trimmed = node.valueProp.value.expr.trim()
|
|
1061
|
-
if (trimmed) node.valueProp.value.parsed = parseValue(trimmed)
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1224
|
+
attachParsedAttrValues(node, parse, parseValue)
|
|
1064
1225
|
switch (node.type) {
|
|
1065
1226
|
case 'element':
|
|
1066
1227
|
case 'component':
|
|
1067
1228
|
case 'fragment':
|
|
1068
1229
|
case 'provider':
|
|
1069
|
-
for (const child of node.children) attachParsedExpressions(child, analyzer,
|
|
1230
|
+
for (const child of node.children) attachParsedExpressions(child, analyzer, scope)
|
|
1070
1231
|
break
|
|
1071
1232
|
case 'async':
|
|
1072
|
-
attachParsedExpressions(node.fallback, analyzer,
|
|
1073
|
-
for (const child of node.children) attachParsedExpressions(child, analyzer,
|
|
1233
|
+
attachParsedExpressions(node.fallback, analyzer, scope)
|
|
1234
|
+
for (const child of node.children) attachParsedExpressions(child, analyzer, scope)
|
|
1074
1235
|
break
|
|
1075
1236
|
case 'loop': {
|
|
1076
1237
|
// Attach the parse of the SAME `array` string the adapters consume
|
|
@@ -1081,36 +1242,35 @@ function attachParsedExpressions(node: IRNode, analyzer: AnalyzerContext, bound:
|
|
|
1081
1242
|
// own `param`/`index` exist), so it parses against the unextended `bound`.
|
|
1082
1243
|
const trimmedArray = node.array.trim()
|
|
1083
1244
|
if (trimmedArray) node.arrayParsed = parse(trimmedArray)
|
|
1084
|
-
// The loop's item
|
|
1085
|
-
//
|
|
1245
|
+
// The loop row's bindings (item or destructured names, index, preamble
|
|
1246
|
+
// locals) shadow any same-named module-scope const/function and the
|
|
1247
|
+
// children prop for everything inside the loop body (Fable review,
|
|
1086
1248
|
// #2214) — mirrors an arrow's own params in `resolveCallbackMethodFunctionReferences`.
|
|
1087
|
-
const
|
|
1088
|
-
|
|
1089
|
-
if (node.index) loopBound.add(node.index)
|
|
1090
|
-
for (const child of node.children) attachParsedExpressions(child, analyzer, loopBound)
|
|
1249
|
+
const loopScope = scope.enterLoopRow(node)
|
|
1250
|
+
for (const child of node.children) attachParsedExpressions(child, analyzer, loopScope)
|
|
1091
1251
|
// Loops also hold expression nodes off the main `children` array.
|
|
1092
1252
|
if (node.childComponent) {
|
|
1093
|
-
for (const child of node.childComponent.children) attachParsedExpressions(child, analyzer,
|
|
1253
|
+
for (const child of node.childComponent.children) attachParsedExpressions(child, analyzer, loopScope)
|
|
1094
1254
|
}
|
|
1095
1255
|
for (const nested of node.nestedComponents ?? []) {
|
|
1096
|
-
for (const child of nested.children) attachParsedExpressions(child, analyzer,
|
|
1256
|
+
for (const child of nested.children) attachParsedExpressions(child, analyzer, loopScope)
|
|
1097
1257
|
}
|
|
1098
1258
|
for (const seg of node.flatMapCallback?.segments ?? []) {
|
|
1099
|
-
if (seg.kind === 'jsx') attachParsedExpressions(seg.ir, analyzer,
|
|
1259
|
+
if (seg.kind === 'jsx') attachParsedExpressions(seg.ir, analyzer, loopScope)
|
|
1100
1260
|
}
|
|
1101
1261
|
// Preamble leaves (array-builder bodies) are nested IR the same way.
|
|
1102
1262
|
for (const seg of node.preamble?.segments ?? []) {
|
|
1103
|
-
if (seg.kind === 'jsx') attachParsedExpressions(seg.ir, analyzer,
|
|
1263
|
+
if (seg.kind === 'jsx') attachParsedExpressions(seg.ir, analyzer, loopScope)
|
|
1104
1264
|
}
|
|
1105
1265
|
break
|
|
1106
1266
|
}
|
|
1107
1267
|
case 'conditional':
|
|
1108
|
-
attachParsedExpressions(node.whenTrue, analyzer,
|
|
1109
|
-
attachParsedExpressions(node.whenFalse, analyzer,
|
|
1268
|
+
attachParsedExpressions(node.whenTrue, analyzer, scope)
|
|
1269
|
+
attachParsedExpressions(node.whenFalse, analyzer, scope)
|
|
1110
1270
|
break
|
|
1111
1271
|
case 'if-statement':
|
|
1112
|
-
attachParsedExpressions(node.consequent, analyzer,
|
|
1113
|
-
if (node.alternate) attachParsedExpressions(node.alternate, analyzer,
|
|
1272
|
+
attachParsedExpressions(node.consequent, analyzer, scope)
|
|
1273
|
+
if (node.alternate) attachParsedExpressions(node.alternate, analyzer, scope)
|
|
1114
1274
|
break
|
|
1115
1275
|
}
|
|
1116
1276
|
}
|
|
@@ -2199,7 +2359,8 @@ function transformSelfClosingComponent(
|
|
|
2199
2359
|
|
|
2200
2360
|
/**
|
|
2201
2361
|
* Check if a fragment is "transparent" (just passes through children).
|
|
2202
|
-
* Pattern: <>{children}
|
|
2362
|
+
* Pattern: <>{children}</>, <>{props.children}</>, or the children prop
|
|
2363
|
+
* through another binding (`<>{kids}</>` for `{ children: kids }`).
|
|
2203
2364
|
* Transparent fragments don't need scope markers on their children.
|
|
2204
2365
|
*/
|
|
2205
2366
|
function isTransparentFragment(
|
|
@@ -2223,19 +2384,11 @@ function isTransparentFragment(
|
|
|
2223
2384
|
if (!ts.isJsxExpression(child)) return false
|
|
2224
2385
|
if (!child.expression) return false
|
|
2225
2386
|
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
//
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
// Check for custom props object name (e.g., p.children)
|
|
2233
|
-
const propsName = ctx.analyzer.propsObjectName
|
|
2234
|
-
if (propsName && exprText === `${propsName}.children`) {
|
|
2235
|
-
return true
|
|
2236
|
-
}
|
|
2237
|
-
|
|
2238
|
-
return false
|
|
2387
|
+
// A bare read of the component's own children prop, through whichever
|
|
2388
|
+
// binding reads it (`childrenReadOf`, #3572): the same answer the
|
|
2389
|
+
// expression node itself gets.
|
|
2390
|
+
const parsed = parseExpression(child.expression.getText(ctx.sourceFile).trim())
|
|
2391
|
+
return childrenReadOf(parsed, ctx.analyzer, ctx.scope) === 'bare'
|
|
2239
2392
|
}
|
|
2240
2393
|
|
|
2241
2394
|
// #1335: a fragment-wrapped jsx-children prop value lands as
|
|
@@ -2661,7 +2814,7 @@ function transformExpressionInner(
|
|
|
2661
2814
|
// result so memo-as-value (Case 2) and renamed-prop (Case 3) cases —
|
|
2662
2815
|
// which the regex path misses — light up the reactive flag during the
|
|
2663
2816
|
// migration period.
|
|
2664
|
-
const reactive =
|
|
2817
|
+
const reactive = isReactiveTextRead(exprText, ctx, expr, origin)
|
|
2665
2818
|
// @client expressions always need slotId and are treated as reactive for client-side evaluation
|
|
2666
2819
|
// Expressions inside loops that reference the loop parameter need slotId
|
|
2667
2820
|
// so fine-grained effects can target them for per-item signal updates.
|
|
@@ -2721,38 +2874,7 @@ function transformJsxFunctionCall(
|
|
|
2721
2874
|
ctx: TransformContext,
|
|
2722
2875
|
_isClientOnly: boolean
|
|
2723
2876
|
): IRNode {
|
|
2724
|
-
|
|
2725
|
-
const substitutions = new Map<string, string>()
|
|
2726
|
-
for (let i = 0; i < jsxFunc.params.length; i++) {
|
|
2727
|
-
const paramName = jsxFunc.params[i]
|
|
2728
|
-
const arg = callExpr.arguments[i]
|
|
2729
|
-
if (arg) {
|
|
2730
|
-
substitutions.set(paramName, ctx.getJS(arg))
|
|
2731
|
-
}
|
|
2732
|
-
}
|
|
2733
|
-
|
|
2734
|
-
// Temporarily override getJS to apply parameter substitutions.
|
|
2735
|
-
// Capture analyzer.getJS (the base implementation) to avoid circular references.
|
|
2736
|
-
const baseGetJS = ctx.analyzer.getJS.bind(ctx.analyzer)
|
|
2737
|
-
const originalCtxGetJS = ctx.getJS
|
|
2738
|
-
const originalAnalyzerGetJS = ctx.analyzer.getJS
|
|
2739
|
-
|
|
2740
|
-
const substitutedGetJS = (node: ts.Node) => {
|
|
2741
|
-
let text = baseGetJS(node)
|
|
2742
|
-
for (const [paramName, argExpr] of substitutions) {
|
|
2743
|
-
// Replacer function, not the string form: `argExpr` is arbitrary
|
|
2744
|
-
// caller-supplied JS text and may itself contain `$` sequences
|
|
2745
|
-
// (`$&`, `$1`, …) that `String.replace`'s string-replacement form
|
|
2746
|
-
// would interpret specially instead of inserting literally (#2592).
|
|
2747
|
-
text = text.replace(identifierPattern(paramName, 'g'), () => argExpr)
|
|
2748
|
-
}
|
|
2749
|
-
return text
|
|
2750
|
-
}
|
|
2751
|
-
|
|
2752
|
-
ctx.getJS = substitutedGetJS
|
|
2753
|
-
ctx.analyzer.getJS = substitutedGetJS
|
|
2754
|
-
|
|
2755
|
-
try {
|
|
2877
|
+
return withHelperParamsSubstituted(callExpr, jsxFunc.params, ctx, () => {
|
|
2756
2878
|
const result = transformNode(jsxFunc.jsxReturn, ctx)
|
|
2757
2879
|
return result ?? {
|
|
2758
2880
|
type: 'expression' as const,
|
|
@@ -2768,27 +2890,38 @@ function transformJsxFunctionCall(
|
|
|
2768
2890
|
freeRefs: [],
|
|
2769
2891
|
},
|
|
2770
2892
|
}
|
|
2771
|
-
}
|
|
2772
|
-
ctx.getJS = originalCtxGetJS
|
|
2773
|
-
ctx.analyzer.getJS = originalAnalyzerGetJS
|
|
2774
|
-
}
|
|
2893
|
+
})
|
|
2775
2894
|
}
|
|
2776
2895
|
|
|
2777
|
-
|
|
2896
|
+
/**
|
|
2897
|
+
* Run `build` with the helper's parameters substituted by the call's
|
|
2898
|
+
* arguments, for both inliners (#569). The substitution is textual (`getJS`
|
|
2899
|
+
* output), so the free references the built IR records still name the
|
|
2900
|
+
* parameters, which resolve to nothing in the component. Afterwards each
|
|
2901
|
+
* parameter reference is replaced by the argument's own free references
|
|
2902
|
+
* (`rebindHelperParamRefs`), so a consumer that reads the IR instead of the
|
|
2903
|
+
* text sees that `render(count())` reads the `count` signal (#3509).
|
|
2904
|
+
*/
|
|
2905
|
+
function withHelperParamsSubstituted(
|
|
2778
2906
|
callExpr: ts.CallExpression,
|
|
2779
|
-
|
|
2907
|
+
params: readonly string[],
|
|
2780
2908
|
ctx: TransformContext,
|
|
2909
|
+
build: (getText: (node: ts.Node) => string) => IRNode,
|
|
2781
2910
|
): IRNode {
|
|
2782
2911
|
// Build substitution map: paramName → argument expression text
|
|
2783
2912
|
const substitutions = new Map<string, string>()
|
|
2784
|
-
|
|
2785
|
-
|
|
2913
|
+
const argRefs = new Map<string, FreeReference[]>()
|
|
2914
|
+
const env = makeBindingEnv(ctx)
|
|
2915
|
+
for (let i = 0; i < params.length; i++) {
|
|
2786
2916
|
const arg = callExpr.arguments[i]
|
|
2787
2917
|
if (arg) {
|
|
2788
|
-
substitutions.set(
|
|
2918
|
+
substitutions.set(params[i], ctx.getJS(arg))
|
|
2919
|
+
argRefs.set(params[i], resolveFreeRefs(arg, env))
|
|
2789
2920
|
}
|
|
2790
2921
|
}
|
|
2791
2922
|
|
|
2923
|
+
// Temporarily override getJS to apply parameter substitutions.
|
|
2924
|
+
// Capture analyzer.getJS (the base implementation) to avoid circular references.
|
|
2792
2925
|
const baseGetJS = ctx.analyzer.getJS.bind(ctx.analyzer)
|
|
2793
2926
|
const originalCtxGetJS = ctx.getJS
|
|
2794
2927
|
const originalAnalyzerGetJS = ctx.analyzer.getJS
|
|
@@ -2809,14 +2942,25 @@ function transformMultiReturnJsxFunctionCall(
|
|
|
2809
2942
|
ctx.analyzer.getJS = substitutedGetJS
|
|
2810
2943
|
|
|
2811
2944
|
try {
|
|
2812
|
-
const
|
|
2813
|
-
|
|
2945
|
+
const result = build(substitutedGetJS)
|
|
2946
|
+
rebindHelperParamRefs(result, argRefs)
|
|
2947
|
+
return result
|
|
2814
2948
|
} finally {
|
|
2815
2949
|
ctx.getJS = originalCtxGetJS
|
|
2816
2950
|
ctx.analyzer.getJS = originalAnalyzerGetJS
|
|
2817
2951
|
}
|
|
2818
2952
|
}
|
|
2819
2953
|
|
|
2954
|
+
function transformMultiReturnJsxFunctionCall(
|
|
2955
|
+
callExpr: ts.CallExpression,
|
|
2956
|
+
info: MultiReturnJsxInfo,
|
|
2957
|
+
ctx: TransformContext,
|
|
2958
|
+
): IRNode {
|
|
2959
|
+
const loc = getSourceLocation(callExpr, ctx.sourceFile, ctx.filePath)
|
|
2960
|
+
return withHelperParamsSubstituted(callExpr, info.params, ctx, (getText) =>
|
|
2961
|
+
foldMultiReturnBranches(info, ctx, loc, getText))
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2820
2964
|
/**
|
|
2821
2965
|
* Fold an extracted multi-return branch structure (if/else-if chain or switch)
|
|
2822
2966
|
* into a right-nested chain of `IRConditional` nodes, terminating in the
|
|
@@ -3707,15 +3851,15 @@ function resolveCallbackMethodFunctionReferenceIdentifier(name: string, analyzer
|
|
|
3707
3851
|
* const/function is never resolved against the const/function tables
|
|
3708
3852
|
* (Fable review, #2214): it grows exactly like {@link freeVarsInBody}'s own
|
|
3709
3853
|
* `bound` set, at the SAME `arrow` case. The initial call from
|
|
3710
|
-
* `attachParsedExpressions` seeds it with the enclosing loop'
|
|
3711
|
-
*
|
|
3854
|
+
* `attachParsedExpressions` seeds it with the enclosing loop rows' bound
|
|
3855
|
+
* names too (a loop's item variable shadows a same-named module const the
|
|
3712
3856
|
* same way a callback arrow's param does — `origin.freeRefs` already tags
|
|
3713
3857
|
* such a name `kind: 'render-item'`, this walk now honors it).
|
|
3714
3858
|
*/
|
|
3715
3859
|
function resolveCallbackMethodFunctionReferences(
|
|
3716
3860
|
expr: ParsedExpr,
|
|
3717
3861
|
analyzer: AnalyzerContext,
|
|
3718
|
-
bound: ReadonlySet<string
|
|
3862
|
+
bound: ReadonlySet<string>,
|
|
3719
3863
|
): ParsedExpr {
|
|
3720
3864
|
function visit(e: ParsedExpr, bound: ReadonlySet<string>): ParsedExpr {
|
|
3721
3865
|
switch (e.kind) {
|
|
@@ -7130,6 +7274,17 @@ function computeReactivityFlags(
|
|
|
7130
7274
|
}
|
|
7131
7275
|
}
|
|
7132
7276
|
|
|
7277
|
+
/**
|
|
7278
|
+
* An event handler's source as `IREvent.handler`: one expression that
|
|
7279
|
+
* emitters pass verbatim as the listener argument, so a comma sequence
|
|
7280
|
+
* (`{a, b}`) is parenthesized (#3538).
|
|
7281
|
+
*/
|
|
7282
|
+
function eventHandlerText(handlerExpr: ts.Expression, ctx: TransformContext): string {
|
|
7283
|
+
const isSequence =
|
|
7284
|
+
ts.isBinaryExpression(handlerExpr) && handlerExpr.operatorToken.kind === ts.SyntaxKind.CommaToken
|
|
7285
|
+
return isSequence ? `(${ctx.getJS(handlerExpr)})` : ctx.getJS(handlerExpr)
|
|
7286
|
+
}
|
|
7287
|
+
|
|
7133
7288
|
/**
|
|
7134
7289
|
* Emit BF047 if a ref / event-handler callback body references a
|
|
7135
7290
|
* JSX-typed branch-local — the multi-return pipeline has no way to
|
|
@@ -7196,12 +7351,12 @@ function processAttributes(
|
|
|
7196
7351
|
// (`click`, not `Click`), so strip the `on` prefix and downcase.
|
|
7197
7352
|
if (isEventHandlerName(rawName)) {
|
|
7198
7353
|
if (attr.initializer && ts.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
7199
|
-
const
|
|
7200
|
-
reportJsxBranchLocalInCallback(
|
|
7354
|
+
const handlerExpr = attr.initializer.expression
|
|
7355
|
+
reportJsxBranchLocalInCallback(handlerExpr, ctx)
|
|
7201
7356
|
events.push({
|
|
7202
|
-
name:
|
|
7357
|
+
name: rawName.slice(2).toLowerCase(),
|
|
7203
7358
|
originalAttr: rawName,
|
|
7204
|
-
handler: ctx
|
|
7359
|
+
handler: eventHandlerText(handlerExpr, ctx),
|
|
7205
7360
|
loc: getSourceLocation(attr, ctx.sourceFile, ctx.filePath),
|
|
7206
7361
|
})
|
|
7207
7362
|
}
|
|
@@ -7919,17 +8074,50 @@ function getAttributeValue(attr: ts.JsxAttribute, ctx: TransformContext): AttrVa
|
|
|
7919
8074
|
if (ts.isBinaryExpression(expr) && expr.operatorToken.kind === ts.SyntaxKind.BarBarToken) {
|
|
7920
8075
|
if (ts.isIdentifier(expr.right) && expr.right.text === 'undefined') {
|
|
7921
8076
|
const baseExpr = ctx.getJS(expr.left)
|
|
7922
|
-
return AttrValueOf.expression(baseExpr, {
|
|
8077
|
+
return AttrValueOf.expression(baseExpr, {
|
|
8078
|
+
presenceOrUndefined: true,
|
|
8079
|
+
typed: typedSourceBeside(expr.left, baseExpr, ctx),
|
|
8080
|
+
})
|
|
7923
8081
|
}
|
|
7924
8082
|
}
|
|
7925
8083
|
|
|
7926
8084
|
const exprText = ctx.getJS(expr)
|
|
7927
|
-
return AttrValueOf.expression(exprText)
|
|
8085
|
+
return AttrValueOf.expression(exprText, { typed: typedSourceBeside(expr, exprText, ctx) })
|
|
7928
8086
|
}
|
|
7929
8087
|
|
|
7930
8088
|
return AttrValueOf.booleanAttr()
|
|
7931
8089
|
}
|
|
7932
8090
|
|
|
8091
|
+
/**
|
|
8092
|
+
* The author's text for `node` with its TypeScript syntax intact, paired with
|
|
8093
|
+
* the `js` that `ctx.getJS(node)` produced — so a TSX-emitting adapter can
|
|
8094
|
+
* write it in place of `js`, and an assertion the source needed to type-check
|
|
8095
|
+
* (`value={store as never}`) is still there when the emitted template is
|
|
8096
|
+
* type-checked (#2573).
|
|
8097
|
+
*
|
|
8098
|
+
* `undefined` (the adapter keeps `js`) unless `js` is exactly `node`'s type
|
|
8099
|
+
* strip: a synthetic re-parse (not a live position in this source file), or a
|
|
8100
|
+
* `ctx.getJS` that substitutes on top of the strip (branch-scope locals,
|
|
8101
|
+
* inlined helper parameters), has no author text that matches it. Also
|
|
8102
|
+
* `undefined` when the strip removed nothing.
|
|
8103
|
+
*/
|
|
8104
|
+
function typedSourceBeside(
|
|
8105
|
+
node: ts.Node,
|
|
8106
|
+
js: string,
|
|
8107
|
+
ctx: TransformContext,
|
|
8108
|
+
): TypedExprSource | undefined {
|
|
8109
|
+
let own: ts.SourceFile | undefined
|
|
8110
|
+
try {
|
|
8111
|
+
own = node.getSourceFile()
|
|
8112
|
+
} catch {
|
|
8113
|
+
own = undefined
|
|
8114
|
+
}
|
|
8115
|
+
if (own !== ctx.sourceFile) return undefined
|
|
8116
|
+
if (reconstructWithoutTypes(node, ctx.sourceFile, ctx.analyzer.typeExcludeRanges) !== js) return undefined
|
|
8117
|
+
const tsx = node.getText(ctx.sourceFile)
|
|
8118
|
+
return tsx === js ? undefined : { tsx: tsxSourceText(tsx), forExpr: js }
|
|
8119
|
+
}
|
|
8120
|
+
|
|
7933
8121
|
/**
|
|
7934
8122
|
* Convert a static style object literal to a CSS string at compile time.
|
|
7935
8123
|
* Returns null if any property value is non-static (dynamic expression, template literal, etc.).
|