@barefootjs/jsx 0.37.1 → 0.38.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/env-signal.d.ts +0 -8
- package/dist/adapters/env-signal.d.ts.map +1 -1
- package/dist/adapters/interface.d.ts +12 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- package/dist/analyzer.d.ts +31 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/builtin-lowering-plugins.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/component-root-scope-comment.d.ts +36 -0
- package/dist/component-root-scope-comment.d.ts.map +1 -0
- package/dist/errors.d.ts +3 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +13 -0
- package/dist/event-handler-name.d.ts.map +1 -0
- package/dist/expression-parser.d.ts +9 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/format-date-refusal.d.ts +37 -0
- package/dist/format-date-refusal.d.ts.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2421 -1787
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-branch-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-composite-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/plan/build-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/lazy-row-eligibility.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +57 -12
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts +44 -3
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +7 -5
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts +43 -2
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts +9 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/source-map.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +26 -0
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/opaque-local-accessor.d.ts +27 -0
- package/dist/opaque-local-accessor.d.ts.map +1 -0
- package/dist/to-locale-date-lowering.d.ts +7 -4
- package/dist/to-locale-date-lowering.d.ts.map +1 -1
- package/dist/types.d.ts +53 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +724 -4564
- package/src/__tests__/binding-scope-ratchet.test.ts +21 -10
- package/src/__tests__/branch-local-in-raw-capture.test.ts +1 -1
- package/src/__tests__/branch-local-same-name-collision.test.ts +9 -9
- package/src/__tests__/client-js-generation.test.ts +175 -0
- package/src/__tests__/component-root-scope-comment.test.ts +106 -0
- package/src/__tests__/doc-examples.test.ts +12 -22
- package/src/__tests__/event-handler-name.test.ts +74 -0
- package/src/__tests__/flatmap-segments.test.ts +11 -9
- package/src/__tests__/format-date-refusal.test.ts +134 -0
- package/src/__tests__/fragment-wrapped-conditional-return-branch.test.ts +132 -0
- package/src/__tests__/hydrate-template.test.ts +9 -1
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +2 -2
- package/src/__tests__/issue-3009-loop-branch-ref.test.ts +2 -2
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +213 -0
- package/src/__tests__/issue-3113-init-fn-name-collision.test.ts +133 -0
- package/src/__tests__/jsx-return-type-assertion.test.ts +2 -2
- package/src/__tests__/lazy-row-eligibility.test.ts +5 -4
- package/src/__tests__/loop-row-child-children-reactive-attrs.test.ts +108 -0
- package/src/__tests__/loop-row-child-text-children-markers.test.ts +158 -0
- package/src/__tests__/opaque-local-accessor.test.ts +90 -0
- package/src/__tests__/profiler-e2e.test.ts +13 -8
- package/src/__tests__/ref-attr-absent-at-ssr.test.ts +472 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +217 -0
- package/src/adapters/env-signal.ts +2 -21
- package/src/adapters/interface.ts +13 -0
- package/src/analyzer.ts +31 -27
- package/src/builtin-lowering-plugins.ts +0 -2
- package/src/compiler.ts +24 -0
- package/src/component-root-scope-comment.ts +59 -0
- package/src/errors.ts +44 -1
- package/src/event-handler-name.ts +14 -0
- package/src/expression-parser.ts +41 -17
- package/src/format-date-refusal.ts +266 -0
- package/src/index.ts +12 -2
- package/src/ir-to-client-js/child-components.ts +8 -3
- package/src/ir-to-client-js/collect-elements.ts +27 -13
- package/src/ir-to-client-js/control-flow/plan/build-branch-loop.ts +2 -4
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +67 -5
- package/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts +3 -6
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +2 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop.ts +23 -11
- package/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts +3 -3
- package/src/ir-to-client-js/control-flow/plan/loop.ts +51 -10
- package/src/ir-to-client-js/control-flow/shared.ts +78 -5
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +25 -12
- package/src/ir-to-client-js/emit-reactive.ts +140 -10
- package/src/ir-to-client-js/emit-registration.ts +2 -2
- package/src/ir-to-client-js/generate-init.ts +2 -2
- package/src/ir-to-client-js/html-template.ts +41 -19
- package/src/ir-to-client-js/index.ts +4 -3
- package/src/ir-to-client-js/reactivity.ts +20 -16
- package/src/ir-to-client-js/source-map.ts +2 -1
- package/src/ir-to-client-js/utils.ts +34 -0
- package/src/jsx-to-ir.ts +737 -49
- package/src/opaque-local-accessor.ts +44 -0
- package/src/rich-type-refusal.ts +1 -1
- package/src/to-locale-date-lowering.ts +7 -4
- package/src/types.ts +51 -15
- package/dist/format-date-lowering.d.ts +0 -30
- package/dist/format-date-lowering.d.ts.map +0 -1
- package/src/__tests__/create-selector.test.ts +0 -124
- package/src/__tests__/format-date-lowering.test.ts +0 -125
- package/src/format-date-lowering.ts +0 -55
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #3144: shared detection for "opaque local accessor invoked in a template
|
|
3
|
+
* position" — `const label = makeLabel(); {label()}`, where `makeLabel()`
|
|
4
|
+
* is a call the compiler cannot evaluate at compile time (a helper
|
|
5
|
+
* returning a function, or an accessor returned by a library, e.g.
|
|
6
|
+
* `const posts = createQuery(…); {posts()}`).
|
|
7
|
+
*
|
|
8
|
+
* Every non-JS-runtime adapter's `call()` fallback treats ANY zero-arg
|
|
9
|
+
* identifier call as a signal-getter reference (`count() → $count` /
|
|
10
|
+
* `.Count` / `{{ count }}` / …) unconditionally — correct for a real
|
|
11
|
+
* signal/memo getter, but silently wrong here: `label` is never a signal,
|
|
12
|
+
* never a prop, and never reaches the template as a bound variable at all,
|
|
13
|
+
* so the emitted bare-name reference resolves to nothing. The reference
|
|
14
|
+
* adapter (Hono, real JS) evaluates `label()` correctly and does NOT
|
|
15
|
+
* consult this — it has no such gap to guard against.
|
|
16
|
+
*
|
|
17
|
+
* This function answers ONLY the structural question "is `name` bound to a
|
|
18
|
+
* COMPONENT-BODY local whose own initializer is itself an unresolved call
|
|
19
|
+
* expression" — every DSL adapter's `call()` method calls it, with its own
|
|
20
|
+
* `localConstants`, before falling into the zero-arg-identifier branch, and
|
|
21
|
+
* refuses loudly (reusing each adapter's own BF101 recording, matching the
|
|
22
|
+
* #2994 / #3012 precedent for a bare-name call to a module-scope helper)
|
|
23
|
+
* instead of guessing.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { ConstantInfo } from './types.ts'
|
|
27
|
+
|
|
28
|
+
export function isOpaqueLocalAccessorName(
|
|
29
|
+
name: string,
|
|
30
|
+
localConstants: readonly ConstantInfo[] | undefined,
|
|
31
|
+
): boolean {
|
|
32
|
+
const constant = (localConstants ?? []).find((c) => c.name === name)
|
|
33
|
+
if (!constant) return false
|
|
34
|
+
// Module-scope bindings go through the #2994/#3012 module-helper-call
|
|
35
|
+
// refusal path already (a DIFFERENT shape: the bare name IS the helper,
|
|
36
|
+
// not a local re-binding of one) — out of scope here.
|
|
37
|
+
if (constant.isModule) return false
|
|
38
|
+
// `ConstantInfo.parsed` is the analyzer's best-effort structural parse of
|
|
39
|
+
// the initializer (`jsx-to-ir.ts`/analyzer). `kind === 'call'` means the
|
|
40
|
+
// local's value came from invoking something — exactly the opaque-
|
|
41
|
+
// accessor shape, regardless of whether that call itself would separately
|
|
42
|
+
// refuse if written bare in a template position.
|
|
43
|
+
return constant.parsed?.kind === 'call'
|
|
44
|
+
}
|
package/src/rich-type-refusal.ts
CHANGED
|
@@ -225,7 +225,7 @@ function buildSuggestion(
|
|
|
225
225
|
if (method === 'toLocaleDateString' && typeName === 'Date') {
|
|
226
226
|
return {
|
|
227
227
|
message:
|
|
228
|
-
"Pass a literal locale and an explicit literal timeZone — .toLocaleDateString('ja-JP', { timeZone: 'UTC' }), a fixed '±HH:MM' offset, or a canonical IANA zone ID like 'Asia/Tokyo' (exact case; #2344) — to compile it to the format_date helper; for a runtime locale,
|
|
228
|
+
"Pass a literal locale and an explicit literal timeZone — .toLocaleDateString('ja-JP', { timeZone: 'UTC' }), a fixed '±HH:MM' offset, or a canonical IANA zone ID like 'Asia/Tokyo' (exact case; #2344) — to compile it to the format_date helper; for a runtime locale, defer the whole read to the client with /* @client */, which can call any date-formatting API you like (Intl.DateTimeFormat, your i18n layer, ...) since it runs as real JS in the browser — formatDate itself is compiler ABI and cannot be called by name (BF056). " +
|
|
229
229
|
`Alternatively pre-compute server-side, or evaluate client-only by ${revivalExpr} — ${revivalReason}.`,
|
|
230
230
|
escape: [{ kind: 'rewrite' }, { kind: 'prop-precompute' }, { kind: 'client-directive' }],
|
|
231
231
|
}
|
|
@@ -31,9 +31,11 @@
|
|
|
31
31
|
* timezone, the implicit-environment hole #2273 closed;
|
|
32
32
|
* - an OPEN-typed runtime locale (`locale: string`) — build-time CLDR
|
|
33
33
|
* resolution is impossible; the app's i18n layer owns locale → pattern
|
|
34
|
-
* there,
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* there, deferring the whole read to the client with `/* @client *\/`
|
|
35
|
+
* (`formatDate` itself is compiler ABI and cannot be called by name —
|
|
36
|
+
* BF056, #3089). An OPTIONAL union prop also declines: `undefined` at
|
|
37
|
+
* runtime makes real `toLocaleDateString` read the host locale, which
|
|
38
|
+
* no frozen pattern table can reproduce;
|
|
37
39
|
* - an IANA `timeZone` literal the build machine cannot verify (#2344):
|
|
38
40
|
* a named zone IS admitted when the build's own `Intl` echoes it back
|
|
39
41
|
* verbatim from `resolvedOptions().timeZone` — the canonical primary
|
|
@@ -89,7 +91,8 @@ const tzProbeCache = new Map<string, boolean>()
|
|
|
89
91
|
* spellings are exactly where backend tzdata layers disagree (Go/Python/
|
|
90
92
|
* Ruby/Rust resolve the exact ID set; PHP folds case; link availability
|
|
91
93
|
* varies by tzdata vintage). Anything the probe can't verify declines
|
|
92
|
-
* (→ BF021) —
|
|
94
|
+
* (→ BF021) — `/* @client *\/` stays available for edge cases (`formatDate`
|
|
95
|
+
* itself is compiler ABI and cannot be called by name — BF056, #3089).
|
|
93
96
|
*/
|
|
94
97
|
export function isBuildResolvableTimeZone(value: string): boolean {
|
|
95
98
|
const cached = tzProbeCache.get(value)
|
package/src/types.ts
CHANGED
|
@@ -392,6 +392,15 @@ export interface IRElement {
|
|
|
392
392
|
* shared partial carries the same id across every page that composes it.
|
|
393
393
|
*/
|
|
394
394
|
regionId?: string
|
|
395
|
+
/**
|
|
396
|
+
* True when this element's `ref` callback is the recognized SSR-portal
|
|
397
|
+
* pattern (#3059): a local named callback whose body directly calls
|
|
398
|
+
* `createPortal(<this element>, document.body, { ownerScope })` — see
|
|
399
|
+
* `isSsrPortalRefCallback` in `jsx-to-ir.ts`. Every adapter's own SSR
|
|
400
|
+
* portal outlet (#3119) places the element's SSR markup there instead
|
|
401
|
+
* of inline, matching where hydration's `createPortal` moves it.
|
|
402
|
+
*/
|
|
403
|
+
ssrPortalOwnerScope?: boolean
|
|
395
404
|
loc: SourceLocation
|
|
396
405
|
}
|
|
397
406
|
|
|
@@ -1154,6 +1163,21 @@ export interface IRComponent {
|
|
|
1154
1163
|
* predicate every backend must consult instead of re-deriving this fact.
|
|
1155
1164
|
*/
|
|
1156
1165
|
loopItemRoot?: boolean
|
|
1166
|
+
/**
|
|
1167
|
+
* True when this component IS the entire render root of a client-
|
|
1168
|
+
* interactive component (`'use client'`, or otherwise needing client
|
|
1169
|
+
* init) — no wrapping element of its own. Such a root has no DOM node
|
|
1170
|
+
* to hang `bf-s`/`bf-p` on, so the adapter must wrap its rendered
|
|
1171
|
+
* output in a comment-based scope marker pair instead, mirroring
|
|
1172
|
+
* `IRFragment.needsScopeComment` (which handles the analogous
|
|
1173
|
+
* multi-element-fragment-root case). Computed once, in `compiler.ts`
|
|
1174
|
+
* (`decideComponentRootScopeComment`) right after `metadata.clientAnalysis`
|
|
1175
|
+
* becomes available — NOT in `jsx-to-ir.ts`'s per-node transform, since
|
|
1176
|
+
* "is this component client-interactive" isn't known until then. Every
|
|
1177
|
+
* adapter renders the pair from this ONE flag (#3141) instead of each
|
|
1178
|
+
* re-deriving the "root is a component" check locally.
|
|
1179
|
+
*/
|
|
1180
|
+
needsScopeComment?: boolean
|
|
1157
1181
|
loc: SourceLocation
|
|
1158
1182
|
}
|
|
1159
1183
|
|
|
@@ -2350,28 +2374,36 @@ export interface ErrorSuggestion {
|
|
|
2350
2374
|
* fixture (packages/adapter-tests) instead of lowering it — the adapter's
|
|
2351
2375
|
* machine-readable known-limitations declaration. Consumed by the adapter's
|
|
2352
2376
|
* own conformance test (as `expectedDiagnostics`) and by `bf compat`
|
|
2353
|
-
* (
|
|
2354
|
-
*
|
|
2377
|
+
* (limitation attribution). Every pin cites the registry entry that
|
|
2378
|
+
* defines the limitation it is an instance of:
|
|
2379
|
+
* `packages/adapter-tests/limitations/<id>.ts` (see that package's
|
|
2380
|
+
* `src/limitations.ts` for the entry format). The registry, not a label or
|
|
2381
|
+
* an issue tracker, is the source of truth for what is limited and why.
|
|
2355
2382
|
*/
|
|
2356
2383
|
export interface ConformancePin {
|
|
2357
2384
|
/** Diagnostic code, e.g. 'BF101'. */
|
|
2358
2385
|
code: string
|
|
2359
2386
|
severity: 'error' | 'warning'
|
|
2360
|
-
/**
|
|
2361
|
-
|
|
2387
|
+
/**
|
|
2388
|
+
* The registry id (`packages/adapter-tests/limitations/<id>.ts`) of the
|
|
2389
|
+
* limitation this refusal is an instance of. Required: a pin with no
|
|
2390
|
+
* definition behind it is a gap nobody can read about. The join test
|
|
2391
|
+
* (`packages/compat/src/__tests__/limitations-join.test.ts`) fails on an
|
|
2392
|
+
* id that has no entry, and on an entry whose `fixtures` do not list this
|
|
2393
|
+
* pin's fixture.
|
|
2394
|
+
*/
|
|
2395
|
+
limitation: string
|
|
2362
2396
|
/**
|
|
2363
2397
|
* Present when THIS adapter has no verified escape yet for this
|
|
2364
|
-
* refusal — the per-adapter half of
|
|
2365
|
-
* (`packages/compat/src/__tests__/escape-coverage.test.ts`).
|
|
2366
|
-
* the tracking pointer for closing the gap (fall back to
|
|
2367
|
-
* https://github.com/piconic-ai/barefootjs/issues/2613 itself when no
|
|
2368
|
-
* more specific issue exists yet).
|
|
2398
|
+
* refusal — the per-adapter half of the "loud-or-escapable" floor
|
|
2399
|
+
* (`packages/compat/src/__tests__/escape-coverage.test.ts`).
|
|
2369
2400
|
*
|
|
2370
2401
|
* Declared here, next to the refusal it qualifies, so an adapter's own
|
|
2371
2402
|
* package is the sole place that states what it knows about its own
|
|
2372
2403
|
* refusal — no central cross-adapter ledger to keep in sync (that was
|
|
2373
|
-
* the architectural defect increment
|
|
2374
|
-
* test hardcoding every adapter's id, which made
|
|
2404
|
+
* the architectural defect the floor's first increment shipped with: a
|
|
2405
|
+
* `packages/compat` test hardcoding every adapter's id, which made
|
|
2406
|
+
* adapters non-additive).
|
|
2375
2407
|
*
|
|
2376
2408
|
* Absent means the adapter believes an escape is owed here — either
|
|
2377
2409
|
* already satisfied (the refused fixture's `escapes` twin compiles
|
|
@@ -2381,8 +2413,10 @@ export interface ConformancePin {
|
|
|
2381
2413
|
* Shrink-only, same discipline `KNOWN_HOLES` established: once a
|
|
2382
2414
|
* working twin exists here, a lingering `unescapable` becomes a STALE
|
|
2383
2415
|
* declaration and the floor test fails loudly on it, naming this pin.
|
|
2416
|
+
* The set of pins still carrying it is the "escape twins still to
|
|
2417
|
+
* author" work list — derived, never tracked elsewhere.
|
|
2384
2418
|
*/
|
|
2385
|
-
unescapable?:
|
|
2419
|
+
unescapable?: true
|
|
2386
2420
|
}
|
|
2387
2421
|
/** Keyed by shared-fixture id (`JSXFixture.id`). */
|
|
2388
2422
|
export type ConformancePins = Record<string, ReadonlyArray<ConformancePin>>
|
|
@@ -2397,10 +2431,12 @@ export type ConformancePins = Record<string, ReadonlyArray<ConformancePin>>
|
|
|
2397
2431
|
* file derives the skip list from this object so the two can't drift)
|
|
2398
2432
|
* and by `packages/compat` (the fixture-divergences section of
|
|
2399
2433
|
* `ui/compat.lock.json`, rendered on the docs compatibility-matrix
|
|
2400
|
-
* page). Keyed by shared-fixture id; the value
|
|
2401
|
-
*
|
|
2434
|
+
* page). Keyed by shared-fixture id; the value cites the registry entry
|
|
2435
|
+
* (`packages/adapter-tests/limitations/<id>.ts`, kind `silent`) that
|
|
2436
|
+
* defines the divergence — what the reference renders, what this
|
|
2437
|
+
* adapter renders instead.
|
|
2402
2438
|
*/
|
|
2403
|
-
export type RenderDivergences = Record<string, string>
|
|
2439
|
+
export type RenderDivergences = Record<string, { limitation: string }>
|
|
2404
2440
|
|
|
2405
2441
|
// =============================================================================
|
|
2406
2442
|
// Compile Options & Results
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `formatDate` lowering plugin (#2324) — the pure-function date formatter
|
|
3
|
-
* (`packages/client/src/format-date.ts`). A call to the `formatDate` binding
|
|
4
|
-
* imported from `@barefootjs/client` lowers to a backend-neutral
|
|
5
|
-
* `helper-call` on the `format_date` helper (spec/template-helpers.md), which
|
|
6
|
-
* every adapter renders through its generic helper-call path (#2069) — no
|
|
7
|
-
* adapter-specific recognition code, only the runtime helper each backend
|
|
8
|
-
* ships.
|
|
9
|
-
*
|
|
10
|
-
* The canonical helper arity is 3: a two-arg call site
|
|
11
|
-
* (`formatDate(d, 'YYYY/M/D')`) is normalized here by supplying the
|
|
12
|
-
* `'UTC'` literal the client function defaults to, so backend helpers stay
|
|
13
|
-
* fixed-arity. Unlike the `date` plugin there is no receiver-type gate —
|
|
14
|
-
* `formatDate` is recognised by its import binding (like `queryHref`), and
|
|
15
|
-
* its own receiver contract (native date / ISO string / nil → `''`) is total,
|
|
16
|
-
* so any argument expression the adapter can evaluate is admissible.
|
|
17
|
-
*/
|
|
18
|
-
import type { ParsedExpr } from './expression-parser.ts';
|
|
19
|
-
import type { LoweringNode, LoweringPlugin } from './lowering-registry.ts';
|
|
20
|
-
/**
|
|
21
|
-
* Recognise `formatDate(date, pattern[, timeZone[, names]])` against the
|
|
22
|
-
* component's local import bindings, or decline (null): a non-identifier
|
|
23
|
-
* callee, a name not bound to the `@barefootjs/client` import, or an arity
|
|
24
|
-
* outside 2–4. The canonical helper arity is 4 (#2334): omitted `timeZone` /
|
|
25
|
-
* `names` normalize to the `'UTC'` literal and the empty table the client
|
|
26
|
-
* function defaults to, so backend helpers stay fixed-arity.
|
|
27
|
-
*/
|
|
28
|
-
export declare function matchFormatDateCall(callee: ParsedExpr, args: readonly ParsedExpr[], locals: ReadonlySet<string>): LoweringNode | null;
|
|
29
|
-
export declare const formatDatePlugin: LoweringPlugin;
|
|
30
|
-
//# sourceMappingURL=format-date-lowering.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format-date-lowering.d.ts","sourceRoot":"","sources":["../src/format-date-lowering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAM1E;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,SAAS,UAAU,EAAE,EAC3B,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAC1B,YAAY,GAAG,IAAI,CAQrB;AAED,eAAO,MAAM,gBAAgB,EAAE,cAO9B,CAAA"}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `createSelector` compiler recognition (perf, #2143 gap 5).
|
|
3
|
-
*
|
|
4
|
-
* `createSelector`'s returned accessor is `Reactive<(key) => boolean>`
|
|
5
|
-
* branded exactly like a signal/memo getter, so the existing type-based
|
|
6
|
-
* reactivity analyzer (`reactivity-checker.ts`) recognises a call like
|
|
7
|
-
* `isSelected(row.id)` as reactive with no analyzer changes — the callee's
|
|
8
|
-
* type carries the brand, not the call's return type. These tests pin:
|
|
9
|
-
* - the classic js-framework-benchmark row compiles with `isSelected(row.id)`
|
|
10
|
-
* wired through the lazy row graph — ZERO emitted per-row effects, the
|
|
11
|
-
* loop-level effect living in `mapArrayLazy` (spec §9). Until §9.3a
|
|
12
|
-
* was lifted this shape was gate-INELIGIBLE (an opaque local whose call
|
|
13
|
-
* is the reactive read could not be primed) and compiled to one per-row
|
|
14
|
-
* `createEffect`; the runtime re-subscribe seam replaced that, so the
|
|
15
|
-
* loop is emitted like any other. Either way it is never
|
|
16
|
-
* the legacy `selected() === row.id` shape, which subscribes every row
|
|
17
|
-
* to the raw signal.
|
|
18
|
-
* - the loop-param accessor wrap applies only to the call ARGUMENT
|
|
19
|
-
* (`row.id` -> `row().id`), leaving the `isSelected` callee untouched
|
|
20
|
-
* - the hoisted skeleton fast path (#2223) still fires for a selector-driven
|
|
21
|
-
* attr, since it's covered by a loop-child reactive-attr effect like any
|
|
22
|
-
* other dynamic attribute
|
|
23
|
-
* - `createSelector` is pulled into the runtime import line
|
|
24
|
-
* - the attr is auto-deferred out of the SSR-mirror `template:` lambda
|
|
25
|
-
* (mechanism #1638, same as `@barefootjs/form` accessors) — pinned as
|
|
26
|
-
* documented behavior, not a regression: full SSR parity for selector
|
|
27
|
-
* calls is a known follow-up, not in scope here
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
import { describe, test, expect } from 'bun:test'
|
|
31
|
-
import { compileJSX } from '../compiler'
|
|
32
|
-
import { TestAdapter } from '../adapters/test-adapter'
|
|
33
|
-
|
|
34
|
-
const adapter = new TestAdapter()
|
|
35
|
-
|
|
36
|
-
function compile(source: string, filename: string): { clientJs: string; template: string; errors: readonly { severity: string }[] } {
|
|
37
|
-
const result = compileJSX(source, filename, { adapter })
|
|
38
|
-
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
39
|
-
const template = result.files.find(f => f.type === 'markedTemplate')
|
|
40
|
-
return { clientJs: clientJs?.content ?? '', template: template?.content ?? '', errors: result.errors }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
describe('createSelector (perf, #2143 gap 5)', () => {
|
|
44
|
-
test('isSelected(row.id) in a loop body compiles through the lazy row graph', () => {
|
|
45
|
-
const source = `
|
|
46
|
-
'use client'
|
|
47
|
-
import { createSignal, createSelector } from '@barefootjs/client'
|
|
48
|
-
|
|
49
|
-
interface RowData { id: number; label: string }
|
|
50
|
-
|
|
51
|
-
export function Bench() {
|
|
52
|
-
const [rows, setRows] = createSignal<RowData[]>([])
|
|
53
|
-
const [selected, setSelected] = createSignal<number>(0)
|
|
54
|
-
const isSelected = createSelector(selected)
|
|
55
|
-
return (
|
|
56
|
-
<table>
|
|
57
|
-
<tbody>
|
|
58
|
-
{rows().map(row => (
|
|
59
|
-
<tr key={row.id} className={isSelected(row.id) ? 'danger' : ''}></tr>
|
|
60
|
-
))}
|
|
61
|
-
</tbody>
|
|
62
|
-
</table>
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
`
|
|
66
|
-
const { clientJs, errors } = compile(source, 'Bench.tsx')
|
|
67
|
-
expect(errors.filter(e => e.severity === 'error')).toHaveLength(0)
|
|
68
|
-
|
|
69
|
-
// Loop-param wrap applies to the call ARGUMENT only.
|
|
70
|
-
expect(clientJs).toContain('isSelected(row().id)')
|
|
71
|
-
// The callee itself is never rewritten to an accessor call.
|
|
72
|
-
expect(clientJs).not.toContain('isSelected()(')
|
|
73
|
-
|
|
74
|
-
// The selector-driven class attribute costs NO emitted effect at all:
|
|
75
|
-
// the loop is lazy-eligible, so its one loop-level effect lives inside
|
|
76
|
-
// `mapArrayLazy` rather than in the emitted row body. It is also never
|
|
77
|
-
// the O(rows) `selected() === row.id` shape.
|
|
78
|
-
const effectCount = (clientJs.match(/createEffect\(/g) ?? []).length
|
|
79
|
-
expect(effectCount).toBe(0)
|
|
80
|
-
expect(clientJs).toContain('mapArrayLazy(')
|
|
81
|
-
expect(clientJs).not.toContain('selected() ===')
|
|
82
|
-
|
|
83
|
-
// `isSelected` is an opaque local (its CALL is the reactive read). Nothing
|
|
84
|
-
// in the emission marks that: the runtime's re-subscribe seam applies to
|
|
85
|
-
// every loop-level outer effect, so the compiler has no judgement to
|
|
86
|
-
// encode here (§9.3a).
|
|
87
|
-
expect(clientJs).not.toContain('outerNeedsResubscribe')
|
|
88
|
-
|
|
89
|
-
// The hoisted skeleton fast path (#2223) still fires: a single-line
|
|
90
|
-
// renderItem clones from a once-per-loop template.
|
|
91
|
-
expect(clientJs).toMatch(/const __tpl_\w+ = document\.createElement\('template'\)/)
|
|
92
|
-
|
|
93
|
-
// createSelector is pulled into the runtime import line.
|
|
94
|
-
expect(clientJs).toMatch(/import \{[^}]*\bcreateSelector\b[^}]*\} from '@barefootjs\/client\/runtime'/)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
test('selector-driven attr is deferred out of the SSR-mirror template lambda (documented, not a regression)', () => {
|
|
98
|
-
const source = `
|
|
99
|
-
'use client'
|
|
100
|
-
import { createSignal, createSelector } from '@barefootjs/client'
|
|
101
|
-
|
|
102
|
-
interface RowData { id: number; label: string }
|
|
103
|
-
|
|
104
|
-
export function Bench() {
|
|
105
|
-
const [rows, setRows] = createSignal<RowData[]>([])
|
|
106
|
-
const [selected, setSelected] = createSignal<number>(0)
|
|
107
|
-
const isSelected = createSelector(selected)
|
|
108
|
-
return (
|
|
109
|
-
<ul>
|
|
110
|
-
{rows().map(row => (
|
|
111
|
-
<li key={row.id} className={isSelected(row.id) ? 'danger' : ''}>{row.label}</li>
|
|
112
|
-
))}
|
|
113
|
-
</ul>
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
`
|
|
117
|
-
const { clientJs } = compile(source, 'BenchDefer.tsx')
|
|
118
|
-
const csrMirror = clientJs.slice(clientJs.indexOf('hydrate('))
|
|
119
|
-
// The class attribute never appears as a literal `class="..."` write in
|
|
120
|
-
// the SSR-mirror template string — it's covered entirely by the
|
|
121
|
-
// per-row createEffect, matching the documented auto-defer mechanism.
|
|
122
|
-
expect(csrMirror).not.toMatch(/class="danger"/)
|
|
123
|
-
})
|
|
124
|
-
})
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `formatDatePlugin` (#2324) — recognises the `formatDate` import from
|
|
3
|
-
* `@barefootjs/client` (incl. aliases and the runtime re-export) and lowers a
|
|
4
|
-
* `formatDate(date, pattern[, timeZone])` call to the backend-neutral
|
|
5
|
-
* `helper-call` on the `format_date` helper, normalizing the omitted
|
|
6
|
-
* `timeZone` to the `'UTC'` literal (fixed helper arity of 3).
|
|
7
|
-
*/
|
|
8
|
-
import { describe, expect, test } from 'bun:test'
|
|
9
|
-
import { compileJSX, type ComponentIR } from '../index'
|
|
10
|
-
import { formatDateLocalNames } from '../adapters/env-signal'
|
|
11
|
-
import { matchFormatDateCall, formatDatePlugin } from '../format-date-lowering'
|
|
12
|
-
import type { ParsedExpr } from '../expression-parser'
|
|
13
|
-
import { TestAdapter } from '../adapters/test-adapter'
|
|
14
|
-
|
|
15
|
-
function metadata(src: string): ComponentIR['metadata'] {
|
|
16
|
-
const result = compileJSX(src.trimStart(), 'T.tsx', { adapter: new TestAdapter(), outputIR: true })
|
|
17
|
-
const ir = JSON.parse(result.files.find(f => f.type === 'ir')!.content) as ComponentIR
|
|
18
|
-
return ir.metadata
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const CALLEE: ParsedExpr = { kind: 'identifier', name: 'formatDate' }
|
|
22
|
-
const DATE_ARG: ParsedExpr = { kind: 'identifier', name: 'createdAt' }
|
|
23
|
-
const PATTERN_ARG: ParsedExpr = { kind: 'literal', value: 'YYYY/M/D', literalType: 'string' }
|
|
24
|
-
const TZ_ARG: ParsedExpr = { kind: 'literal', value: '+09:00', literalType: 'string' }
|
|
25
|
-
const LOCALS = new Set(['formatDate'])
|
|
26
|
-
|
|
27
|
-
describe('formatDateLocalNames (#2324)', () => {
|
|
28
|
-
test('recognises the import, aliases, and the runtime entry', () => {
|
|
29
|
-
const md = metadata(`
|
|
30
|
-
'use client'
|
|
31
|
-
import { formatDate } from '@barefootjs/client'
|
|
32
|
-
export function P(props: { createdAt: Date }) {
|
|
33
|
-
return <time>{formatDate(props.createdAt, 'YYYY/M/D')}</time>
|
|
34
|
-
}
|
|
35
|
-
`)
|
|
36
|
-
expect([...formatDateLocalNames(md)]).toEqual(['formatDate'])
|
|
37
|
-
|
|
38
|
-
const aliased = metadata(`
|
|
39
|
-
'use client'
|
|
40
|
-
import { formatDate as fd } from '@barefootjs/client/runtime'
|
|
41
|
-
export function P(props: { createdAt: Date }) {
|
|
42
|
-
return <time>{fd(props.createdAt, 'YYYY/M/D')}</time>
|
|
43
|
-
}
|
|
44
|
-
`)
|
|
45
|
-
expect([...formatDateLocalNames(aliased)]).toEqual(['fd'])
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
test('is empty when not imported', () => {
|
|
49
|
-
const md = metadata(`
|
|
50
|
-
'use client'
|
|
51
|
-
export function P() { return <time>x</time> }
|
|
52
|
-
`)
|
|
53
|
-
expect(formatDateLocalNames(md).size).toBe(0)
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
const EMPTY_NAMES = { kind: 'array-literal', elements: [], raw: '[]' }
|
|
58
|
-
|
|
59
|
-
describe('matchFormatDateCall (#2324/#2334)', () => {
|
|
60
|
-
test('normalizes a 3-arg call to canonical arity 4 (empty names table)', () => {
|
|
61
|
-
expect(matchFormatDateCall(CALLEE, [DATE_ARG, PATTERN_ARG, TZ_ARG], LOCALS)).toEqual({
|
|
62
|
-
kind: 'helper-call',
|
|
63
|
-
helper: 'format_date',
|
|
64
|
-
args: [DATE_ARG, PATTERN_ARG, TZ_ARG, EMPTY_NAMES as ParsedExpr],
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
test('normalizes a 2-arg call by supplying the UTC literal and empty names', () => {
|
|
69
|
-
const node = matchFormatDateCall(CALLEE, [DATE_ARG, PATTERN_ARG], LOCALS)
|
|
70
|
-
expect(node).toEqual({
|
|
71
|
-
kind: 'helper-call',
|
|
72
|
-
helper: 'format_date',
|
|
73
|
-
args: [
|
|
74
|
-
DATE_ARG,
|
|
75
|
-
PATTERN_ARG,
|
|
76
|
-
{ kind: 'literal', value: 'UTC', literalType: 'string' },
|
|
77
|
-
EMPTY_NAMES as ParsedExpr,
|
|
78
|
-
],
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test('a caller-supplied 4th (names) argument passes through', () => {
|
|
83
|
-
const namesArg: ParsedExpr = { kind: 'identifier', name: 'names' }
|
|
84
|
-
expect(matchFormatDateCall(CALLEE, [DATE_ARG, PATTERN_ARG, TZ_ARG, namesArg], LOCALS)).toEqual({
|
|
85
|
-
kind: 'helper-call',
|
|
86
|
-
helper: 'format_date',
|
|
87
|
-
args: [DATE_ARG, PATTERN_ARG, TZ_ARG, namesArg],
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
test('declines wrong callees and arities', () => {
|
|
92
|
-
expect(matchFormatDateCall({ kind: 'identifier', name: 'other' }, [DATE_ARG, PATTERN_ARG], LOCALS)).toBeNull()
|
|
93
|
-
expect(
|
|
94
|
-
matchFormatDateCall(
|
|
95
|
-
{ kind: 'member', object: DATE_ARG, property: 'formatDate', computed: false } as ParsedExpr,
|
|
96
|
-
[DATE_ARG, PATTERN_ARG],
|
|
97
|
-
LOCALS,
|
|
98
|
-
),
|
|
99
|
-
).toBeNull()
|
|
100
|
-
expect(matchFormatDateCall(CALLEE, [DATE_ARG], LOCALS)).toBeNull()
|
|
101
|
-
expect(matchFormatDateCall(CALLEE, [DATE_ARG, PATTERN_ARG, TZ_ARG, TZ_ARG, TZ_ARG], LOCALS)).toBeNull()
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
test('the plugin prepares only for components that import formatDate', () => {
|
|
105
|
-
const withImport = metadata(`
|
|
106
|
-
'use client'
|
|
107
|
-
import { formatDate } from '@barefootjs/client'
|
|
108
|
-
export function P(props: { createdAt: Date }) {
|
|
109
|
-
return <time>{formatDate(props.createdAt, 'YYYY/M/D')}</time>
|
|
110
|
-
}
|
|
111
|
-
`)
|
|
112
|
-
const matcher = formatDatePlugin.prepare(withImport)
|
|
113
|
-
expect(matcher).not.toBeNull()
|
|
114
|
-
expect(matcher!(CALLEE, [DATE_ARG, PATTERN_ARG, TZ_ARG])).toMatchObject({
|
|
115
|
-
kind: 'helper-call',
|
|
116
|
-
helper: 'format_date',
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
const without = metadata(`
|
|
120
|
-
'use client'
|
|
121
|
-
export function P() { return <time>x</time> }
|
|
122
|
-
`)
|
|
123
|
-
expect(formatDatePlugin.prepare(without)).toBeNull()
|
|
124
|
-
})
|
|
125
|
-
})
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `formatDate` lowering plugin (#2324) — the pure-function date formatter
|
|
3
|
-
* (`packages/client/src/format-date.ts`). A call to the `formatDate` binding
|
|
4
|
-
* imported from `@barefootjs/client` lowers to a backend-neutral
|
|
5
|
-
* `helper-call` on the `format_date` helper (spec/template-helpers.md), which
|
|
6
|
-
* every adapter renders through its generic helper-call path (#2069) — no
|
|
7
|
-
* adapter-specific recognition code, only the runtime helper each backend
|
|
8
|
-
* ships.
|
|
9
|
-
*
|
|
10
|
-
* The canonical helper arity is 3: a two-arg call site
|
|
11
|
-
* (`formatDate(d, 'YYYY/M/D')`) is normalized here by supplying the
|
|
12
|
-
* `'UTC'` literal the client function defaults to, so backend helpers stay
|
|
13
|
-
* fixed-arity. Unlike the `date` plugin there is no receiver-type gate —
|
|
14
|
-
* `formatDate` is recognised by its import binding (like `queryHref`), and
|
|
15
|
-
* its own receiver contract (native date / ISO string / nil → `''`) is total,
|
|
16
|
-
* so any argument expression the adapter can evaluate is admissible.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import type { ParsedExpr } from './expression-parser.ts'
|
|
20
|
-
import type { LoweringNode, LoweringPlugin } from './lowering-registry.ts'
|
|
21
|
-
import { formatDateLocalNames } from './adapters/env-signal.ts'
|
|
22
|
-
|
|
23
|
-
const UTC_LITERAL: ParsedExpr = { kind: 'literal', value: 'UTC', literalType: 'string' }
|
|
24
|
-
const EMPTY_NAMES: ParsedExpr = { kind: 'array-literal', elements: [], raw: '[]' } as ParsedExpr
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Recognise `formatDate(date, pattern[, timeZone[, names]])` against the
|
|
28
|
-
* component's local import bindings, or decline (null): a non-identifier
|
|
29
|
-
* callee, a name not bound to the `@barefootjs/client` import, or an arity
|
|
30
|
-
* outside 2–4. The canonical helper arity is 4 (#2334): omitted `timeZone` /
|
|
31
|
-
* `names` normalize to the `'UTC'` literal and the empty table the client
|
|
32
|
-
* function defaults to, so backend helpers stay fixed-arity.
|
|
33
|
-
*/
|
|
34
|
-
export function matchFormatDateCall(
|
|
35
|
-
callee: ParsedExpr,
|
|
36
|
-
args: readonly ParsedExpr[],
|
|
37
|
-
locals: ReadonlySet<string>,
|
|
38
|
-
): LoweringNode | null {
|
|
39
|
-
if (callee.kind !== 'identifier' || !locals.has(callee.name)) return null
|
|
40
|
-
if (args.length < 2 || args.length > 4) return null
|
|
41
|
-
return {
|
|
42
|
-
kind: 'helper-call',
|
|
43
|
-
helper: 'format_date',
|
|
44
|
-
args: [args[0], args[1], args[2] ?? UTC_LITERAL, args[3] ?? EMPTY_NAMES],
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const formatDatePlugin: LoweringPlugin = {
|
|
49
|
-
name: 'formatDate',
|
|
50
|
-
prepare(metadata) {
|
|
51
|
-
const locals = formatDateLocalNames(metadata)
|
|
52
|
-
if (locals.size === 0) return null
|
|
53
|
-
return (callee, args) => matchFormatDateCall(callee, args, locals)
|
|
54
|
-
},
|
|
55
|
-
}
|