Fix component-source SSR override, add SX island tests

component-source from data/helpers.sx was overriding the native
OCaml version. The SX version calls env-get with wrong arity (1 arg
vs required 2), producing empty source. Re-bind the native version
in SSR overrides after file loading.

Note: source code still not visible because highlight function
returns empty — separate issue in the aser rendering pipeline.

Also adds:
- spec/tests/test-reactive-islands.sx — 22 SX-native tests for all
  14 reactive island demos (render + signal logic + DOM)
- tests/node/run-sx-tests.js — Node runner for SX test files
- tests/node/test-reactive-islands.js — 39 Node/happy-dom tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-31 17:44:11 +00:00
parent 9742d0236e
commit 28273eb740
4 changed files with 562 additions and 0 deletions

View File

@@ -2140,6 +2140,31 @@ let http_mode port =
let bind name fn = ignore (env_bind env name (NativeFn (name, fn))) in
bind "effect" (fun _args -> Nil);
bind "register-in-scope" (fun _args -> Nil);
(* Re-bind component-source — data/helpers.sx overrides the native version
with an SX version that calls env-get with wrong arity. Native version
uses env_get directly and handles pretty-printing in OCaml. *)
bind "component-source" (fun args ->
match args with
| [String name] ->
let lookup = if String.length name > 0 && name.[0] = '~'
then name
else "~" ^ name in
(try
let comp = env_get env lookup in
match comp with
| Component c ->
let params = List (List.map (fun s -> Symbol s) c.c_params) in
let form = List [Symbol "defcomp"; Symbol ("~" ^ c.c_name);
params; c.c_body] in
String (pretty_print_value form)
| Island c ->
let params = List (List.map (fun s -> Symbol s) c.i_params) in
let form = List [Symbol "defisland"; Symbol ("~" ^ c.i_name);
params; c.i_body] in
String (pretty_print_value form)
| _ -> String (";; " ^ name ^ ": not a component")
with _ -> String (";; component " ^ name ^ " not found"))
| _ -> raise (Eval_error "component-source: expected (name)"));
let jt0 = Unix.gettimeofday () in
let count = ref 0 in
let compiler_names = [