@barefootjs/jsx 0.40.1 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/boolean-result.d.ts +32 -10
- package/dist/adapters/boolean-result.d.ts.map +1 -1
- package/dist/adapters/brace-delimiter-text.d.ts +18 -0
- package/dist/adapters/brace-delimiter-text.d.ts.map +1 -0
- package/dist/adapters/callback-method.d.ts +45 -5
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +3 -4
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/computed-const.d.ts +11 -1
- package/dist/adapters/computed-const.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +24 -12
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-bound-names.d.ts +9 -1
- package/dist/adapters/loop-bound-names.d.ts.map +1 -1
- package/dist/adapters/loop-row-type.d.ts +59 -0
- package/dist/adapters/loop-row-type.d.ts.map +1 -0
- package/dist/adapters/nil-reading.d.ts +63 -0
- package/dist/adapters/nil-reading.d.ts.map +1 -0
- package/dist/adapters/non-primitive-equality.d.ts +33 -0
- package/dist/adapters/non-primitive-equality.d.ts.map +1 -0
- package/dist/adapters/number-value.d.ts +5 -3
- package/dist/adapters/number-value.d.ts.map +1 -1
- package/dist/adapters/operand-typing.d.ts +126 -0
- package/dist/adapters/operand-typing.d.ts.map +1 -0
- package/dist/adapters/parsed-expr-emitter.d.ts +80 -12
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/primitive-plan.d.ts +320 -0
- package/dist/adapters/primitive-plan.d.ts.map +1 -0
- package/dist/adapters/prop-classes.d.ts +5 -0
- package/dist/adapters/prop-classes.d.ts.map +1 -1
- package/dist/analyzer-context.d.ts +4 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts +63 -8
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +12 -0
- package/dist/event-handler-name.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +8 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +20 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4903 -2311
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/child-props-object.d.ts +106 -0
- package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -0
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +4 -2
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/index.d.ts +2 -6
- package/dist/ir-to-client-js/index.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
- package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +30 -18
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
- 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 +3 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +3 -2
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts +1 -0
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +51 -34
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/prop-rewrite.d.ts +7 -0
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +58 -13
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/props-object-whole-read.d.ts +15 -0
- package/dist/props-object-whole-read.d.ts.map +1 -0
- package/dist/rich-type-refusal.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +85 -10
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/scope/lexical-scope-walk.d.ts +3 -2
- package/dist/scope/lexical-scope-walk.d.ts.map +1 -1
- package/dist/scope/root-prop-alias.d.ts +10 -7
- package/dist/scope/root-prop-alias.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +39 -3
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/strip-types.d.ts +13 -0
- package/dist/strip-types.d.ts.map +1 -1
- package/dist/template-position-walk.d.ts +21 -3
- package/dist/template-position-walk.d.ts.map +1 -1
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +9 -9
- package/src/__tests__/binding-scope.test.ts +89 -1
- package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
- package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
- package/src/__tests__/body-destructured-props-live.test.ts +5 -5
- package/src/__tests__/boolean-result.test.ts +22 -5
- package/src/__tests__/brace-delimiter-text.test.ts +26 -0
- package/src/__tests__/callback-method.test.ts +62 -2
- package/src/__tests__/child-components-in-map.test.ts +1 -1
- package/src/__tests__/client-js-generation.test.ts +3 -3
- package/src/__tests__/computed-const.test.ts +103 -0
- package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
- package/src/__tests__/destructured-props-live.test.ts +1 -1
- package/src/__tests__/emit-to-string-call.test.ts +2 -1
- package/src/__tests__/hydration-payload-analysis.test.ts +166 -0
- package/src/__tests__/issue-2724-prop-alias-loop-not-static.test.ts +7 -7
- package/src/__tests__/issue-2754-rest-spread-needs-slot.test.ts +5 -2
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +1 -1
- package/src/__tests__/issue-2835-props-type-member-name-collision.test.ts +4 -4
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +1 -1
- package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +2 -1
- package/src/__tests__/issue-3713-props-spread-loop-row.test.ts +65 -0
- package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
- package/src/__tests__/lookup-literal-const.test.ts +9 -3
- package/src/__tests__/loop-index-reactivity.test.ts +2 -2
- package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +1 -1
- package/src/__tests__/loop-plan.test.ts +1 -1
- package/src/__tests__/loop-row-const-initializer-shadow.test.ts +146 -0
- package/src/__tests__/loop-row-type.test.ts +64 -0
- package/src/__tests__/lowering-value-position.test.ts +4 -0
- package/src/__tests__/memo-body-expr.test.ts +2 -2
- package/src/__tests__/module-const-destructure-default.test.ts +156 -0
- package/src/__tests__/nested-loop-index-param.test.ts +1 -1
- package/src/__tests__/nested-loop-reactive-attrs.test.ts +2 -2
- package/src/__tests__/nested-row-shadowing.test.ts +2 -2
- package/src/__tests__/nil-reading.test.ts +78 -0
- package/src/__tests__/nullable-signal-attr.test.ts +109 -48
- package/src/__tests__/primitive-plan.test.ts +494 -0
- package/src/__tests__/profile-loop-binding-ids.test.ts +2 -2
- package/src/__tests__/profile-nested-binding-ids.test.ts +2 -2
- package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
- package/src/__tests__/prop-references.test.ts +2 -2
- package/src/__tests__/props-destructuring.test.ts +17 -0
- package/src/__tests__/props-object-whole-read.test.ts +40 -0
- package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
- package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
- package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
- package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
- package/src/__tests__/rest-binding-gaps.test.ts +192 -0
- package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
- package/src/__tests__/root-prop-alias.test.ts +53 -8
- package/src/__tests__/ssr-defaults.test.ts +113 -25
- package/src/__tests__/static-loop-csr-materialize.test.ts +2 -2
- package/src/__tests__/static-record-literal-array.test.ts +171 -0
- package/src/__tests__/string-concat-identifier.test.ts +40 -1
- package/src/__tests__/written-binding-substitution.test.ts +8 -8
- package/src/adapters/boolean-result.ts +72 -66
- package/src/adapters/brace-delimiter-text.ts +25 -0
- package/src/adapters/callback-method.ts +159 -27
- package/src/adapters/component-props.ts +3 -4
- package/src/adapters/computed-const.ts +238 -4
- package/src/adapters/dsl-template-adapter.ts +62 -26
- package/src/adapters/loop-bound-names.ts +9 -1
- package/src/adapters/loop-plan.ts +1 -1
- package/src/adapters/loop-row-type.ts +149 -0
- package/src/adapters/nil-reading.ts +295 -0
- package/src/adapters/non-primitive-equality.ts +92 -0
- package/src/adapters/number-value.ts +17 -4
- package/src/adapters/operand-typing.ts +522 -0
- package/src/adapters/parsed-expr-emitter.ts +183 -19
- package/src/adapters/primitive-plan.ts +765 -0
- package/src/adapters/prop-classes.ts +16 -3
- package/src/analyzer-context.ts +6 -0
- package/src/analyzer.ts +532 -26
- package/src/augment-inherited-props.ts +108 -10
- package/src/compiler.ts +17 -0
- package/src/event-handler-name.ts +15 -0
- package/src/expression-parser.ts +70 -1
- package/src/index.ts +35 -16
- package/src/ir-to-client-js/build-references.ts +69 -0
- package/src/ir-to-client-js/child-props-object.ts +240 -0
- package/src/ir-to-client-js/collect-elements.ts +31 -63
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +8 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +31 -28
- package/src/ir-to-client-js/control-flow/shared.ts +20 -22
- package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +5 -3
- package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +1 -1
- package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +1 -1
- package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +3 -3
- package/src/ir-to-client-js/html-template.ts +43 -17
- package/src/ir-to-client-js/imports.ts +2 -2
- package/src/ir-to-client-js/index.ts +53 -11
- package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
- package/src/ir-to-client-js/plan/build-static-array-child-init.ts +31 -14
- package/src/ir-to-client-js/plan/static-array-child-init.ts +27 -18
- package/src/ir-to-client-js/prop-handling.ts +22 -3
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
- package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +26 -10
- package/src/jsx-to-ir.ts +459 -37
- package/src/nullable-signal-attr.ts +200 -110
- package/src/prop-rewrite.ts +30 -6
- package/src/props-binding.ts +84 -19
- package/src/props-object-whole-read.ts +87 -0
- package/src/rich-type-refusal.ts +2 -1
- package/src/scope/binding-scope.ts +182 -18
- package/src/scope/lexical-scope-walk.ts +4 -3
- package/src/scope/root-prop-alias.ts +15 -8
- package/src/ssr-defaults.ts +100 -11
- package/src/strip-types.ts +31 -3
- package/src/template-position-walk.ts +57 -28
- package/src/types.ts +87 -0
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -41
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
- package/src/adapters/ambiguous-nil-arithmetic.ts +0 -94
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
import type { ParsedExpr, FlatDepth, TemplatePart, ObjectLiteralProperty } from '../expression-parser.ts'
|
|
37
37
|
import { asCallbackMethodCall } from '../expression-parser.ts'
|
|
38
38
|
import type { LoweringMatcher, LoweringNode } from '../lowering-registry.ts'
|
|
39
|
+
import { booleanValueSites, foldNegatedNumberLiteral, nilTestOperand, planPrimitive, planToString, refuseUnspelledNilTest, type NilTestHelper, type PrimitiveInputs, type PrimitivePlan } from './primitive-plan.ts'
|
|
40
|
+
import { rewriteNilReadings, rewriteNilReadingsDeep } from './nil-reading.ts'
|
|
39
41
|
|
|
40
42
|
export type HigherOrderMethod = 'filter' | 'every' | 'some' | 'find' | 'findIndex' | 'findLast' | 'findLastIndex'
|
|
41
43
|
|
|
@@ -121,10 +123,26 @@ export interface LoweringEmitter {
|
|
|
121
123
|
* the emitter can inspect their kinds before deciding how to lower
|
|
122
124
|
* them, plus an `emit` callback to recurse on any child it wants the
|
|
123
125
|
* default rendering for.
|
|
126
|
+
*
|
|
127
|
+
* The primitive operations (`binary`, `unary`, `logical`, a `conditional`'s
|
|
128
|
+
* test, `indexAccess`, a computed `member`, a number `literal`) also receive
|
|
129
|
+
* their {@link PrimitivePlan} as the last parameter (#3824,
|
|
130
|
+
* `spec/js-primitive-semantics.md` "How it reaches emitters"): native or
|
|
131
|
+
* helper, decided once by `planPrimitive` from the emitter's
|
|
132
|
+
* {@link ParsedExprEmitter.primitives}. `null` for a node that is not a
|
|
133
|
+
* primitive operation (a non-number literal, a non-computed member, loose
|
|
134
|
+
* `==`, …). Step 0: every emitter accepts the plan and keeps its own
|
|
135
|
+
* spelling; the rollout makes each one spell the plan.
|
|
124
136
|
*/
|
|
125
137
|
export interface ParsedExprEmitter {
|
|
138
|
+
/**
|
|
139
|
+
* The inputs `planPrimitive` reads for this emitter: the operand typing at
|
|
140
|
+
* the emission site (the component's `collectOperandTyping` through the
|
|
141
|
+
* current `BindingScope`) and the target's `NativeSafeTable`.
|
|
142
|
+
*/
|
|
143
|
+
readonly primitives: PrimitiveInputs
|
|
126
144
|
identifier(name: string): string
|
|
127
|
-
literal(value: string | number | boolean | null, literalType: LiteralType): string
|
|
145
|
+
literal(value: string | number | boolean | null, literalType: LiteralType, plan: PrimitivePlan | null): string
|
|
128
146
|
call(callee: ParsedExpr, args: ParsedExpr[], emit: (e: ParsedExpr) => string): string
|
|
129
147
|
// Optional (#2843): when present, `emitParsedExpr`'s `call` case tries
|
|
130
148
|
// every matcher FIRST — before `call()` itself, and before the
|
|
@@ -137,6 +155,13 @@ export interface ParsedExprEmitter {
|
|
|
137
155
|
// registry inline in its own `call()` per #2842) — behaviour is then
|
|
138
156
|
// byte-identical to before this field existed.
|
|
139
157
|
lowering?: LoweringEmitter
|
|
158
|
+
/**
|
|
159
|
+
* Spell a boolean-value plan (#3824 step 5): materialize `rendered`, a
|
|
160
|
+
* boolean whose value leaves the expression, as the host's boolean.
|
|
161
|
+
* {@link emitParsedValue} calls it only for a `helper` plan, so a target
|
|
162
|
+
* whose `NativeSafeTable` claims `boolean-value` never needs it.
|
|
163
|
+
*/
|
|
164
|
+
booleanValue?(rendered: string, plan: PrimitivePlan): string
|
|
140
165
|
// `optional` is true for a `?.`-written access (`user?.name`); see the
|
|
141
166
|
// `ParsedExpr` `member` variant's docstring in `expression-parser.ts`
|
|
142
167
|
// for the single-hop caveat. Every adapter's `member()` implementation
|
|
@@ -148,6 +173,7 @@ export interface ParsedExprEmitter {
|
|
|
148
173
|
computed: boolean,
|
|
149
174
|
optional: boolean,
|
|
150
175
|
emit: (e: ParsedExpr) => string,
|
|
176
|
+
plan: PrimitivePlan | null,
|
|
151
177
|
): string
|
|
152
178
|
// Element access with a non-literal index (`arr[index]`). The index
|
|
153
179
|
// is a full `ParsedExpr` (loop variable, arithmetic, etc.); the
|
|
@@ -156,22 +182,40 @@ export interface ParsedExprEmitter {
|
|
|
156
182
|
object: ParsedExpr,
|
|
157
183
|
index: ParsedExpr,
|
|
158
184
|
emit: (e: ParsedExpr) => string,
|
|
185
|
+
plan: PrimitivePlan | null,
|
|
159
186
|
): string
|
|
160
|
-
binary(op: string, left: ParsedExpr, right: ParsedExpr, emit: (e: ParsedExpr) => string): string
|
|
161
|
-
|
|
187
|
+
binary(op: string, left: ParsedExpr, right: ParsedExpr, emit: (e: ParsedExpr) => string, plan: PrimitivePlan | null): string
|
|
188
|
+
/**
|
|
189
|
+
* A nil-test plan (`spec/js-undefined-value.md`, "Decisions" (3) and (7)):
|
|
190
|
+
* on a target that carries `undefined`, `x === null`, `x === undefined`
|
|
191
|
+
* and the loose `x == null` plan as the runtime's `is_null`,
|
|
192
|
+
* `is_undefined` and `is_nullish` over `operand` (the side that is not the
|
|
193
|
+
* nil literal, {@link nilTestOperand}), `negated` for `!==` / `!=`. An
|
|
194
|
+
* emitter without it refuses the plan ({@link refuseUnspelledNilTest});
|
|
195
|
+
* only the emitter of a target that carries `undefined` receives one.
|
|
196
|
+
*/
|
|
197
|
+
nilTest?(helper: NilTestHelper, negated: boolean, operand: ParsedExpr, emit: (e: ParsedExpr) => string): string
|
|
198
|
+
unary(op: string, argument: ParsedExpr, emit: (e: ParsedExpr) => string, plan: PrimitivePlan | null): string
|
|
162
199
|
logical(
|
|
163
200
|
op: '&&' | '||' | '??',
|
|
164
201
|
left: ParsedExpr,
|
|
165
202
|
right: ParsedExpr,
|
|
166
203
|
emit: (e: ParsedExpr) => string,
|
|
204
|
+
plan: PrimitivePlan | null,
|
|
167
205
|
): string
|
|
168
206
|
conditional(
|
|
169
207
|
test: ParsedExpr,
|
|
170
208
|
consequent: ParsedExpr,
|
|
171
209
|
alternate: ParsedExpr,
|
|
172
210
|
emit: (e: ParsedExpr) => string,
|
|
211
|
+
plan: PrimitivePlan | null,
|
|
173
212
|
): string
|
|
174
|
-
|
|
213
|
+
/**
|
|
214
|
+
* `plans[i]` is the ToString plan of `parts[i]` (`planToString`, #3824
|
|
215
|
+
* step 4) for an expression part, null for a string part: the part as it
|
|
216
|
+
* is when native, through the runtime's `to_string` otherwise.
|
|
217
|
+
*/
|
|
218
|
+
templateLiteral(parts: TemplatePart[], emit: (e: ParsedExpr) => string, plans: readonly (PrimitivePlan | null)[]): string
|
|
175
219
|
// A higher-order callback method call (`<object>.<method>(<arrow>, …rest)`,
|
|
176
220
|
// method ∈ `CALLBACK_METHODS`): `.filter`/`.find`/`.every`/`.some`/`.sort`/
|
|
177
221
|
// `.reduce`/`.flatMap`/… (#2018 P5). The adapter serializes the `arrow` body
|
|
@@ -232,6 +276,24 @@ export interface ParsedExprEmitter {
|
|
|
232
276
|
unsupported(raw: string, reason: string): string
|
|
233
277
|
}
|
|
234
278
|
|
|
279
|
+
/**
|
|
280
|
+
* The adapter's string typing of a name at the emission site (its
|
|
281
|
+
* `BindingScope`): `componentProperty` when the read is `props.<name>`,
|
|
282
|
+
* `path` when it is the member chain `name.<path…>` (`row.id`).
|
|
283
|
+
*/
|
|
284
|
+
export type StringNameTest = (name: string, componentProperty?: boolean, path?: readonly string[]) => boolean
|
|
285
|
+
|
|
286
|
+
/** `row.id.label` as its root name and field path; null for any other shape. */
|
|
287
|
+
function memberChain(expr: Extract<ParsedExpr, { kind: 'member' }>): { root: string; path: string[] } | null {
|
|
288
|
+
const path: string[] = []
|
|
289
|
+
let current: ParsedExpr = expr
|
|
290
|
+
while (current.kind === 'member' && !current.computed) {
|
|
291
|
+
path.unshift(current.property)
|
|
292
|
+
current = current.object
|
|
293
|
+
}
|
|
294
|
+
return current.kind === 'identifier' ? { root: current.name, path } : null
|
|
295
|
+
}
|
|
296
|
+
|
|
235
297
|
/**
|
|
236
298
|
* Whether an operand is string-typed, as far as the ParsedExpr tree can
|
|
237
299
|
* tell: a string literal, a template literal, a zero-arg getter call /
|
|
@@ -244,7 +306,7 @@ export interface ParsedExprEmitter {
|
|
|
244
306
|
* Consumed by `===`/`!==` lowering on backends whose `==` is numeric
|
|
245
307
|
* (Perl `eq`/`ne`) and by `isStringConcatBinary` below.
|
|
246
308
|
*/
|
|
247
|
-
export function isStringTypedOperand(expr: ParsedExpr, isStringName:
|
|
309
|
+
export function isStringTypedOperand(expr: ParsedExpr, isStringName: StringNameTest): boolean {
|
|
248
310
|
if (expr.kind === 'literal' && expr.literalType === 'string') return true
|
|
249
311
|
if (expr.kind === 'template-literal') return true
|
|
250
312
|
if (expr.kind === 'call' && expr.callee.kind === 'identifier' && expr.args.length === 0) {
|
|
@@ -253,6 +315,14 @@ export function isStringTypedOperand(expr: ParsedExpr, isStringName: (n: string,
|
|
|
253
315
|
if (expr.kind === 'member' && expr.object.kind === 'identifier' && expr.object.name === 'props') {
|
|
254
316
|
return isStringName(expr.property, true)
|
|
255
317
|
}
|
|
318
|
+
// A field read (`row.id`, `row.meta.label`): string-typed when the
|
|
319
|
+
// binding's declared type says the field is (#3762). A member of a
|
|
320
|
+
// string-typed name is never itself a string (`label.length`), which also
|
|
321
|
+
// keeps a test that types the name alone from typing its members.
|
|
322
|
+
if (expr.kind === 'member') {
|
|
323
|
+
const chain = memberChain(expr)
|
|
324
|
+
return chain !== null && !isStringName(chain.root) && isStringName(chain.root, false, chain.path)
|
|
325
|
+
}
|
|
256
326
|
// A bare identifier (#2212): a destructured prop param or a same-file
|
|
257
327
|
// local const, string-typed per the caller's `isStringName` set — each
|
|
258
328
|
// adapter's `collectStringValueNames` already tracks `propsParams`, so a
|
|
@@ -282,7 +352,7 @@ export function isStringConcatBinary(
|
|
|
282
352
|
op: string,
|
|
283
353
|
left: ParsedExpr,
|
|
284
354
|
right: ParsedExpr,
|
|
285
|
-
isStringName:
|
|
355
|
+
isStringName: StringNameTest,
|
|
286
356
|
): boolean {
|
|
287
357
|
return op === '+' && (isStringTypedOperand(left, isStringName) || isStringTypedOperand(right, isStringName))
|
|
288
358
|
}
|
|
@@ -296,7 +366,7 @@ export function isStringConcatBinary(
|
|
|
296
366
|
*/
|
|
297
367
|
export function isNumericArithmeticResult(
|
|
298
368
|
expr: ParsedExpr | null | undefined,
|
|
299
|
-
isStringName:
|
|
369
|
+
isStringName: StringNameTest,
|
|
300
370
|
): boolean {
|
|
301
371
|
if (!expr) return false
|
|
302
372
|
if (expr.kind === 'unary') return expr.op === '-'
|
|
@@ -428,6 +498,17 @@ export function asToStringCall(expr: ParsedExpr): ParsedExpr | null {
|
|
|
428
498
|
return callee.object
|
|
429
499
|
}
|
|
430
500
|
|
|
501
|
+
/**
|
|
502
|
+
* The plan `emitParsedExpr` hands an emitter method for `expr`: decided by
|
|
503
|
+
* `planPrimitive` from the emitter's own typing and native-safe table.
|
|
504
|
+
*/
|
|
505
|
+
export function primitivePlanFor(expr: ParsedExpr, emitter: Pick<ParsedExprEmitter, 'primitives'>): PrimitivePlan | null {
|
|
506
|
+
// The two kinds that are mostly not primitive operations skip the typing.
|
|
507
|
+
if (expr.kind === 'literal' && expr.literalType !== 'number') return null
|
|
508
|
+
if (expr.kind === 'member' && !expr.computed) return null
|
|
509
|
+
return planPrimitive(expr, emitter.primitives.typing(), emitter.primitives.nativeSafe)
|
|
510
|
+
}
|
|
511
|
+
|
|
431
512
|
/**
|
|
432
513
|
* Single point of dispatch from `ParsedExpr.kind` to the adapter's
|
|
433
514
|
* method. Adapters call this once at their entry point; the recursion
|
|
@@ -437,13 +518,91 @@ export function asToStringCall(expr: ParsedExpr): ParsedExpr | null {
|
|
|
437
518
|
* a TS compile error here — and, transitively, in every adapter that
|
|
438
519
|
* hasn't extended its `ParsedExprEmitter` implementation.
|
|
439
520
|
*/
|
|
440
|
-
export function emitParsedExpr(
|
|
441
|
-
|
|
521
|
+
export function emitParsedExpr(
|
|
522
|
+
expr: ParsedExpr,
|
|
523
|
+
emitter: ParsedExprEmitter,
|
|
524
|
+
sites?: ReadonlyMap<ParsedExpr, PrimitivePlan>,
|
|
525
|
+
): string {
|
|
526
|
+
const rendered = dispatchParsedExpr(expr, emitter, sites)
|
|
527
|
+
const plan = sites?.get(expr)
|
|
528
|
+
return plan?.mode === 'helper' && emitter.booleanValue ? emitter.booleanValue(rendered, plan) : rendered
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* {@link emitParsedExpr} for `expr` read as a value that leaves the
|
|
533
|
+
* expression (a child prop, a stored seed, a `JSON.stringify` argument, a
|
|
534
|
+
* displayed text child): every boolean its value can be is spelled through
|
|
535
|
+
* the boolean-value plan `booleanValueSites` decides (#3824 step 5).
|
|
536
|
+
*/
|
|
537
|
+
export function emitParsedValue(expr: ParsedExpr, emitter: ParsedExprEmitter): string {
|
|
538
|
+
return emitParsedExpr(expr, emitter, booleanValueSites(expr, emitter.primitives.nativeSafe))
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* The ToString plans of a template literal's parts, for
|
|
543
|
+
* {@link ParsedExprEmitter.templateLiteral}: null for a string part.
|
|
544
|
+
*/
|
|
545
|
+
export function templatePartPlans(parts: readonly TemplatePart[], emitter: Pick<ParsedExprEmitter, 'primitives'>): (PrimitivePlan | null)[] {
|
|
546
|
+
const typing = emitter.primitives.typing()
|
|
547
|
+
return parts.map(p => (p.type === 'expression' ? planToString(p.expr, typing, emitter.primitives.nativeSafe) : null))
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* `expr` with the nil-reading rewrite applied to its own operands
|
|
552
|
+
* (`rewriteNilReadings`, #3824 step 4), in the emitter's scope. Only the
|
|
553
|
+
* kinds whose coercion the rewrite reads take the typing.
|
|
554
|
+
*/
|
|
555
|
+
export function withNilReadings(expr: ParsedExpr, emitter: Pick<ParsedExprEmitter, 'primitives'>): ParsedExpr {
|
|
556
|
+
if (expr.kind !== 'binary' && expr.kind !== 'unary' && expr.kind !== 'template-literal') return expr
|
|
557
|
+
return rewriteNilReadings(expr, emitter.primitives.typing())
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* A `binary` node. A nil test (a target that carries `undefined`) goes to
|
|
562
|
+
* the emitter's `nilTest`; an emitter without one refuses it here, so no
|
|
563
|
+
* emitter's own `==` lowering sees it.
|
|
564
|
+
*/
|
|
565
|
+
function dispatchBinary(
|
|
566
|
+
expr: Extract<ParsedExpr, { kind: 'binary' }>,
|
|
567
|
+
emitter: ParsedExprEmitter,
|
|
568
|
+
emit: (e: ParsedExpr) => string,
|
|
569
|
+
): string {
|
|
570
|
+
const plan = primitivePlanFor(expr, emitter)
|
|
571
|
+
if (plan?.op === 'nil-test' && plan.mode === 'helper' && emitter.nilTest) {
|
|
572
|
+
const operand = nilTestOperand(expr.left, expr.right, emitter.primitives.typing())
|
|
573
|
+
return emitter.nilTest(plan.helper as NilTestHelper, expr.op === '!==' || expr.op === '!=', operand, emit)
|
|
574
|
+
}
|
|
575
|
+
refuseUnspelledNilTest(plan)
|
|
576
|
+
return emitter.binary(expr.op, expr.left, expr.right, emit, plan)
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* A callback's arrow with the nil-reading rewrite run over its whole body:
|
|
581
|
+
* the body reaches the runtime evaluator (or the adapter's own predicate
|
|
582
|
+
* form) without passing through {@link emitParsedExpr} node by node.
|
|
583
|
+
*/
|
|
584
|
+
function withNilReadingBody(
|
|
585
|
+
arrow: Extract<ParsedExpr, { kind: 'arrow' }>,
|
|
586
|
+
emitter: Pick<ParsedExprEmitter, 'primitives'>,
|
|
587
|
+
): Extract<ParsedExpr, { kind: 'arrow' }> {
|
|
588
|
+
const body = rewriteNilReadingsDeep(arrow.body, emitter.primitives.typing().enterCallback(arrow.params))
|
|
589
|
+
return body === arrow.body ? arrow : { ...arrow, body }
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function dispatchParsedExpr(
|
|
593
|
+
original: ParsedExpr,
|
|
594
|
+
emitter: ParsedExprEmitter,
|
|
595
|
+
sites: ReadonlyMap<ParsedExpr, PrimitivePlan> | undefined,
|
|
596
|
+
): string {
|
|
597
|
+
const emit = (child: ParsedExpr): string => emitParsedExpr(child, emitter, sites)
|
|
598
|
+
// The nil-reading rewrite runs wherever the plan runs: each operand whose
|
|
599
|
+
// nil Phase 1 can read is made non-nil before the node is planned.
|
|
600
|
+
const expr = withNilReadings(original, emitter)
|
|
442
601
|
switch (expr.kind) {
|
|
443
602
|
case 'identifier':
|
|
444
603
|
return emitter.identifier(expr.name)
|
|
445
604
|
case 'literal':
|
|
446
|
-
return emitter.literal(expr.value, expr.literalType)
|
|
605
|
+
return emitter.literal(expr.value, expr.literalType, primitivePlanFor(expr, emitter))
|
|
447
606
|
case 'call': {
|
|
448
607
|
// #2843: a registered lowering plugin's call wins in EVERY value
|
|
449
608
|
// position this dispatcher reaches, not only an adapter's own
|
|
@@ -471,23 +630,28 @@ export function emitParsedExpr(expr: ParsedExpr, emitter: ParsedExprEmitter): st
|
|
|
471
630
|
// A higher-order callback call (`arr.filter(p)` / `arr.sort(cmp)` / …)
|
|
472
631
|
// routes to the dedicated `callbackMethod` arm; any other call is generic.
|
|
473
632
|
const cb = asCallbackMethodCall(expr)
|
|
474
|
-
if (cb) return emitter.callbackMethod(cb.method, cb.object, cb.arrow, cb.args, emit)
|
|
633
|
+
if (cb) return emitter.callbackMethod(cb.method, cb.object, withNilReadingBody(cb.arrow, emitter), cb.args, emit)
|
|
475
634
|
return emitter.call(expr.callee, expr.args, emit)
|
|
476
635
|
}
|
|
477
636
|
case 'member':
|
|
478
|
-
return emitter.member(expr.object, expr.property, expr.computed, expr.optional, emit)
|
|
637
|
+
return emitter.member(expr.object, expr.property, expr.computed, expr.optional, emit, primitivePlanFor(expr, emitter))
|
|
479
638
|
case 'index-access':
|
|
480
|
-
return emitter.indexAccess(expr.object, expr.index, emit)
|
|
639
|
+
return emitter.indexAccess(expr.object, expr.index, emit, primitivePlanFor(expr, emitter))
|
|
481
640
|
case 'binary':
|
|
482
|
-
return
|
|
483
|
-
case 'unary':
|
|
484
|
-
|
|
641
|
+
return dispatchBinary(expr, emitter, emit)
|
|
642
|
+
case 'unary': {
|
|
643
|
+
// `-1.5` is the literal `-1.5` (#3824 step 6): a unary minus over a
|
|
644
|
+
// non-zero number literal is spelled as the literal it folds into.
|
|
645
|
+
const folded = foldNegatedNumberLiteral(expr)
|
|
646
|
+
if (folded) return emitter.literal(folded.value, 'number', primitivePlanFor(folded, emitter))
|
|
647
|
+
return emitter.unary(expr.op, expr.argument, emit, primitivePlanFor(expr, emitter))
|
|
648
|
+
}
|
|
485
649
|
case 'logical':
|
|
486
|
-
return emitter.logical(expr.op, expr.left, expr.right, emit)
|
|
650
|
+
return emitter.logical(expr.op, expr.left, expr.right, emit, primitivePlanFor(expr, emitter))
|
|
487
651
|
case 'conditional':
|
|
488
|
-
return emitter.conditional(expr.test, expr.consequent, expr.alternate, emit)
|
|
652
|
+
return emitter.conditional(expr.test, expr.consequent, expr.alternate, emit, primitivePlanFor(expr, emitter))
|
|
489
653
|
case 'template-literal':
|
|
490
|
-
return emitter.templateLiteral(expr.parts, emit)
|
|
654
|
+
return emitter.templateLiteral(expr.parts, emit, templatePartPlans(expr.parts, emitter))
|
|
491
655
|
case 'arrow':
|
|
492
656
|
return emitter.arrow(expr.params, expr.body, emit)
|
|
493
657
|
case 'regex':
|