@barefootjs/blade 0.1.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.
Files changed (72) hide show
  1. package/README.md +73 -0
  2. package/dist/adapter/analysis/component-tree.d.ts +26 -0
  3. package/dist/adapter/analysis/component-tree.d.ts.map +1 -0
  4. package/dist/adapter/blade-adapter.d.ts +537 -0
  5. package/dist/adapter/blade-adapter.d.ts.map +1 -0
  6. package/dist/adapter/boolean-result.d.ts +76 -0
  7. package/dist/adapter/boolean-result.d.ts.map +1 -0
  8. package/dist/adapter/emit-context.d.ts +105 -0
  9. package/dist/adapter/emit-context.d.ts.map +1 -0
  10. package/dist/adapter/expr/array-method.d.ts +74 -0
  11. package/dist/adapter/expr/array-method.d.ts.map +1 -0
  12. package/dist/adapter/expr/emitters.d.ts +176 -0
  13. package/dist/adapter/expr/emitters.d.ts.map +1 -0
  14. package/dist/adapter/expr/operand.d.ts +25 -0
  15. package/dist/adapter/expr/operand.d.ts.map +1 -0
  16. package/dist/adapter/index.d.ts +6 -0
  17. package/dist/adapter/index.d.ts.map +1 -0
  18. package/dist/adapter/index.js +189060 -0
  19. package/dist/adapter/lib/blade-naming.d.ts +128 -0
  20. package/dist/adapter/lib/blade-naming.d.ts.map +1 -0
  21. package/dist/adapter/lib/constants.d.ts +21 -0
  22. package/dist/adapter/lib/constants.d.ts.map +1 -0
  23. package/dist/adapter/lib/ir-scope.d.ts +48 -0
  24. package/dist/adapter/lib/ir-scope.d.ts.map +1 -0
  25. package/dist/adapter/lib/types.d.ts +27 -0
  26. package/dist/adapter/lib/types.d.ts.map +1 -0
  27. package/dist/adapter/memo/seed.d.ts +84 -0
  28. package/dist/adapter/memo/seed.d.ts.map +1 -0
  29. package/dist/adapter/props/prop-classes.d.ts +34 -0
  30. package/dist/adapter/props/prop-classes.d.ts.map +1 -0
  31. package/dist/adapter/spread/spread-codegen.d.ts +72 -0
  32. package/dist/adapter/spread/spread-codegen.d.ts.map +1 -0
  33. package/dist/adapter/value/parsed-literal.d.ts +27 -0
  34. package/dist/adapter/value/parsed-literal.d.ts.map +1 -0
  35. package/dist/build.d.ts +28 -0
  36. package/dist/build.d.ts.map +1 -0
  37. package/dist/build.js +189080 -0
  38. package/dist/conformance-pins.d.ts +12 -0
  39. package/dist/conformance-pins.d.ts.map +1 -0
  40. package/dist/index.d.ts +9 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +189079 -0
  43. package/package.json +67 -0
  44. package/php/composer.json +32 -0
  45. package/php/src/BladeBackend.php +197 -0
  46. package/php/src/naming.php +84 -0
  47. package/php/tests/test_render.php +159 -0
  48. package/src/__tests__/blade-adapter-unit.test.ts +392 -0
  49. package/src/__tests__/blade-adapter.test.ts +52 -0
  50. package/src/__tests__/blade-counter.test.ts +63 -0
  51. package/src/__tests__/blade-query-href.test.ts +113 -0
  52. package/src/__tests__/blade-spread-attrs.test.ts +235 -0
  53. package/src/adapter/analysis/component-tree.ts +119 -0
  54. package/src/adapter/blade-adapter.ts +1912 -0
  55. package/src/adapter/boolean-result.ts +168 -0
  56. package/src/adapter/emit-context.ts +117 -0
  57. package/src/adapter/expr/array-method.ts +345 -0
  58. package/src/adapter/expr/emitters.ts +636 -0
  59. package/src/adapter/expr/operand.ts +35 -0
  60. package/src/adapter/index.ts +6 -0
  61. package/src/adapter/lib/blade-naming.ts +180 -0
  62. package/src/adapter/lib/constants.ts +33 -0
  63. package/src/adapter/lib/ir-scope.ts +83 -0
  64. package/src/adapter/lib/types.ts +30 -0
  65. package/src/adapter/memo/seed.ts +135 -0
  66. package/src/adapter/props/prop-classes.ts +66 -0
  67. package/src/adapter/spread/spread-codegen.ts +179 -0
  68. package/src/adapter/value/parsed-literal.ts +75 -0
  69. package/src/build.ts +37 -0
  70. package/src/conformance-pins.ts +86 -0
  71. package/src/index.ts +9 -0
  72. package/src/test-render.ts +782 -0
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Blade/PHP identifier, hash-key, and member/index-access conventions for
3
+ * the Blade adapter.
4
+ *
5
+ * Ported from `packages/adapter-twig/src/adapter/lib/twig-naming.ts`
6
+ * (`twigIdent`/`twigHashKey`/`twigLoopBindingAccessor`), adjusted for the
7
+ * real syntax divergences between Twig and Blade that matter here:
8
+ *
9
+ * 1. **Every variable reference needs the `$` sigil.** Twig has no sigil —
10
+ * `twigIdent(name)` returned the bare (possibly mangled) name, used
11
+ * directly as both a read and a `{% set %}` assignment target. Blade
12
+ * compiles straight to raw PHP, where every variable — read OR write —
13
+ * is `$name`. `bladeIdent(name)` (this file) mirrors `twigIdent`'s
14
+ * mangling-only role (used for the PHP array KEY a prop is threaded
15
+ * through as, e.g. `naming.php`'s `blade_ident`); `bladeVar(name)` is the
16
+ * NEW wrapper that additionally prepends `$` — every place the Blade
17
+ * adapter emits a bare variable REFERENCE (identifier read, loop-binding
18
+ * `@php($x = ...)` target, hash-entry value, …) uses `bladeVar`, not
19
+ * `bladeIdent` alone.
20
+ * 2. **Hash-literal keys are always quoted, but the literal itself is a PHP
21
+ * array, not a Twig hash.** `{'k': v}` → `['k' => v]` (mapping table) —
22
+ * `bladeHashKey` still always quotes (same bareword-key trap Twig/Jinja
23
+ * have), but every CALL SITE joins entries with `=>` and wraps them in
24
+ * `[...]`, never `{...}` / `: `.
25
+ * 3. **Member/index access has no raw-PHP polymorphic equivalent.** Twig's
26
+ * `.`/`[]` transparently resolve an object property, an array key, OR a
27
+ * getter method on ANY of {stdClass, array, null} under
28
+ * `strict_variables: false`. Raw PHP has no single operator with that
29
+ * property — `$x->prop` fatals on a non-object, `$x['key']` warns on
30
+ * `null`/scalar, and dynamic keys need yet another form. This adapter
31
+ * uses Laravel's `data_get($target, $key)` (from `illuminate/support`,
32
+ * already a transitive dependency of `illuminate/view`) uniformly for
33
+ * BOTH member access (`a.b` → `data_get($a, 'b')`) and index access
34
+ * (`a[i]` → `data_get($a, $i)`) — verified empirically (see
35
+ * `bladeMemberAccess`'s docstring) to be null-safe over the same
36
+ * {stdClass, array, null} value shapes Twig's dot/bracket cover, with NO
37
+ * runtime helper added to `packages/adapter-php` (the `data_get`
38
+ * lowering point is entirely on the TS emit side).
39
+ * 4. **Reserved-word set is COMPLETELY DIFFERENT, and for a different
40
+ * reason.** Twig keywords (`for`, `filter`, `if`, …) collide with Twig's
41
+ * OWN expression grammar — irrelevant here, since Blade variables are
42
+ * real PHP variables (`$for`, `$filter` are legal). What collides
43
+ * instead is anything the Blade/illuminate RENDER-TIME PHP SCOPE already
44
+ * binds to a different meaning, or a name PHP itself forbids — see
45
+ * `RESERVED_WORDS`'s docstring below and `php/src/naming.php`'s (this
46
+ * adapter's PHP-side twin, which MUST mirror this list exactly; each
47
+ * side carries a parity test against the other).
48
+ */
49
+ import type { LoopBindingPathSegment } from '@barefootjs/jsx';
50
+ /**
51
+ * Escape a string for a PHP/Blade single-quoted literal: backslash first (so
52
+ * it doesn't double-escape the quote we add next), then the quote. PHP's
53
+ * single-quoted string escaping rules are `\\` and `\'` ONLY (verified:
54
+ * `php -r "echo 'a\\'b';"` → `a'b`) — byte-identical to Twig's own
55
+ * single-quoted escaping, so this function's body is unchanged from
56
+ * `escapeTwigSingleQuoted`.
57
+ */
58
+ export declare function escapeBladeSingleQuoted(s: string): string;
59
+ /**
60
+ * Quote an array-literal KEY for Blade/PHP. Always quotes — a bareword key
61
+ * in a PHP array literal (`[key => value]`) is a syntax error, not a
62
+ * variable lookup (unlike Twig's hash literal, where an unquoted key reads
63
+ * as a variable reference) — but this adapter quotes unconditionally anyway
64
+ * for one uniform rule across every adapter in the family (mirrors
65
+ * `twigHashKey`/`jinjaHashKey`).
66
+ */
67
+ export declare function bladeHashKey(name: string): string;
68
+ /**
69
+ * Mangle a JS identifier (prop name, signal getter, loop param, …) into a
70
+ * Blade-safe NAME: reserved words get a trailing `_` suffix, everything else
71
+ * passes through unchanged. This is the BARE (no `$`) form — used for a PHP
72
+ * array KEY a prop is threaded through as (`naming.php`'s `blade_ident`,
73
+ * `BladeBackend::render_named`'s per-prop mangling). Every place the adapter
74
+ * emits an actual Blade VARIABLE REFERENCE uses `bladeVar` (below), which
75
+ * wraps this with the `$` sigil Twig's `twigIdent` never needed.
76
+ */
77
+ export declare function bladeIdent(name: string): string;
78
+ /**
79
+ * Mangle a JS identifier into a Blade VARIABLE REFERENCE (`$name` or
80
+ * `$name_` when reserved) — the sigil-bearing counterpart of `bladeIdent`,
81
+ * used at every point the adapter emits a bare variable read OR a
82
+ * `@php($NAME = ...)` assignment target (mirrors every `twigIdent(...)`
83
+ * call site in the Twig port, since Twig had no sigil to add).
84
+ */
85
+ export declare function bladeVar(name: string): string;
86
+ /**
87
+ * Member access lowering: `a.b` → `data_get($a, 'b')`. Uniform, null-safe
88
+ * over `stdClass` (JSON-decoded objects), PHP assoc arrays (runtime helper
89
+ * outputs), and `null` — verified empirically:
90
+ *
91
+ * php -r 'require "vendor/autoload.php";
92
+ * $o = json_decode("{\"a\":{\"b\":1}}");
93
+ * var_dump(data_get($o, "a.b")); // int(1)
94
+ * var_dump(data_get($o, "missing.x")); // NULL (no warning)
95
+ * var_dump(data_get(null, "a.b")); // NULL (no warning)'
96
+ *
97
+ * `data_get` treats a key with no `.` as ONE top-level segment (not a
98
+ * multi-hop path), so a literal property name that itself happens to
99
+ * contain a `.` character would be misread as a nested path — accepted as a
100
+ * known, narrow limitation (JS field/prop names essentially never contain a
101
+ * literal dot; no adapter-conformance fixture does).
102
+ */
103
+ export declare function bladeMemberAccess(objectExpr: string, property: string): string;
104
+ /**
105
+ * Index access lowering: `a[i]` → `data_get($a, $i)`. `data_get` accepts a
106
+ * non-string (int, or a PHP expression evaluating to int/string) segment
107
+ * directly — verified empirically: `data_get(['a','b','c'], $i)` with
108
+ * `$i = 1` → `'b'`. Same null-safety as `bladeMemberAccess`.
109
+ */
110
+ export declare function bladeIndexAccess(objectExpr: string, indexExpr: string): string;
111
+ /**
112
+ * Build a Blade/PHP accessor expression that walks a `.map()` destructure
113
+ * binding's structured `segments` path (#2087 Phase A, `LoopBindingPathSegment`)
114
+ * off `base` — the per-iteration loop var (`$__bf_item`) for a fixed binding
115
+ * or a top-level rest binding, or an already-built PARENT accessor for a
116
+ * nested rest binding (`segments` there is the prefix up to, not including,
117
+ * the rest token).
118
+ *
119
+ * UNLIKE `twigLoopBindingAccessor` (which branches on bracket-subscript vs.
120
+ * dot-access vs. the `attribute()` builtin depending on whether a `field`
121
+ * segment's key is identifier-safe), every segment here — `index` OR `field`,
122
+ * ident-safe or not — routes through the SAME uniform `data_get` accessor
123
+ * (see the file header, divergence 3): there is no raw-PHP polymorphic
124
+ * operator to special-case around in the first place, so there is nothing to
125
+ * branch on. This is strictly SIMPLER than the Twig port.
126
+ */
127
+ export declare function bladeLoopBindingAccessor(base: string, segments: readonly LoopBindingPathSegment[]): string;
128
+ //# sourceMappingURL=blade-naming.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blade-naming.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/blade-naming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAE7D;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAwBD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,SAAS,sBAAsB,EAAE,GAC1C,MAAM,CAQR"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Compile-time constant tables for the Blade template adapter.
3
+ *
4
+ * Ported from `packages/adapter-jinja/src/adapter/lib/constants.ts`.
5
+ */
6
+ import type { PrimitiveSpec } from './types.ts';
7
+ /**
8
+ * Single source of truth for the Blade adapter's template-primitive surface.
9
+ * Each entry pairs the expected arity with the emit function.
10
+ *
11
+ * The emit fn returns a Blade/PHP expression (no surrounding `{{ }}`)
12
+ * suitable for embedding inside an interpolation — `$bf->json($val)`,
13
+ * `$bf->floor($val)`, etc. Same primitive names and keys as the Jinja/Twig
14
+ * adapters; every `bf.xxx(...)` call becomes `$bf->xxx(...)` (mapping table).
15
+ */
16
+ export declare const BLADE_TEMPLATE_PRIMITIVES: Record<string, PrimitiveSpec>;
17
+ /**
18
+ * Module-scope `templatePrimitives` map derived once from the spec record.
19
+ */
20
+ export declare const BLADE_PRIMITIVE_EMIT_MAP: Record<string, (args: string[]) => string>;
21
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAOnE,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,MAAM,CAG7E,CAAA"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * IR traversal helpers for the Blade template adapter.
3
+ *
4
+ * Ported from `packages/adapter-twig/src/adapter/lib/ir-scope.ts`.
5
+ * `resolveJsxChildrenProp` and `collectRootScopeNodes` are byte-identical
6
+ * (adapter-agnostic IR walks).
7
+ *
8
+ * `extractTopLevelIdentifiers` is SIMPLER than the Twig port's. Twig
9
+ * identifiers have no sigil, so that port had to strip quoted strings first,
10
+ * exclude dotted property/method names, and drop a closed set of Twig-
11
+ * grammar keywords the adapter's own codegen could emit (`is`, `defined`,
12
+ * `and`, `not`, `null`, `true`, `false`, `bf`) to avoid false-matching one of
13
+ * those as a genuine context-var reference. Blade variables carry PHP's `$`
14
+ * sigil — the SAME property that made Kolon's own `\$([A-Za-z_]\w*)` scan
15
+ * trivially safe (see the Twig port's file header, which calls this out
16
+ * explicitly as the thing Twig's sigil-less grammar lacked). So this port
17
+ * needs no quote-stripping, no dotted-name exclusion (member/index access
18
+ * here is `data_get(...)`, a function call, not a `.`/`[]` postfix that
19
+ * could attach to a preceding bare word), and no keyword-exclusion set at
20
+ * all — the ONLY non-context-var `$name` this adapter's own codegen ever
21
+ * emits is `$bf` (the runtime handle), excluded explicitly below.
22
+ */
23
+ import type { IRNode, IRProp } from '@barefootjs/jsx';
24
+ /**
25
+ * Extract the set of "top-level identifier" tokens (bare `$name` references,
26
+ * `$bf` excluded) from a rendered Blade expression. `memo/seed.ts` uses this
27
+ * to detect a constant lowering (no real variable reference at all) that
28
+ * should keep the static ssr-defaults seed instead of an in-template
29
+ * `@php($x = ...)`; scope AVAILABILITY itself is the shared
30
+ * `computeSsrSeedPlan`'s job (packages/jsx/src/ssr-seed-plan.ts), not this
31
+ * module's.
32
+ */
33
+ export declare function extractTopLevelIdentifiers(bladeExpr: string): string[];
34
+ /**
35
+ * Find the `children` prop's `jsx-children` payload. Narrowed via the
36
+ * AttrValue `kind` discriminator so adapter code stays type-safe if the IR
37
+ * shape evolves.
38
+ */
39
+ export declare function resolveJsxChildrenProp(props: readonly IRProp[]): IRNode[];
40
+ /**
41
+ * Collect the component's root scope element node(s) — the elements that
42
+ * become the rendered root and so carry `data-key` for a keyed loop item. A
43
+ * plain element root is itself; an `if-statement` (early-return) root
44
+ * contributes the top element of each branch, since exactly one renders at
45
+ * runtime. (#1297)
46
+ */
47
+ export declare function collectRootScopeNodes(node: IRNode): Set<IRNode>;
48
+ //# sourceMappingURL=ir-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ir-scope.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/ir-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAA6B,MAAM,iBAAiB,CAAA;AAEhF;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAUtE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAKzE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAiB/D"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Shared type aliases for the Blade template adapter.
3
+ *
4
+ * Ported from `packages/adapter-jinja/src/adapter/lib/types.ts`: pure type
5
+ * declarations — no runtime behaviour — so the extracted emit modules and
6
+ * the main adapter share one definition rather than re-declaring the
7
+ * render context / options shape.
8
+ */
9
+ /** A template-primitive spec: expected call arity + the emit fn. */
10
+ export interface PrimitiveSpec {
11
+ arity: number;
12
+ emit: (args: string[]) => string;
13
+ }
14
+ /**
15
+ * Blade adapter's IRNode render context. Like the Jinja adapter, Blade's
16
+ * lowering doesn't consume any render-position flags, so the Ctx is empty.
17
+ * Kept as a named alias so future flags can extend it without changing the
18
+ * `IRNodeEmitter` interface.
19
+ */
20
+ export type BladeRenderCtx = Record<string, never>;
21
+ export interface BladeAdapterOptions {
22
+ /** Base path for client JS files (default: '/static/components/') */
23
+ clientJsBasePath?: string;
24
+ /** Path to barefoot.js runtime (default: '/static/components/barefoot.js') */
25
+ barefootJsPath?: string;
26
+ }
27
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,MAAM,CAAA;CACjC;AAED;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;AAElD,MAAM,WAAW,mBAAmB;IAClC,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAEzB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * In-template memo / context seeding for the Blade template adapter.
3
+ *
4
+ * Ported from `packages/adapter-twig/src/adapter/memo/seed.ts`. Free
5
+ * functions taking a `BladeMemoContext` (built by the adapter's `memoCtx`
6
+ * getter) so the cluster depends only on the recursive expression entry, not
7
+ * the whole adapter class. These emit the `@php($x = ...)` statements that
8
+ * let the body's bare `$x` resolve to a derived signal/memo value or an
9
+ * active context value at SSR time.
10
+ *
11
+ * One deliberate behavioural IMPROVEMENT over the Kolon port, carried
12
+ * through from the Twig/Jinja ports unchanged: Kolon's `my` declares a NEW
13
+ * lexical, so `: my $x = … $x …;` reads the not-yet-assigned lexical on its
14
+ * own right-hand side — broken. Blade's `@php($x = ...)` compiles to a
15
+ * plain PHP assignment statement — PHP has function-level (not block-level)
16
+ * scope, and the view-rendering method already `extract()`ed the incoming
17
+ * template vars into real PHP variables before this statement runs, so
18
+ * `@php($x = $x + 1)` simply reads-then-reassigns the SAME `$x` — no
19
+ * shadowing hazard (verified empirically:
20
+ * `$factory->make('t', ['x' => 5])->render()` over a template whose body is
21
+ * `@php($x = $x + 1)\n{{ $x }}` → `"6"`, not an error or a stale `5` — same
22
+ * behaviour Twig/Jinja exhibit). This adapter therefore seeds a same-name
23
+ * signal/memo too, which is strictly more correct — the seed then
24
+ * re-derives from the already-bound prop instead of leaving the render var
25
+ * on its static (possibly per-callsite-wrong) default. No self-ref guard is
26
+ * ported for this reason (same as the Twig port's divergence 8).
27
+ */
28
+ import { type ComponentIR, type ContextConsumer } from '@barefootjs/jsx';
29
+ import type { BladeMemoContext } from '../emit-context.ts';
30
+ /** Blade/PHP literal for a context-consumer's `createContext` default. */
31
+ export declare function contextDefaultBlade(c: ContextConsumer): string;
32
+ /**
33
+ * Emit one `@php($local = $bf->use_context(...))` statement per context
34
+ * consumer so the body's bare `$local` resolves to the active provider
35
+ * value (or the `createContext` default). (#1297)
36
+ */
37
+ export declare function generateContextConsumerSeed(ir: ComponentIR): string;
38
+ /**
39
+ * Emit `@php($name = <blade>)` statements for every `derived` step of the
40
+ * backend-neutral SSR seed plan — the scope/availability/ordering analysis
41
+ * lives in `computeSsrSeedPlan` (packages/jsx/src/ssr-seed-plan.ts); this
42
+ * only lowers each step's expression to Blade and applies the
43
+ * backend-specific emit guards: skip an empty lowering, and skip a lowering
44
+ * that references no top-level identifier at all (a constant init/body —
45
+ * e.g. a `derived` step with empty `frees` — keeps the existing static
46
+ * ssr-defaults seed instead). Unlike the Kolon port there is no self-ref
47
+ * guard — see the file header. `env-reader` and `opaque` steps emit nothing
48
+ * (the runtime supplies the reader, or the adapter's ssr-defaults path
49
+ * already covers it). (#1297, #2075)
50
+ *
51
+ * `convertExpressionToBlade` can still fail DEEPER than the plan's
52
+ * structural `isSupported` pre-check — e.g. a `.filter(predicate)` whose
53
+ * predicate isn't evaluator-serializable has NO lambda fallback on this
54
+ * adapter (`expr/emitters.ts`'s file header, divergence 9: unlike Kolon/Perl,
55
+ * Blade has no lambda-expression form), so the lowering records a HARD
56
+ * BF101 as a side effect rather than degrading. That's correct for every
57
+ * OTHER `convertExpressionToBlade` call site (which commit to using the
58
+ * lowered text), but wrong here: this is a SPECULATIVE "recompute the memo
59
+ * in-template, else keep the static ssrDefault seed" attempt, so a deeper
60
+ * refusal must degrade silently, not fail the whole component compile.
61
+ * Snapshot the diagnostic list and roll back any errors appended during each
62
+ * step's attempt before moving on.
63
+ *
64
+ * A second, related divergence opens up: a predicate referencing a SIBLING
65
+ * getter (`props.items.filter((p) => !tag() || …)`, `tag` a sibling memo)
66
+ * contains a zero-arg CALL node (`tag()`), which the evaluator's pure-
67
+ * expression surface refuses (`toEvalNode`'s `call` arm only allows a
68
+ * builtin callee, e.g. `Math.floor`) — with no lambda fallback to fall back
69
+ * to, the whole predicate would refuse. Kolon/Perl never hit this: their
70
+ * lambda form closes over the sibling's ALREADY-SEEDED lexical directly,
71
+ * without going through the evaluator at all. Go hits the identical gap (it
72
+ * also has no closures at SSR-constructor time) and fixes it the same way
73
+ * its `memo/memo-compute.ts` (`matchFilterArmMemo`) does:
74
+ * `materializeGetterCalls` rewrites a getter call into a bare identifier
75
+ * BEFORE serialization, so the evaluator captures it as a free-var read from
76
+ * `base_env` instead of an unsupported call node — and that free var then
77
+ * resolves against the sibling's own `@php($x = ...)` line, which (being an
78
+ * EARLIER step per the plan's ordering guarantee) is always already bound.
79
+ * `env-reader` names are excluded from the materializable set — the runtime
80
+ * supplies those via the per-request reader, not a template-var lexical, so
81
+ * a call to one (`searchParams()`) must stay a real call, not a bare var.
82
+ */
83
+ export declare function generateDerivedMemoSeed(ctx: BladeMemoContext, ir: ComponentIR): string;
84
+ //# sourceMappingURL=seed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../../src/adapter/memo/seed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,eAAe,EAIrB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAI1D,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,eAAe,GAAG,MAAM,CAM9D;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,WAAW,GAAG,MAAM,CAWnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,gBAAgB,EAAE,EAAE,EAAE,WAAW,GAAG,MAAM,CAsBtF"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Prop classification for the Blade template adapter.
3
+ *
4
+ * Ported from `packages/adapter-jinja/src/adapter/props/prop-classes.ts`.
5
+ * Pure functions over `ir.metadata` that derive the per-compile prop/name
6
+ * sets the adapter consults during lowering. No adapter instance state.
7
+ */
8
+ import type { ComponentIR } from '@barefootjs/jsx';
9
+ /**
10
+ * Props whose declared TS type is boolean — a bare binding of one
11
+ * (`data-active={props.isActive}`) must stringify as JS `String(boolean)`
12
+ * ("true"/"false"), not PHP's `(string) bool` ("1"/"") (#1897, pagination's
13
+ * data-active).
14
+ */
15
+ export declare function collectBooleanTypedProps(ir: ComponentIR): Set<string>;
16
+ /**
17
+ * Bare references to optional, no-default, non-primitive props (e.g.
18
+ * textarea's `rows`) are `null` when omitted → guarded with
19
+ * `is defined and is not null` in `emitExpression`. See the
20
+ * `nullableOptionalProps` field docstring in `blade-adapter.ts`.
21
+ */
22
+ export declare function collectNullableOptionalProps(ir: ComponentIR): Set<string>;
23
+ /**
24
+ * String-typed signals and props. A signal is string-typed when its inferred
25
+ * type is `string` (or, defensively, when its initial value is a bare string
26
+ * literal); a prop when its annotated type is `string`. In the Mojo adapter
27
+ * this drives `eq`/`ne` selection for string equality; the Blade emitters
28
+ * don't consume the distinction — `===`/`!==` ALWAYS route through
29
+ * `bf.eq`/`bf.neq` regardless of operand type (see
30
+ * `expr/emitters.ts`'s file header, divergence 4) — so this set is carried
31
+ * only for parity with the Perl-family adapters.
32
+ */
33
+ export declare function collectStringValueNames(ir: ComponentIR): Set<string>;
34
+ //# sourceMappingURL=prop-classes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prop-classes.d.ts","sourceRoot":"","sources":["../../../src/adapter/props/prop-classes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAGlD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,CAMrE;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,EAAE,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,CAWzE;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,CAWpE"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Object-literal / conditional-spread → Blade hash lowering for the Blade
3
+ * template adapter.
4
+ *
5
+ * Ported from `packages/adapter-jinja/src/adapter/spread/spread-codegen.ts`.
6
+ * Free functions taking a `BladeSpreadContext` (built by the adapter's
7
+ * `spreadCtx` getter) so the cluster depends on the narrow seam — the
8
+ * recursive expression entry plus per-compile bookkeeping — rather than the
9
+ * whole adapter class.
10
+ *
11
+ * The conditional-spread / object-literal entries read the IR-carried
12
+ * structured `ParsedExpr` tree (#2018) instead of re-parsing the source with
13
+ * `ts.createSourceFile`. The condition and scalar values are threaded
14
+ * straight into `ctx.convertExpressionToBlade` as its `preParsed` argument,
15
+ * so no stringify→re-parse round-trip occurs. The `ts.factory` rebuild in
16
+ * `recordIndexAccessToBlade` only reconstructs the `IDENT[KEY]` node the
17
+ * shared `parseRecordIndexAccess` parser accepts; no source-text re-parse.
18
+ *
19
+ * Twig→Blade divergence: a Twig hash literal `{'k': v}` becomes a PHP array
20
+ * literal `['k' => v]` (mapping table) — `'key' => value` entries joined by
21
+ * `, `, wrapped in `[...]`, never `{...}`. Empty hash is `[]`, not `{}`.
22
+ */
23
+ import type { ParsedExpr } from '@barefootjs/jsx';
24
+ import type { BladeSpreadContext } from '../emit-context.ts';
25
+ /**
26
+ * Lower a conditional inline-object spread
27
+ * `COND ? { 'aria-describedby': describedBy } : {}`
28
+ * to a Blade inline ternary of PHP arrays
29
+ * `($bf->truthy($describedBy) ? ['aria-describedby' => $describedBy] : [])`.
30
+ * Reads the IR-carried structured `ParsedExpr` tree; both branches must be
31
+ * object literals; the condition + values route through
32
+ * `convertExpressionToBlade`. Returns `null` for any other shape so the
33
+ * caller falls back to its normal lowering.
34
+ */
35
+ export declare function conditionalSpreadToBlade(ctx: BladeSpreadContext, expr: ParsedExpr | undefined): string | null;
36
+ /**
37
+ * (#1971) Lower a bare object-literal expression (`{ align: 'start' }`),
38
+ * carried as the IR's structured `ParsedExpr` tree, to a PHP array via
39
+ * `objectLiteralToBladeDict`, or null when it isn't a plain object literal.
40
+ * Used for inline object-literal child props (carousel `opts`).
41
+ */
42
+ export declare function objectLiteralExprToBladeDict(ctx: BladeSpreadContext, expr: ParsedExpr | undefined): string | null;
43
+ /**
44
+ * Convert a static object literal into a PHP array-literal string for a
45
+ * conditional spread. Only static string/identifier keys are allowed; values
46
+ * resolve via `convertExpressionToBlade` (or the `Record[propKey]` index
47
+ * lowering). Returns `null` for any computed/spread/dynamic key. Empty
48
+ * object → `[]`.
49
+ */
50
+ export declare function objectLiteralToBladeDict(ctx: BladeSpreadContext, obj: Extract<ParsedExpr, {
51
+ kind: 'object-literal';
52
+ }>): string | null;
53
+ /**
54
+ * Lower a spread-object VALUE of the form `IDENT[KEY]` (CheckIcon's
55
+ * `sizeMap[size]`) to an inline indexed PHP array
56
+ * `['sm' => 16, 'md' => 20, ...][$size]`.
57
+ * Reuses the shared structural parse (`parseRecordIndexAccess`) — rebuilding
58
+ * the `IDENT[KEY]` node from the carried tree via `ts.factory` rather than
59
+ * re-parsing source text; this wrapper only does the single-quote escaping +
60
+ * bracket-index emit. PHP indexes an array literal with the SAME bracket
61
+ * syntax `[...][key]` a JS object index would use (verified empirically —
62
+ * `php -r 'var_dump(["a"=>1]["a"]);'` → `1`) — no Kolon-style divergence to
63
+ * steer around here. Unlike Twig's own hash `{…}[key]`, a MISSING key here
64
+ * would normally raise a PHP warning rather than resolve to `null` — this
65
+ * call site's caller (`objectLiteralToBladeDict`'s data-table lookup path,
66
+ * and `blade-adapter.ts`'s `${MAP}[key]` template-literal lowering) always
67
+ * wraps the result in `?? ''`/`?? null`, which silences an undefined-index
68
+ * warning exactly like it silences an undefined-variable one (see
69
+ * `blade-adapter.ts`'s file header, the `??` divergence).
70
+ */
71
+ export declare function recordIndexAccessToBlade(ctx: BladeSpreadContext, val: ParsedExpr): string | null;
72
+ //# sourceMappingURL=spread-codegen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spread-codegen.d.ts","sourceRoot":"","sources":["../../../src/adapter/spread/spread-codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAG5D;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,kBAAkB,EACvB,IAAI,EAAE,UAAU,GAAG,SAAS,GAC3B,MAAM,GAAG,IAAI,CAgBf;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,kBAAkB,EACvB,IAAI,EAAE,UAAU,GAAG,SAAS,GAC3B,MAAM,GAAG,IAAI,CAGf;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,kBAAkB,EACvB,GAAG,EAAE,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,CAAC,GACnD,MAAM,GAAG,IAAI,CA0Cf;AAUD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAuBhG"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * String-literal value lowering for the Blade template adapter.
3
+ *
4
+ * Ported from `packages/adapter-jinja/src/adapter/value/parsed-literal.ts`.
5
+ * Byte-identical logic (the source-text parsing here is language-agnostic;
6
+ * only the caller's escaping of the resolved value into a template literal
7
+ * differs, and that happens at the call site in `blade-adapter.ts`, not
8
+ * here).
9
+ */
10
+ import { type TypeInfo } from '@barefootjs/jsx';
11
+ /**
12
+ * Parse a const initializer's source text. Returns the unescaped string value
13
+ * when the whole initializer is a single pure string literal — single/double
14
+ * quoted, or a no-substitution backtick template (no `${}`) — else `null`.
15
+ * Only such a value can be inlined byte-for-byte; template literals with
16
+ * interpolation, numbers, objects, and `Record<T,string>` maps are excluded.
17
+ */
18
+ export declare function parsePureStringLiteral(source: string): string | null;
19
+ /** Whether `s` contains an unescaped occurrence of `ch`. */
20
+ export declare function containsUnescaped(s: string, ch: string): boolean;
21
+ /** Unescape a JS string-literal body's common escape sequences. */
22
+ export declare function unescapeStringLiteralBody(s: string): string;
23
+ /** True when `type` is the `string` primitive. */
24
+ export declare function isStringTypeInfo(type: TypeInfo | undefined): boolean;
25
+ /** True when `initialValue` is a bare string-literal expression. */
26
+ export declare function isBareStringLiteral(initialValue: string | undefined): boolean;
27
+ //# sourceMappingURL=parsed-literal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsed-literal.d.ts","sourceRoot":"","sources":["../../../src/adapter/value/parsed-literal.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAuB,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAEpE;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAqBpE;AAED,4DAA4D;AAC5D,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAMhE;AAED,mEAAmE;AACnE,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAU3D;AAED,kDAAkD;AAClD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO,CAEpE;AAED,oEAAoE;AACpE,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAI7E"}
@@ -0,0 +1,28 @@
1
+ import type { BuildOptions } from '@barefootjs/jsx';
2
+ import { BladeAdapter } from './adapter/index.ts';
3
+ import type { BladeAdapterOptions } from './adapter/index.ts';
4
+ export interface BladeBuildOptions extends BuildOptions {
5
+ /** Adapter-specific options passed to BladeAdapter */
6
+ adapterOptions?: BladeAdapterOptions;
7
+ }
8
+ /**
9
+ * Create a BarefootBuildConfig for Blade (PHP) template projects.
10
+ *
11
+ * Uses structural typing — does not import BarefootBuildConfig to avoid a
12
+ * circular dependency between @barefootjs/blade and @barefootjs/cli.
13
+ */
14
+ export declare function createConfig(options?: BladeBuildOptions): {
15
+ adapter: BladeAdapter;
16
+ paths: import("@barefootjs/jsx").BarefootPaths | undefined;
17
+ components: string[] | undefined;
18
+ outDir: string | undefined;
19
+ minify: boolean | undefined;
20
+ contentHash: boolean | undefined;
21
+ externals: Record<string, import("@barefootjs/jsx").ExternalSpec> | undefined;
22
+ externalsBasePath: string | undefined;
23
+ bundleEntries: import("@barefootjs/jsx").BundleEntry[] | undefined;
24
+ localImportPrefixes: string[] | undefined;
25
+ outputLayout: import("@barefootjs/jsx").OutputLayout;
26
+ postBuild: ((ctx: import("@barefootjs/jsx").PostBuildContext) => Promise<void> | void) | undefined;
27
+ };
28
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,MAAM,WAAW,iBAAkB,SAAQ,YAAY;IACrD,sDAAsD;IACtD,cAAc,CAAC,EAAE,mBAAmB,CAAA;CACrC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,iBAAsB;IAExD,OAAO;IACP,KAAK;IACL,UAAU;IACV,MAAM;IACN,MAAM;IACN,WAAW;IACX,SAAS;IACT,iBAAiB;IACjB,aAAa;IACb,mBAAmB;IACnB,YAAY;IAKZ,SAAS;EAEZ"}