@barefootjs/jsx 0.8.0 → 0.9.1

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.
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Shared adapter helpers for the SolidJS props-object pattern (#checkbox).
3
+ *
4
+ * These two functions are the SINGLE SOURCE OF TRUTH for logic that the
5
+ * Go-template and Mojolicious template adapters previously carried as
6
+ * near-identical private copies. They live in `@barefootjs/jsx` (the IR
7
+ * layer) so the two adapters can share one implementation; they are
8
+ * deliberately NOT wired into the core IR-construction pipeline — only the
9
+ * Go and Mojo adapters call them, so every other IR consumer (Hono, the
10
+ * client codegen, etc.) is unaffected.
11
+ */
12
+ import ts from 'typescript';
13
+ import type { ComponentIR, IRMetadata } from './types';
14
+ /**
15
+ * A `const x = useContext(SomeContext)` consumer in a component body. SSR
16
+ * template adapters have no JS runtime context stack, so a consumer's value is
17
+ * threaded in at the data-construction layer: the adapter exposes a field/stash
18
+ * var defaulted to the context default, which an enclosing `<Ctx.Provider
19
+ * value>` overwrites for descendant child slots.
20
+ */
21
+ export interface ContextConsumer {
22
+ /** The local const bound to the `useContext` call (e.g. `theme`). */
23
+ localName: string;
24
+ /** The `createContext` identifier read (e.g. `ThemeContext`). */
25
+ contextName: string;
26
+ /**
27
+ * The `createContext(<default>)` argument as a JS literal, or `null` when
28
+ * absent / not a literal (the consumer then defaults to the empty value).
29
+ */
30
+ defaultValue: string | number | boolean | null;
31
+ }
32
+ /**
33
+ * Collect every `const x = useContext(Ctx)` consumer in a component, resolving
34
+ * each `Ctx` to its `createContext(<default>)` default via the component's
35
+ * module-scope `createContext` constants. Returns `[]` when the component
36
+ * consumes no context. Single source of truth for the SSR-context adapters.
37
+ */
38
+ export declare function collectContextConsumers(metadata: IRMetadata): ContextConsumer[];
39
+ /**
40
+ * (#checkbox) Enumerate inherited-attribute accesses for the SolidJS
41
+ * props-object pattern.
42
+ *
43
+ * `function Checkbox(props: CheckboxProps)` only lists `CheckboxProps`'s own
44
+ * members in `propsParams`; the inherited `ButtonHTMLAttributes` members the
45
+ * component actually reads (`props.className` in the classes memo, `props.id`,
46
+ * `props.disabled` on the root element) are never enumerated, so the generated
47
+ * Input/Props structs (Go) or stash vars (Mojo) have no field to bind a
48
+ * caller's `className: ''` / `id` / `disabled` to. This scans the component's
49
+ * expressions for `props.<name>` accesses (where `props` is the resolved
50
+ * `propsObjectName`) and appends any not-already-a-param as a synthetic prop
51
+ * param, with a type inferred from how the access is used:
52
+ * - a boolean attribute (`disabled={props.disabled ?? false}`) → `boolean`;
53
+ * - a pure bare-reference attribute (`id={props.id}`) → `unknown`
54
+ * (nillable, so the attribute is omitted when unset — Hono parity);
55
+ * - otherwise (`className`, read in a string memo) → `string`.
56
+ *
57
+ * Scans memos, signals, init statements, effects, and template attribute
58
+ * expressions. (The Mojo adapter previously omitted `effects` from its scan;
59
+ * unifying on the Go behaviour of also scanning `effects` is intentional — the
60
+ * function only ever ADDS a param, and it changes no fixture output.)
61
+ *
62
+ * Idempotent: re-running (e.g. once in `generate`, again in `generateTypes` on
63
+ * a round-tripped IR) is a no-op once the params are present. Mutates
64
+ * `ir.metadata.propsParams` in place so every downstream emitter sees one
65
+ * consistent param list.
66
+ *
67
+ * The single source of truth for BOTH the Go and Mojo adapters — change here,
68
+ * not in an adapter copy.
69
+ */
70
+ export declare function augmentInheritedPropAccesses(ir: ComponentIR): void;
71
+ /**
72
+ * Statically evaluate `[<string literals>].join(<sep?>)` (e.g. a module-scope
73
+ * `const stateClasses = ['…', …].join(' ')`) to its joined string, so SSR
74
+ * adapters inline the flattened literal byte-for-byte like the Hono reference
75
+ * instead of referencing a binding that doesn't exist server-side. Default
76
+ * separator `,` matches JS `Array.prototype.join`. Returns `null` for any
77
+ * other shape (non-`.join` call, non-array receiver, non-string-literal element
78
+ * or separator). Shared by the Mojo + Xslate adapters; Go keeps a private copy.
79
+ */
80
+ export declare function evalStringArrayJoin(source: string): string | null;
81
+ /** A minimal `{ name }` shape — both adapters pass their own param/const lists. */
82
+ interface NamedConst {
83
+ name: string;
84
+ value?: string;
85
+ isModule?: boolean;
86
+ }
87
+ /** A parsed `Record<staticKeys, scalar>[propKey]` map entry. */
88
+ export interface RecordIndexEntry {
89
+ key: string;
90
+ value: {
91
+ kind: 'number' | 'string';
92
+ text: string;
93
+ };
94
+ }
95
+ /** The structured result of a `Record<staticKeys, scalar>[propKey]` access. */
96
+ export interface RecordIndexAccess {
97
+ /** The bare prop identifier used as the index key (`size` in `sizeMap[size]`). */
98
+ indexPropName: string;
99
+ /** The map's entries in source order — each a static key + scalar literal value. */
100
+ entries: RecordIndexEntry[];
101
+ /**
102
+ * When the index key is a local const with a `props.X ?? '<lit>'` default
103
+ * (the Toggle `classes` memo's `const variant = props.variant ?? 'default'`),
104
+ * the `<lit>` fallback key — so a caller can render the default entry's value
105
+ * when the prop is unset. Absent when the key is a bare prop with no default.
106
+ */
107
+ defaultKey?: string;
108
+ }
109
+ /**
110
+ * Structural parse of a spread-object VALUE of the form `IDENT[KEY]` where:
111
+ * - `IDENT` resolves via `localConstants` to a MODULE-scope (`isModule`)
112
+ * object literal whose every property has a static (string-literal or
113
+ * identifier) key and a scalar (number or string) literal value
114
+ * (a `Record<staticKeys, scalar>` map like `sizeMap`), AND
115
+ * - `KEY` is a bare identifier that is a prop (`propsParams`).
116
+ *
117
+ * Returns the structured `{ indexPropName, entries }` when convertible, else
118
+ * `null` for any unsupported shape (non-element-access, non-identifier
119
+ * object/index, non-prop index, non-module const, non-object-literal const,
120
+ * computed/spread/dynamic key, or non-scalar value) so the caller falls back
121
+ * to its normal lowering / BF101.
122
+ *
123
+ * The single source of truth for BOTH adapters' `recordIndexAccessTo*` emitters
124
+ * — only the final language-specific emit differs (Go inline `map[string]any{…}
125
+ * [fmt.Sprint(in.Field)]`; Mojo `{ … }->{$key}`). (#checkbox / icon `sizeMap[size]`.)
126
+ */
127
+ export declare function parseRecordIndexAccess(val: ts.Expression, localConstants: readonly NamedConst[], propsParams: ReadonlyArray<{
128
+ name: string;
129
+ }>,
130
+ /**
131
+ * Resolves an index key that isn't a bare prop (a memo-local const like
132
+ * `const variant = props.variant ?? 'default'`) to its underlying prop + an
133
+ * optional default-key literal; returns `null` to reject. Keeps the parse
134
+ * generic — the caller owns the block-scoped binding map.
135
+ */
136
+ resolveKey?: (name: string) => {
137
+ propName: string;
138
+ defaultLiteral?: string;
139
+ } | null): RecordIndexAccess | null;
140
+ export {};
141
+ //# sourceMappingURL=augment-inherited-props.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augment-inherited-props.d.ts","sourceRoot":"","sources":["../src/augment-inherited-props.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAA+B,MAAM,SAAS,CAAA;AAGnF;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAA;IACjB,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;CAC/C;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,UAAU,GAAG,eAAe,EAAE,CAsB/E;AAkCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,4BAA4B,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,CA6ElE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA8BjE;AAED,mFAAmF;AACnF,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,gEAAgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE;QAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CACnD;AAED,+EAA+E;AAC/E,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,aAAa,EAAE,MAAM,CAAA;IACrB,oFAAoF;IACpF,OAAO,EAAE,gBAAgB,EAAE,CAAA;IAC3B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,EAAE,CAAC,UAAU,EAClB,cAAc,EAAE,SAAS,UAAU,EAAE,EACrC,WAAW,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAC5C;;;;;GAKG;AACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAClF,iBAAiB,GAAG,IAAI,CA2D1B"}
@@ -13,6 +13,28 @@ export interface CompileOptionsWithAdapter extends CompileOptions {
13
13
  /** Template adapter for generating output (required) */
14
14
  adapter: TemplateAdapter;
15
15
  }
16
+ /**
17
+ * Merge the import lines of a multi-component template file into a single,
18
+ * conflict-free block.
19
+ *
20
+ * Named value/type imports from the same source are folded into their first
21
+ * occurrence (preserving line order and first-seen symbol order); every
22
+ * other import form (side-effect, default, namespace) is kept in place and
23
+ * de-duplicated by exact line. This ensures a symbol is never imported
24
+ * twice across sibling components — a redeclaration that Bun tolerates but
25
+ * stricter ESM parsers (the Deno runtime that renders SSR templates) reject.
26
+ *
27
+ * For a single-component file the output is identical to the input order;
28
+ * only repeated sibling imports collapse.
29
+ *
30
+ * Matching is whitespace-insensitive (`import {a,b} from 'x'` and
31
+ * `import { a , b } from "x"` fold the same): the merge must not silently
32
+ * depend on the emitter's exact spacing. A named import that failed to match
33
+ * would fall through to the by-line branch below and re-introduce the very
34
+ * duplicate-binding SyntaxError this function exists to prevent, so the
35
+ * patterns tolerate any spacing the generated lines might carry.
36
+ */
37
+ export declare function mergeTemplateImports(lines: string[]): string;
16
38
  export declare function buildMetadata(ctx: ReturnType<typeof analyzeComponent>): IRMetadata;
17
39
  export declare function compileJSX(source: string, filePath: string, options: CompileOptionsWithAdapter): CompileResult;
18
40
  export type { ComponentIR, CompileOptions, CompileResult, FileOutput };
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,aAAa,EACb,UAAU,EACX,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAyE,MAAM,YAAY,CAAA;AAWpH;;GAEG;AACH,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC/D,wDAAwD;IACxD,OAAO,EAAE,eAAe,CAAA;CACzB;AAmYD,wBAAgB,aAAa,CAC3B,GAAG,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GACvC,UAAU,CA4BZ;AAMD,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,yBAAyB,GACjC,aAAa,CAoOf;AAMD,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,CAAA"}
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,aAAa,EACb,UAAU,EACX,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAyE,MAAM,YAAY,CAAA;AAWpH;;GAEG;AACH,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC/D,wDAAwD;IACxD,OAAO,EAAE,eAAe,CAAA;CACzB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAyC5D;AAgYD,wBAAgB,aAAa,CAC3B,GAAG,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GACvC,UAAU,CA4BZ;AAMD,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,yBAAyB,GACjC,aAAa,CAoOf;AAMD,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,CAAA"}
package/dist/index.d.ts CHANGED
@@ -175,5 +175,7 @@ export { buildComponentGraph, buildComponentAnalysis, buildGraphFromIR, buildEve
175
175
  export type { ComponentGraph, ComponentAnalysis, SignalNode, MemoNode, EffectNode, DomBinding, UpdatePath, SignalTrace, EventBinding, SetterRef, FnSetterResolution, EventSummary, LoopInfo, LoopChildBinding, LoopSummary, WhyUpdateResult, WhyUpdateDep, WhyUpdateSource, FallbackExplanation, ComponentSummary } from './debug';
176
176
  export type { WrapReason } from './ir-to-client-js/reactivity';
177
177
  export { BOOLEAN_ATTRS, isBooleanAttr } from './html-constants';
178
+ export { augmentInheritedPropAccesses, parseRecordIndexAccess, evalStringArrayJoin, collectContextConsumers } from './augment-inherited-props';
179
+ export type { RecordIndexAccess, RecordIndexEntry, ContextConsumer } from './augment-inherited-props';
178
180
  export type { TargetedEvent, TargetedInputEvent, TargetedFocusEvent, TargetedKeyboardEvent, TargetedMouseEvent, InputEventHandler, FocusEventHandler, KeyboardEventHandler, MouseEventHandler, ChangeEventHandler, BaseEventAttributes, HTMLBaseAttributes, HTMLAttributeFormEnctype, HTMLAttributeFormMethod, HTMLAttributeAnchorTarget, ButtonHTMLAttributes, InputHTMLAttributes, TextareaHTMLAttributes, SelectHTMLAttributes, FormHTMLAttributes, AnchorHTMLAttributes, ImgHTMLAttributes, LabelHTMLAttributes, OptionHTMLAttributes, } from './html-types';
179
181
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACtD,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGtG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGhD,YAAY,EACV,WAAW,EACX,MAAM,EACN,SAAS,EACT,MAAM,EACN,YAAY,EACZ,aAAa,EACb,MAAM,EACN,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,MAAM,EACN,aAAa,EACb,UAAU,EACV,OAAO,EACP,UAAU,EACV,SAAS,EACT,WAAW,EACX,cAAc,EACd,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACV,eAAe,EACf,cAAc,EACd,MAAM,EACN,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,cAAc,EACd,aAAa,GACd,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,sBAAsB,IAAI,sBAAsB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AAC3O,OAAO,EAAE,sBAAsB,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAGpF,OA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AiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAGlB,mBAAmB,EACnB,kBAAkB,EAGlB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,EAGzB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -16738,6 +16738,15 @@ function extractSsrDefaults(metadata) {
16738
16738
  out[metadata.restPropsName] = { isRestProps: true, value: {} };
16739
16739
  }
16740
16740
  const bindings = {};
16741
+ for (const c of metadata.localConstants ?? []) {
16742
+ if (!c.isModule || c.value === undefined)
16743
+ continue;
16744
+ if (c.name in bindings)
16745
+ continue;
16746
+ const v = tryStaticEval(c.value, { bindings, propsLike });
16747
+ if (v !== UNRESOLVED)
16748
+ bindings[c.name] = v;
16749
+ }
16741
16750
  for (const sig of metadata.signals) {
16742
16751
  if (!sig.getter || sig.isModule)
16743
16752
  continue;
@@ -16789,8 +16798,26 @@ function evalNode(node, ctx) {
16789
16798
  if (ts16.isNonNullExpression(node))
16790
16799
  return evalNode(node.expression, ctx);
16791
16800
  if (ts16.isArrowFunction(node)) {
16792
- if (node.parameters.length === 0 && !ts16.isBlock(node.body)) {
16801
+ if (node.parameters.length !== 0)
16802
+ return UNRESOLVED;
16803
+ if (!ts16.isBlock(node.body))
16793
16804
  return evalNode(node.body, ctx);
16805
+ const localBindings = { ...ctx.bindings };
16806
+ const localCtx = { ...ctx, bindings: localBindings };
16807
+ for (const stmt of node.body.statements) {
16808
+ if (ts16.isVariableStatement(stmt)) {
16809
+ for (const d of stmt.declarationList.declarations) {
16810
+ if (!ts16.isIdentifier(d.name) || !d.initializer)
16811
+ continue;
16812
+ const v = evalNode(d.initializer, localCtx);
16813
+ if (v !== UNRESOLVED)
16814
+ localBindings[d.name.text] = v;
16815
+ }
16816
+ } else if (ts16.isReturnStatement(stmt)) {
16817
+ return stmt.expression ? evalNode(stmt.expression, localCtx) : UNRESOLVED;
16818
+ } else {
16819
+ return UNRESOLVED;
16820
+ }
16794
16821
  }
16795
16822
  return UNRESOLVED;
16796
16823
  }
@@ -16859,7 +16886,21 @@ function evalNode(node, ctx) {
16859
16886
  }
16860
16887
  return arr;
16861
16888
  }
16862
- if (ts16.isPropertyAccessExpression(node) || ts16.isElementAccessExpression(node)) {
16889
+ if (ts16.isElementAccessExpression(node)) {
16890
+ const base = evalNode(node.expression, ctx);
16891
+ if (base === undefined)
16892
+ return;
16893
+ if (base === UNRESOLVED || base === null || typeof base !== "object")
16894
+ return UNRESOLVED;
16895
+ if (!node.argumentExpression)
16896
+ return UNRESOLVED;
16897
+ const key = evalNode(node.argumentExpression, ctx);
16898
+ if (key === UNRESOLVED || key === undefined || key === null)
16899
+ return UNRESOLVED;
16900
+ const k = String(key);
16901
+ return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
16902
+ }
16903
+ if (ts16.isPropertyAccessExpression(node)) {
16863
16904
  const baseResult = evalNode(node.expression, ctx);
16864
16905
  if (baseResult === undefined)
16865
16906
  return;
@@ -16869,6 +16910,20 @@ function evalNode(node, ctx) {
16869
16910
  if (node.arguments.length === 0 && ts16.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
16870
16911
  return ctx.bindings[node.expression.text];
16871
16912
  }
16913
+ if (ts16.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
16914
+ const recv = evalNode(node.expression.expression, ctx);
16915
+ if (Array.isArray(recv)) {
16916
+ let sep2 = ",";
16917
+ if (node.arguments.length >= 1) {
16918
+ const sepVal = evalNode(node.arguments[0], ctx);
16919
+ if (typeof sepVal !== "string")
16920
+ return UNRESOLVED;
16921
+ sep2 = sepVal;
16922
+ }
16923
+ return recv.map((x) => x === null || x === undefined ? "" : `${x}`).join(sep2);
16924
+ }
16925
+ return UNRESOLVED;
16926
+ }
16872
16927
  return UNRESOLVED;
16873
16928
  }
16874
16929
  if (ts16.isConditionalExpression(node)) {
@@ -16945,6 +17000,42 @@ function evalNode(node, ctx) {
16945
17000
  }
16946
17001
 
16947
17002
  // src/compiler.ts
17003
+ function mergeTemplateImports(lines) {
17004
+ const result = [];
17005
+ const valueIdx = new Map;
17006
+ const valueNames = new Map;
17007
+ const typeIdx = new Map;
17008
+ const typeNames = new Map;
17009
+ const seenOther = new Set;
17010
+ const fold = (src, rawNames, idx, names, render) => {
17011
+ if (!idx.has(src)) {
17012
+ idx.set(src, result.length);
17013
+ names.set(src, new Set);
17014
+ result.push("");
17015
+ }
17016
+ const set = names.get(src);
17017
+ for (const n of rawNames.split(",").map((s) => s.trim()).filter(Boolean))
17018
+ set.add(n);
17019
+ result[idx.get(src)] = render(src, set);
17020
+ };
17021
+ for (const raw of lines) {
17022
+ const line = raw.trim();
17023
+ if (!line)
17024
+ continue;
17025
+ const typeMatch = line.match(/^import\s+type\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]\s*;?$/);
17026
+ const valueMatch = line.match(/^import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]\s*;?$/);
17027
+ if (valueMatch) {
17028
+ fold(valueMatch[2], valueMatch[1], valueIdx, valueNames, (s, n) => `import { ${[...n].join(", ")} } from '${s}'`);
17029
+ } else if (typeMatch) {
17030
+ fold(typeMatch[2], typeMatch[1], typeIdx, typeNames, (s, n) => `import type { ${[...n].join(", ")} } from '${s}'`);
17031
+ } else if (!seenOther.has(line)) {
17032
+ seenOther.add(line);
17033
+ result.push(line);
17034
+ }
17035
+ }
17036
+ return result.filter(Boolean).join(`
17037
+ `);
17038
+ }
16948
17039
  function compileMultipleComponents(source, filePath, componentNames, options) {
16949
17040
  const files = [];
16950
17041
  const errors = [];
@@ -17102,21 +17193,8 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
17102
17193
  }
17103
17194
  return { files, errors };
17104
17195
  }
17105
- const seenImportLines = new Set;
17106
- const uniqueImports = [];
17107
- for (const output of allOutputs) {
17108
- if (output.imports) {
17109
- for (const line of output.imports.split(`
17110
- `)) {
17111
- if (line.trim() && !seenImportLines.has(line)) {
17112
- seenImportLines.add(line);
17113
- uniqueImports.push(line);
17114
- }
17115
- }
17116
- }
17117
- }
17118
- const mergedImports = uniqueImports.join(`
17119
- `);
17196
+ const mergedImports = mergeTemplateImports(allOutputs.flatMap((o) => o.imports ? o.imports.split(`
17197
+ `) : []));
17120
17198
  const seenTypes = new Set;
17121
17199
  const uniqueTypes = [];
17122
17200
  for (const output of allOutputs) {
@@ -19131,6 +19209,236 @@ function findSourceFile2(meta) {
19131
19209
  }
19132
19210
  return null;
19133
19211
  }
19212
+ // src/augment-inherited-props.ts
19213
+ import ts19 from "typescript";
19214
+ function collectContextConsumers(metadata) {
19215
+ const constants = metadata.localConstants ?? [];
19216
+ const contextDefaults = new Map;
19217
+ for (const c of constants) {
19218
+ if (c.systemConstructKind !== "createContext" || c.value === undefined)
19219
+ continue;
19220
+ contextDefaults.set(c.name, parseCreateContextDefault(c.value));
19221
+ }
19222
+ if (contextDefaults.size === 0)
19223
+ return [];
19224
+ const consumers = [];
19225
+ for (const c of constants) {
19226
+ if (c.value === undefined)
19227
+ continue;
19228
+ const ctxName = parseUseContextArg(c.value);
19229
+ if (ctxName === null || !contextDefaults.has(ctxName))
19230
+ continue;
19231
+ consumers.push({
19232
+ localName: c.name,
19233
+ contextName: ctxName,
19234
+ defaultValue: contextDefaults.get(ctxName) ?? null
19235
+ });
19236
+ }
19237
+ return consumers;
19238
+ }
19239
+ function parseUseContextArg(source) {
19240
+ const expr = parseSingleExpression(source);
19241
+ if (!expr || !ts19.isCallExpression(expr))
19242
+ return null;
19243
+ if (!ts19.isIdentifier(expr.expression) || expr.expression.text !== "useContext")
19244
+ return null;
19245
+ if (expr.arguments.length !== 1)
19246
+ return null;
19247
+ const arg = expr.arguments[0];
19248
+ return ts19.isIdentifier(arg) ? arg.text : null;
19249
+ }
19250
+ function parseCreateContextDefault(source) {
19251
+ const expr = parseSingleExpression(source);
19252
+ if (!expr || !ts19.isCallExpression(expr))
19253
+ return null;
19254
+ if (expr.arguments.length === 0)
19255
+ return null;
19256
+ const arg = expr.arguments[0];
19257
+ if (ts19.isStringLiteral(arg) || ts19.isNoSubstitutionTemplateLiteral(arg))
19258
+ return arg.text;
19259
+ if (ts19.isNumericLiteral(arg))
19260
+ return Number(arg.text);
19261
+ if (arg.kind === ts19.SyntaxKind.TrueKeyword)
19262
+ return true;
19263
+ if (arg.kind === ts19.SyntaxKind.FalseKeyword)
19264
+ return false;
19265
+ return null;
19266
+ }
19267
+ function parseSingleExpression(source) {
19268
+ const sf = ts19.createSourceFile("__ctx.ts", `(${source})`, ts19.ScriptTarget.Latest, false);
19269
+ const stmt = sf.statements[0];
19270
+ if (!stmt || !ts19.isExpressionStatement(stmt))
19271
+ return null;
19272
+ let e = stmt.expression;
19273
+ while (ts19.isParenthesizedExpression(e))
19274
+ e = e.expression;
19275
+ return e;
19276
+ }
19277
+ function augmentInheritedPropAccesses(ir) {
19278
+ const propsObj = ir.metadata.propsObjectName;
19279
+ if (!propsObj)
19280
+ return;
19281
+ const existing = new Set(ir.metadata.propsParams.map((p) => p.name));
19282
+ const bareRefProps = new Set;
19283
+ const booleanAttrProps = new Set;
19284
+ const accessed = new Set;
19285
+ const accessRe = new RegExp(`(?:^|[^\\w$.])${propsObj}\\.([A-Za-z_$][\\w$]*)`, "g");
19286
+ const scan = (s) => {
19287
+ if (!s)
19288
+ return;
19289
+ for (const m of s.matchAll(accessRe))
19290
+ accessed.add(m[1]);
19291
+ };
19292
+ for (const memo of ir.metadata.memos)
19293
+ scan(memo.computation);
19294
+ for (const signal of ir.metadata.signals)
19295
+ scan(signal.initialValue);
19296
+ for (const stmt of ir.metadata.initStatements ?? [])
19297
+ scan(stmt.body);
19298
+ for (const eff of ir.metadata.effects ?? [])
19299
+ scan(eff.body);
19300
+ for (const c of ir.metadata.localConstants ?? []) {
19301
+ if (c.isModule)
19302
+ continue;
19303
+ scan(c.value);
19304
+ }
19305
+ const walk = (node) => {
19306
+ if (!node)
19307
+ return;
19308
+ const el = node;
19309
+ for (const attr of el.attrs ?? []) {
19310
+ const v = attr.value;
19311
+ if (v?.kind === "expression" && typeof v.expr === "string") {
19312
+ scan(v.expr);
19313
+ const expr = v.expr.trim();
19314
+ const prefix = `${propsObj}.`;
19315
+ if (isBooleanAttr(attr.name) || v.presenceOrUndefined) {
19316
+ const m = expr.match(new RegExp(`^${propsObj}\\.([A-Za-z_$][\\w$]*)`));
19317
+ if (m)
19318
+ booleanAttrProps.add(m[1]);
19319
+ } else if (expr.startsWith(prefix)) {
19320
+ const rest = expr.slice(prefix.length);
19321
+ if (/^[A-Za-z_$][\w$]*$/.test(rest))
19322
+ bareRefProps.add(rest);
19323
+ }
19324
+ }
19325
+ }
19326
+ for (const child of el.children ?? []) {
19327
+ const c = child;
19328
+ walk(c.element ?? child);
19329
+ }
19330
+ };
19331
+ walk(ir.root);
19332
+ for (const name of accessed) {
19333
+ if (existing.has(name))
19334
+ continue;
19335
+ let raw;
19336
+ if (booleanAttrProps.has(name))
19337
+ raw = "boolean";
19338
+ else if (bareRefProps.has(name))
19339
+ raw = "unknown";
19340
+ else
19341
+ raw = "string";
19342
+ const type = raw === "boolean" ? { kind: "primitive", raw: "boolean", primitive: "boolean" } : raw === "string" ? { kind: "primitive", raw: "string", primitive: "string" } : { kind: "unknown", raw: "unknown" };
19343
+ ir.metadata.propsParams.push({ name, type, optional: true });
19344
+ existing.add(name);
19345
+ }
19346
+ }
19347
+ function evalStringArrayJoin(source) {
19348
+ const sf = ts19.createSourceFile("__join.ts", `const __x = (${source});`, ts19.ScriptTarget.Latest, false);
19349
+ const stmt = sf.statements[0];
19350
+ if (!stmt || !ts19.isVariableStatement(stmt))
19351
+ return null;
19352
+ let node = stmt.declarationList.declarations[0]?.initializer;
19353
+ while (node && ts19.isParenthesizedExpression(node))
19354
+ node = node.expression;
19355
+ if (!node || !ts19.isCallExpression(node))
19356
+ return null;
19357
+ const callee = node.expression;
19358
+ if (!ts19.isPropertyAccessExpression(callee))
19359
+ return null;
19360
+ if (callee.name.text !== "join")
19361
+ return null;
19362
+ let recv = callee.expression;
19363
+ while (ts19.isParenthesizedExpression(recv))
19364
+ recv = recv.expression;
19365
+ if (!ts19.isArrayLiteralExpression(recv))
19366
+ return null;
19367
+ const parts = [];
19368
+ for (const el of recv.elements) {
19369
+ if (ts19.isStringLiteral(el) || ts19.isNoSubstitutionTemplateLiteral(el)) {
19370
+ parts.push(el.text);
19371
+ } else {
19372
+ return null;
19373
+ }
19374
+ }
19375
+ let sep2 = ",";
19376
+ if (node.arguments.length >= 1) {
19377
+ const arg = node.arguments[0];
19378
+ if (ts19.isStringLiteral(arg) || ts19.isNoSubstitutionTemplateLiteral(arg))
19379
+ sep2 = arg.text;
19380
+ else
19381
+ return null;
19382
+ }
19383
+ return parts.join(sep2);
19384
+ }
19385
+ function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
19386
+ if (!ts19.isElementAccessExpression(val))
19387
+ return null;
19388
+ const obj = val.expression;
19389
+ const arg = val.argumentExpression;
19390
+ if (!ts19.isIdentifier(obj) || !ts19.isIdentifier(arg))
19391
+ return null;
19392
+ let indexPropName;
19393
+ let defaultKey;
19394
+ const resolved = resolveKey?.(arg.text);
19395
+ if (resolved) {
19396
+ indexPropName = resolved.propName;
19397
+ defaultKey = resolved.defaultLiteral;
19398
+ } else if (propsParams.some((p) => p.name === arg.text)) {
19399
+ indexPropName = arg.text;
19400
+ } else {
19401
+ return null;
19402
+ }
19403
+ const constInfo = localConstants.find((c) => c.name === obj.text && c.isModule);
19404
+ if (constInfo?.value === undefined)
19405
+ return null;
19406
+ const sf = ts19.createSourceFile("__rec.ts", `(${constInfo.value})`, ts19.ScriptTarget.Latest, true);
19407
+ if (sf.statements.length !== 1)
19408
+ return null;
19409
+ const stmt = sf.statements[0];
19410
+ if (!ts19.isExpressionStatement(stmt))
19411
+ return null;
19412
+ let parsed = stmt.expression;
19413
+ while (ts19.isParenthesizedExpression(parsed))
19414
+ parsed = parsed.expression;
19415
+ if (!ts19.isObjectLiteralExpression(parsed))
19416
+ return null;
19417
+ const entries = [];
19418
+ for (const prop of parsed.properties) {
19419
+ if (!ts19.isPropertyAssignment(prop))
19420
+ return null;
19421
+ let key;
19422
+ if (ts19.isIdentifier(prop.name)) {
19423
+ key = prop.name.text;
19424
+ } else if (ts19.isStringLiteral(prop.name) || ts19.isNoSubstitutionTemplateLiteral(prop.name)) {
19425
+ key = prop.name.text;
19426
+ } else {
19427
+ return null;
19428
+ }
19429
+ let v = prop.initializer;
19430
+ while (ts19.isParenthesizedExpression(v))
19431
+ v = v.expression;
19432
+ if (ts19.isNumericLiteral(v)) {
19433
+ entries.push({ key, value: { kind: "number", text: v.text } });
19434
+ } else if (ts19.isStringLiteral(v) || ts19.isNoSubstitutionTemplateLiteral(v)) {
19435
+ entries.push({ key, value: { kind: "string", text: v.text } });
19436
+ } else {
19437
+ return null;
19438
+ }
19439
+ }
19440
+ return { indexPropName, entries, defaultKey };
19441
+ }
19134
19442
  export {
19135
19443
  traceUpdatePath,
19136
19444
  stringifyParsedExpr,
@@ -19138,6 +19446,7 @@ export {
19138
19446
  resolveSetters,
19139
19447
  resetCompilerCounters,
19140
19448
  renderImportMapHtml,
19449
+ parseRecordIndexAccess,
19141
19450
  parseExpression,
19142
19451
  parseBlockBody,
19143
19452
  needsTypeBasedDetection,
@@ -19169,6 +19478,7 @@ export {
19169
19478
  extractSsrDefaults,
19170
19479
  extractFunctionParams,
19171
19480
  exprToString,
19481
+ evalStringArrayJoin,
19172
19482
  enableCompilerInstrumentation,
19173
19483
  emitParsedExpr,
19174
19484
  emitIRNode,
@@ -19181,6 +19491,7 @@ export {
19181
19491
  containsHigherOrder,
19182
19492
  compileJSX,
19183
19493
  combineParentChildClientJs,
19494
+ collectContextConsumers,
19184
19495
  buildWhyUpdate,
19185
19496
  buildSourceMapFromIR,
19186
19497
  buildMetadata,
@@ -19192,6 +19503,7 @@ export {
19192
19503
  buildComponentSummary,
19193
19504
  buildComponentGraph,
19194
19505
  buildComponentAnalysis,
19506
+ augmentInheritedPropAccesses,
19195
19507
  applyCssLayerPrefix,
19196
19508
  analyzeComponent,
19197
19509
  analyzeClientNeeds,
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-defaults.d.ts","sourceRoot":"","sources":["../src/ssr-defaults.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,KAAK,EAAE,OAAO,CAAA;IACd;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAYD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,SAAS,CAwD/F"}
1
+ {"version":3,"file":"ssr-defaults.d.ts","sourceRoot":"","sources":["../src/ssr-defaults.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,KAAK,EAAE,OAAO,CAAA;IACd;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAYD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,SAAS,CAsE/F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/jsx",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "JSX compiler for BarefootJS - transforms JSX to server HTML + client JS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -53,7 +53,7 @@
53
53
  "directory": "packages/jsx"
54
54
  },
55
55
  "dependencies": {
56
- "@barefootjs/shared": "0.8.0"
56
+ "@barefootjs/shared": "0.9.1"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@barefootjs/client": ">=0.2.0",