@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/jsx-to-ir.ts
CHANGED
|
@@ -33,15 +33,18 @@ 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'
|
|
47
|
+
import { fallbackChainParts, nullishChainParts } from './children-nullish.ts'
|
|
45
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'
|
|
@@ -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'
|
|
@@ -795,7 +798,7 @@ export function createTransformContext(analyzer: AnalyzerContext): TransformCont
|
|
|
795
798
|
// Shared by `patterns.props` (regex matching) and `boundPropNames`
|
|
796
799
|
// (exact-name binding checks, #2835) so both agree on which prop
|
|
797
800
|
// params are in play — `children` excluded from both the same way.
|
|
798
|
-
const propsParamsForMatching = analyzer.propsParams.filter(p => p
|
|
801
|
+
const propsParamsForMatching = analyzer.propsParams.filter(p => !isChildrenPropParam(p))
|
|
799
802
|
return {
|
|
800
803
|
analyzer,
|
|
801
804
|
sourceFile: analyzer.sourceFile,
|
|
@@ -965,6 +968,7 @@ function makeBindingEnv(ctx: TransformContext): BindingEnvironment {
|
|
|
965
968
|
memos: a.memos,
|
|
966
969
|
propsParams: a.propsParams,
|
|
967
970
|
propsObjectName: a.propsObjectName,
|
|
971
|
+
propsObjectAliases: propsObjectAliasNames(a, ctx.scope),
|
|
968
972
|
restPropsName: a.restPropsName,
|
|
969
973
|
localConstants: a.localConstants,
|
|
970
974
|
localFunctions: a.localFunctions,
|
|
@@ -1000,8 +1004,193 @@ function parseValueExpr(trimmed: string): ParsedExpr {
|
|
|
1000
1004
|
return parseExpression(trimmed.startsWith('{') ? `(${trimmed})` : trimmed)
|
|
1001
1005
|
}
|
|
1002
1006
|
|
|
1003
|
-
|
|
1004
|
-
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
|
+
}
|
|
1005
1194
|
|
|
1006
1195
|
/**
|
|
1007
1196
|
* Attach `parsed` (`parseExpression(expr.trim())`) to every `expression` node
|
|
@@ -1014,59 +1203,35 @@ const EMPTY_BOUND: ReadonlySet<string> = new Set()
|
|
|
1014
1203
|
* (#2206) so a bare-identifier `.map`/`.filter`/… callback (`tags.map(format)`)
|
|
1015
1204
|
* resolves to its declaration wherever it can appear — text/attr/prop/provider
|
|
1016
1205
|
* expressions and the loop-array expression alike — not just one hardcoded
|
|
1017
|
-
* spot. `
|
|
1018
|
-
*
|
|
1019
|
-
*
|
|
1020
|
-
*
|
|
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.
|
|
1021
1210
|
*/
|
|
1022
|
-
function attachParsedExpressions(node: IRNode, analyzer: AnalyzerContext,
|
|
1211
|
+
function attachParsedExpressions(node: IRNode, analyzer: AnalyzerContext, scope: BindingScope = BindingScope.EMPTY): void {
|
|
1212
|
+
const bound = scope.boundNames()
|
|
1023
1213
|
const parse = (trimmed: string) => resolveCallbackMethodFunctionReferences(parseExpression(trimmed), analyzer, bound)
|
|
1024
1214
|
const parseValue = (trimmed: string) => resolveCallbackMethodFunctionReferences(parseValueExpr(trimmed), analyzer, bound)
|
|
1025
1215
|
if (node.type === 'expression') {
|
|
1026
1216
|
const trimmed = node.expr.trim()
|
|
1027
1217
|
if (trimmed) node.parsed = parse(trimmed)
|
|
1218
|
+
const childrenRead = node.parsed ? childrenReadOf(node.parsed, analyzer, scope) : null
|
|
1219
|
+
if (childrenRead) node.childrenRead = childrenRead
|
|
1028
1220
|
} else if (node.type === 'conditional' || node.type === 'if-statement') {
|
|
1029
1221
|
const trimmed = node.condition.trim()
|
|
1030
1222
|
if (trimmed) node.parsedCondition = parse(trimmed)
|
|
1031
1223
|
}
|
|
1032
|
-
|
|
1033
|
-
// lower from the tree instead of re-parsing the string. Element attrs,
|
|
1034
|
-
// component props (e.g. `opts={{ … }}` → Go map), and a provider's `value`
|
|
1035
|
-
// prop all carry it; only `expression` values do (a `spread` / `template`
|
|
1036
|
-
// value can't be the inline object literal the consumers read).
|
|
1037
|
-
if (node.type === 'element') {
|
|
1038
|
-
for (const attr of node.attrs) {
|
|
1039
|
-
if (attr.value.kind === 'expression') {
|
|
1040
|
-
const trimmed = attr.value.expr.trim()
|
|
1041
|
-
if (trimmed) attr.value.parsed = parseValue(trimmed)
|
|
1042
|
-
} else if (attr.value.kind === 'spread') {
|
|
1043
|
-
const trimmed = attr.value.expr.trim()
|
|
1044
|
-
if (trimmed) attr.value.parsed = parse(trimmed)
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
} else if (node.type === 'component') {
|
|
1048
|
-
for (const prop of node.props) {
|
|
1049
|
-
if (prop.value.kind === 'expression') {
|
|
1050
|
-
const trimmed = prop.value.expr.trim()
|
|
1051
|
-
if (trimmed) prop.value.parsed = parseValue(trimmed)
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
} else if (node.type === 'provider') {
|
|
1055
|
-
if (node.valueProp.value.kind === 'expression') {
|
|
1056
|
-
const trimmed = node.valueProp.value.expr.trim()
|
|
1057
|
-
if (trimmed) node.valueProp.value.parsed = parseValue(trimmed)
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1224
|
+
attachParsedAttrValues(node, parse, parseValue)
|
|
1060
1225
|
switch (node.type) {
|
|
1061
1226
|
case 'element':
|
|
1062
1227
|
case 'component':
|
|
1063
1228
|
case 'fragment':
|
|
1064
1229
|
case 'provider':
|
|
1065
|
-
for (const child of node.children) attachParsedExpressions(child, analyzer,
|
|
1230
|
+
for (const child of node.children) attachParsedExpressions(child, analyzer, scope)
|
|
1066
1231
|
break
|
|
1067
1232
|
case 'async':
|
|
1068
|
-
attachParsedExpressions(node.fallback, analyzer,
|
|
1069
|
-
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)
|
|
1070
1235
|
break
|
|
1071
1236
|
case 'loop': {
|
|
1072
1237
|
// Attach the parse of the SAME `array` string the adapters consume
|
|
@@ -1077,36 +1242,35 @@ function attachParsedExpressions(node: IRNode, analyzer: AnalyzerContext, bound:
|
|
|
1077
1242
|
// own `param`/`index` exist), so it parses against the unextended `bound`.
|
|
1078
1243
|
const trimmedArray = node.array.trim()
|
|
1079
1244
|
if (trimmedArray) node.arrayParsed = parse(trimmedArray)
|
|
1080
|
-
// The loop's item
|
|
1081
|
-
//
|
|
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,
|
|
1082
1248
|
// #2214) — mirrors an arrow's own params in `resolveCallbackMethodFunctionReferences`.
|
|
1083
|
-
const
|
|
1084
|
-
|
|
1085
|
-
if (node.index) loopBound.add(node.index)
|
|
1086
|
-
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)
|
|
1087
1251
|
// Loops also hold expression nodes off the main `children` array.
|
|
1088
1252
|
if (node.childComponent) {
|
|
1089
|
-
for (const child of node.childComponent.children) attachParsedExpressions(child, analyzer,
|
|
1253
|
+
for (const child of node.childComponent.children) attachParsedExpressions(child, analyzer, loopScope)
|
|
1090
1254
|
}
|
|
1091
1255
|
for (const nested of node.nestedComponents ?? []) {
|
|
1092
|
-
for (const child of nested.children) attachParsedExpressions(child, analyzer,
|
|
1256
|
+
for (const child of nested.children) attachParsedExpressions(child, analyzer, loopScope)
|
|
1093
1257
|
}
|
|
1094
1258
|
for (const seg of node.flatMapCallback?.segments ?? []) {
|
|
1095
|
-
if (seg.kind === 'jsx') attachParsedExpressions(seg.ir, analyzer,
|
|
1259
|
+
if (seg.kind === 'jsx') attachParsedExpressions(seg.ir, analyzer, loopScope)
|
|
1096
1260
|
}
|
|
1097
1261
|
// Preamble leaves (array-builder bodies) are nested IR the same way.
|
|
1098
1262
|
for (const seg of node.preamble?.segments ?? []) {
|
|
1099
|
-
if (seg.kind === 'jsx') attachParsedExpressions(seg.ir, analyzer,
|
|
1263
|
+
if (seg.kind === 'jsx') attachParsedExpressions(seg.ir, analyzer, loopScope)
|
|
1100
1264
|
}
|
|
1101
1265
|
break
|
|
1102
1266
|
}
|
|
1103
1267
|
case 'conditional':
|
|
1104
|
-
attachParsedExpressions(node.whenTrue, analyzer,
|
|
1105
|
-
attachParsedExpressions(node.whenFalse, analyzer,
|
|
1268
|
+
attachParsedExpressions(node.whenTrue, analyzer, scope)
|
|
1269
|
+
attachParsedExpressions(node.whenFalse, analyzer, scope)
|
|
1106
1270
|
break
|
|
1107
1271
|
case 'if-statement':
|
|
1108
|
-
attachParsedExpressions(node.consequent, analyzer,
|
|
1109
|
-
if (node.alternate) attachParsedExpressions(node.alternate, analyzer,
|
|
1272
|
+
attachParsedExpressions(node.consequent, analyzer, scope)
|
|
1273
|
+
if (node.alternate) attachParsedExpressions(node.alternate, analyzer, scope)
|
|
1110
1274
|
break
|
|
1111
1275
|
}
|
|
1112
1276
|
}
|
|
@@ -2195,7 +2359,8 @@ function transformSelfClosingComponent(
|
|
|
2195
2359
|
|
|
2196
2360
|
/**
|
|
2197
2361
|
* Check if a fragment is "transparent" (just passes through children).
|
|
2198
|
-
* Pattern: <>{children}
|
|
2362
|
+
* Pattern: <>{children}</>, <>{props.children}</>, or the children prop
|
|
2363
|
+
* through another binding (`<>{kids}</>` for `{ children: kids }`).
|
|
2199
2364
|
* Transparent fragments don't need scope markers on their children.
|
|
2200
2365
|
*/
|
|
2201
2366
|
function isTransparentFragment(
|
|
@@ -2219,19 +2384,11 @@ function isTransparentFragment(
|
|
|
2219
2384
|
if (!ts.isJsxExpression(child)) return false
|
|
2220
2385
|
if (!child.expression) return false
|
|
2221
2386
|
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
//
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
// Check for custom props object name (e.g., p.children)
|
|
2229
|
-
const propsName = ctx.analyzer.propsObjectName
|
|
2230
|
-
if (propsName && exprText === `${propsName}.children`) {
|
|
2231
|
-
return true
|
|
2232
|
-
}
|
|
2233
|
-
|
|
2234
|
-
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'
|
|
2235
2392
|
}
|
|
2236
2393
|
|
|
2237
2394
|
// #1335: a fragment-wrapped jsx-children prop value lands as
|
|
@@ -2657,7 +2814,7 @@ function transformExpressionInner(
|
|
|
2657
2814
|
// result so memo-as-value (Case 2) and renamed-prop (Case 3) cases —
|
|
2658
2815
|
// which the regex path misses — light up the reactive flag during the
|
|
2659
2816
|
// migration period.
|
|
2660
|
-
const reactive =
|
|
2817
|
+
const reactive = isReactiveTextRead(exprText, ctx, expr, origin)
|
|
2661
2818
|
// @client expressions always need slotId and are treated as reactive for client-side evaluation
|
|
2662
2819
|
// Expressions inside loops that reference the loop parameter need slotId
|
|
2663
2820
|
// so fine-grained effects can target them for per-item signal updates.
|
|
@@ -3694,15 +3851,15 @@ function resolveCallbackMethodFunctionReferenceIdentifier(name: string, analyzer
|
|
|
3694
3851
|
* const/function is never resolved against the const/function tables
|
|
3695
3852
|
* (Fable review, #2214): it grows exactly like {@link freeVarsInBody}'s own
|
|
3696
3853
|
* `bound` set, at the SAME `arrow` case. The initial call from
|
|
3697
|
-
* `attachParsedExpressions` seeds it with the enclosing loop'
|
|
3698
|
-
*
|
|
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
|
|
3699
3856
|
* same way a callback arrow's param does — `origin.freeRefs` already tags
|
|
3700
3857
|
* such a name `kind: 'render-item'`, this walk now honors it).
|
|
3701
3858
|
*/
|
|
3702
3859
|
function resolveCallbackMethodFunctionReferences(
|
|
3703
3860
|
expr: ParsedExpr,
|
|
3704
3861
|
analyzer: AnalyzerContext,
|
|
3705
|
-
bound: ReadonlySet<string
|
|
3862
|
+
bound: ReadonlySet<string>,
|
|
3706
3863
|
): ParsedExpr {
|
|
3707
3864
|
function visit(e: ParsedExpr, bound: ReadonlySet<string>): ParsedExpr {
|
|
3708
3865
|
switch (e.kind) {
|
|
@@ -7117,6 +7274,17 @@ function computeReactivityFlags(
|
|
|
7117
7274
|
}
|
|
7118
7275
|
}
|
|
7119
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
|
+
|
|
7120
7288
|
/**
|
|
7121
7289
|
* Emit BF047 if a ref / event-handler callback body references a
|
|
7122
7290
|
* JSX-typed branch-local — the multi-return pipeline has no way to
|
|
@@ -7183,12 +7351,12 @@ function processAttributes(
|
|
|
7183
7351
|
// (`click`, not `Click`), so strip the `on` prefix and downcase.
|
|
7184
7352
|
if (isEventHandlerName(rawName)) {
|
|
7185
7353
|
if (attr.initializer && ts.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
7186
|
-
const
|
|
7187
|
-
reportJsxBranchLocalInCallback(
|
|
7354
|
+
const handlerExpr = attr.initializer.expression
|
|
7355
|
+
reportJsxBranchLocalInCallback(handlerExpr, ctx)
|
|
7188
7356
|
events.push({
|
|
7189
|
-
name:
|
|
7357
|
+
name: rawName.slice(2).toLowerCase(),
|
|
7190
7358
|
originalAttr: rawName,
|
|
7191
|
-
handler: ctx
|
|
7359
|
+
handler: eventHandlerText(handlerExpr, ctx),
|
|
7192
7360
|
loc: getSourceLocation(attr, ctx.sourceFile, ctx.filePath),
|
|
7193
7361
|
})
|
|
7194
7362
|
}
|
|
@@ -7906,17 +8074,50 @@ function getAttributeValue(attr: ts.JsxAttribute, ctx: TransformContext): AttrVa
|
|
|
7906
8074
|
if (ts.isBinaryExpression(expr) && expr.operatorToken.kind === ts.SyntaxKind.BarBarToken) {
|
|
7907
8075
|
if (ts.isIdentifier(expr.right) && expr.right.text === 'undefined') {
|
|
7908
8076
|
const baseExpr = ctx.getJS(expr.left)
|
|
7909
|
-
return AttrValueOf.expression(baseExpr, {
|
|
8077
|
+
return AttrValueOf.expression(baseExpr, {
|
|
8078
|
+
presenceOrUndefined: true,
|
|
8079
|
+
typed: typedSourceBeside(expr.left, baseExpr, ctx),
|
|
8080
|
+
})
|
|
7910
8081
|
}
|
|
7911
8082
|
}
|
|
7912
8083
|
|
|
7913
8084
|
const exprText = ctx.getJS(expr)
|
|
7914
|
-
return AttrValueOf.expression(exprText)
|
|
8085
|
+
return AttrValueOf.expression(exprText, { typed: typedSourceBeside(expr, exprText, ctx) })
|
|
7915
8086
|
}
|
|
7916
8087
|
|
|
7917
8088
|
return AttrValueOf.booleanAttr()
|
|
7918
8089
|
}
|
|
7919
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
|
+
|
|
7920
8121
|
/**
|
|
7921
8122
|
* Convert a static style object literal to a CSS string at compile time.
|
|
7922
8123
|
* Returns null if any property value is non-static (dynamic expression, template literal, etc.).
|