@barefootjs/jsx 0.31.10 → 0.33.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/dangerous-inner-html.d.ts.map +1 -1
- package/dist/adapters/parsed-expr-emitter.d.ts +22 -0
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +29 -6
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +129 -108
- package/dist/query-href-lowering.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/static-literal.d.ts.map +1 -1
- package/dist/to-locale-date-lowering.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/expression-parser.test.ts +43 -6
- package/src/__tests__/serialize-parsed-expr.test.ts +17 -3
- package/src/__tests__/ssr-defaults.test.ts +41 -0
- package/src/__tests__/ssr-seed-plan.test.ts +12 -2
- package/src/adapters/dangerous-inner-html.ts +1 -0
- package/src/adapters/parsed-expr-emitter.ts +49 -3
- package/src/expression-parser.ts +200 -89
- package/src/index.ts +2 -3
- package/src/jsx-to-ir.ts +4 -1
- package/src/query-href-lowering.ts +4 -0
- package/src/rich-type-refusal.ts +1 -1
- package/src/ssr-defaults.ts +51 -2
- package/src/ssr-seed-plan.ts +20 -3
- package/src/static-literal.ts +15 -1
- package/src/to-locale-date-lowering.ts +4 -0
- package/dist/signal-init-eval.d.ts +0 -82
- package/dist/signal-init-eval.d.ts.map +0 -1
- package/src/__tests__/signal-init-eval.test.ts +0 -138
- package/src/signal-init-eval.ts +0 -165
|
@@ -458,6 +458,47 @@ describe('extractSsrDefaults', () => {
|
|
|
458
458
|
// space mirrors Hono's empty-className interpolation).
|
|
459
459
|
expect(defaults?.classes).toEqual({ value: 'a b c d tail' })
|
|
460
460
|
})
|
|
461
|
+
|
|
462
|
+
// #2698 review: a property access on a non-plain-object base (an array
|
|
463
|
+
// element bound by `.map()`) must refuse (UNRESOLVED), not silently read
|
|
464
|
+
// `undefined` via `hasOwnProperty` — an array exposes prototype members
|
|
465
|
+
// (`.map`, `.filter`, …) that aren't own properties, so the old guard
|
|
466
|
+
// (`typeof !== 'object'`) let arrays through and misreported them as a
|
|
467
|
+
// real `undefined` value instead of an unrepresentable read.
|
|
468
|
+
test('.map() body property-access on an ARRAY element is UNRESOLVED, not undefined', () => {
|
|
469
|
+
const metadata = metadataFor(`
|
|
470
|
+
'use client'
|
|
471
|
+
import { createSignal } from '@barefootjs/client'
|
|
472
|
+
function C() {
|
|
473
|
+
const [x] = createSignal([[1, 2], [3, 4]].map(t => t.foo))
|
|
474
|
+
return <p>{x()}</p>
|
|
475
|
+
}
|
|
476
|
+
`)
|
|
477
|
+
|
|
478
|
+
const defaults = extractSsrDefaults(metadata)
|
|
479
|
+
// UNRESOLVED aborts the whole `.map()` (not a per-element `null`) —
|
|
480
|
+
// resultToJsonable renders the abort as the same `null` a genuinely
|
|
481
|
+
// undefined value would, but the two paths reach it differently: this
|
|
482
|
+
// pin exists to keep the array case going through the abort path.
|
|
483
|
+
expect(defaults?.x).toEqual({ value: null })
|
|
484
|
+
})
|
|
485
|
+
|
|
486
|
+
test('.map() body property-access on a PLAIN-OBJECT element still resolves a missing key to undefined', () => {
|
|
487
|
+
const metadata = metadataFor(`
|
|
488
|
+
'use client'
|
|
489
|
+
import { createSignal } from '@barefootjs/client'
|
|
490
|
+
function C() {
|
|
491
|
+
const [x] = createSignal([{ a: 1 }, {}].map(t => t.a))
|
|
492
|
+
return <p>{x()}</p>
|
|
493
|
+
}
|
|
494
|
+
`)
|
|
495
|
+
|
|
496
|
+
const defaults = extractSsrDefaults(metadata)
|
|
497
|
+
// Unlike the array case, a missing key on a plain object resolves that
|
|
498
|
+
// ONE element to `undefined` (→ `null`) and the `.map()` keeps going —
|
|
499
|
+
// it does not abort the whole computation.
|
|
500
|
+
expect(defaults?.x).toEqual({ value: [1, null] })
|
|
501
|
+
})
|
|
461
502
|
})
|
|
462
503
|
|
|
463
504
|
// TS twin of the Ruby/Python/PHP/Perl/Rust `derive*FromDefaults` runtime
|
|
@@ -158,7 +158,12 @@ describe('computeSsrSeedPlan', () => {
|
|
|
158
158
|
if (label.kind === 'opaque') expect(label.origin).toBe('memo')
|
|
159
159
|
})
|
|
160
160
|
|
|
161
|
-
test('
|
|
161
|
+
test('object-literal body → derived (#2696: value-position object literal, isSupportedValue)', () => {
|
|
162
|
+
// Was `opaque` before `checkSupport` gained its `pos` parameter — a
|
|
163
|
+
// memo's WHOLE body is a value position (an assignment, never a
|
|
164
|
+
// render), so an object literal there is exactly the shape
|
|
165
|
+
// `isSupportedValue` now admits (every property value — here `n()` —
|
|
166
|
+
// is itself supported).
|
|
162
167
|
const plan = planFor(`
|
|
163
168
|
'use client'
|
|
164
169
|
import { createMemo, createSignal } from '@barefootjs/client'
|
|
@@ -169,7 +174,12 @@ describe('computeSsrSeedPlan', () => {
|
|
|
169
174
|
}
|
|
170
175
|
`)
|
|
171
176
|
|
|
172
|
-
|
|
177
|
+
const obj = step(plan, 'obj')
|
|
178
|
+
expect(obj.kind).toBe('derived')
|
|
179
|
+
if (obj.kind === 'derived') {
|
|
180
|
+
expect(obj.origin).toBe('memo')
|
|
181
|
+
expect(obj.frees).toEqual(['n'])
|
|
182
|
+
}
|
|
173
183
|
})
|
|
174
184
|
|
|
175
185
|
test('literal signal init → derived with empty frees (constant-skip is emit-side)', () => {
|
|
@@ -122,6 +122,7 @@ function htmlPropValue(parsed: ParsedExpr): ParsedExpr | null {
|
|
|
122
122
|
if (parsed.kind !== 'object-literal') return null
|
|
123
123
|
if (parsed.properties.length !== 1) return null
|
|
124
124
|
const [prop] = parsed.properties
|
|
125
|
+
if (prop.kind === 'spread') return null
|
|
125
126
|
if (prop.key !== '__html') return null
|
|
126
127
|
return prop.value
|
|
127
128
|
}
|
|
@@ -163,9 +163,11 @@ export interface ParsedExprEmitter {
|
|
|
163
163
|
arrow(params: string[], body: ParsedExpr, emit: (e: ParsedExpr) => string): string
|
|
164
164
|
regex(raw: string): string
|
|
165
165
|
arrayLiteral(elements: ParsedExpr[], emit: (e: ParsedExpr) => string): string
|
|
166
|
-
// Emit an object literal `{ a: 1, b: x }
|
|
167
|
-
//
|
|
168
|
-
//
|
|
166
|
+
// Emit an object literal `{ a: 1, b: x, ...rest }` (#2696 Step 2 adds
|
|
167
|
+
// spread entries — `properties` is ORDER-PRESERVING, so an adapter must
|
|
168
|
+
// merge left-to-right, later entries winning, to match JS). `raw` is the
|
|
169
|
+
// original expression string so an adapter that doesn't lower object
|
|
170
|
+
// values yet can delegate to `unsupported(raw, …)` and stay byte-identical.
|
|
169
171
|
objectLiteral(
|
|
170
172
|
properties: ObjectLiteralProperty[],
|
|
171
173
|
raw: string,
|
|
@@ -277,6 +279,50 @@ export function groupBinaryOperand(operand: ParsedExpr, emitted: string): string
|
|
|
277
279
|
: emitted
|
|
278
280
|
}
|
|
279
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Split an `object-literal`'s (order-preserving) `properties` into rendered
|
|
284
|
+
* SEGMENTS an adapter's `objectLiteral()` folds with its own merge idiom
|
|
285
|
+
* (#2696 Step 2): each maximal run of consecutive `prop` entries collapses
|
|
286
|
+
* into ONE literal (via `literalOf`), and each `spread` entry becomes its
|
|
287
|
+
* own segment (its emitted source expression) — so `{ a: 1, b: 2, ...t, c: 3
|
|
288
|
+
* }` yields `[literal({a,b}), emit(t), literal({c})]`, in source order.
|
|
289
|
+
*
|
|
290
|
+
* A caller with NO spread entries at all should keep its pre-#2696 single
|
|
291
|
+
* `literalOf(properties)` call instead of this (this always returns at
|
|
292
|
+
* least one segment, but a caller folding 1-segment output through a merge
|
|
293
|
+
* call — `array_merge(x)`, `{}.merge(x)` — would be needlessly indirect
|
|
294
|
+
* for the common spread-free case).
|
|
295
|
+
*
|
|
296
|
+
* Shared here (not duplicated per adapter) because the grouping itself is
|
|
297
|
+
* backend-neutral structure — only `literalOf` (the target language's
|
|
298
|
+
* literal syntax) and the fold (the target language's merge idiom) are
|
|
299
|
+
* adapter-specific.
|
|
300
|
+
*/
|
|
301
|
+
export function groupObjectLiteralSegments(
|
|
302
|
+
properties: readonly ObjectLiteralProperty[],
|
|
303
|
+
literalOf: (run: ReadonlyArray<Extract<ObjectLiteralProperty, { kind: 'prop' }>>) => string,
|
|
304
|
+
emit: (e: ParsedExpr) => string,
|
|
305
|
+
): string[] {
|
|
306
|
+
const segments: string[] = []
|
|
307
|
+
let run: Extract<ObjectLiteralProperty, { kind: 'prop' }>[] = []
|
|
308
|
+
const flushRun = () => {
|
|
309
|
+
if (run.length > 0) {
|
|
310
|
+
segments.push(literalOf(run))
|
|
311
|
+
run = []
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
for (const p of properties) {
|
|
315
|
+
if (p.kind === 'spread') {
|
|
316
|
+
flushRun()
|
|
317
|
+
segments.push(emit(p.expr))
|
|
318
|
+
} else {
|
|
319
|
+
run.push(p)
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
flushRun()
|
|
323
|
+
return segments
|
|
324
|
+
}
|
|
325
|
+
|
|
280
326
|
/**
|
|
281
327
|
* Single point of dispatch from `ParsedExpr.kind` to the adapter's
|
|
282
328
|
* method. Adapters call this once at their entry point; the recursion
|