From 42184797f1f3e8b2aea9c98c85cf788ee4f7f3ee Mon Sep 17 00:00:00 2001 From: giles Date: Mon, 4 May 2026 18:33:12 +0000 Subject: [PATCH] HS: fix repeat-in loop variable binding + dict insertion order (+4 tests) Two fixes: (1) compiler.sx: remove `it` from hs-reserved-var?. `it` is the standard HS loop variable for `repeat in` loops; renaming it to `_hs_lv_it` made the body reference the outer (nil) `it` rather than the bound element. Other reserved vars (meta, event, result) still get renamed to prevent shadowing built-ins in misnamed loops. (2) runtime.sx: hs-make-object now appends an `_order` list tracking insertion order, mirroring the pattern used by other dict-building paths. Without this, `for prop in obj` fell back to `(keys obj)` which gives non-deterministic key order for objects with string keys. Co-Authored-By: Claude Sonnet 4.6 --- lib/hyperscript/compiler.sx | 8 +------- lib/hyperscript/runtime.sx | 11 ++++++++++- shared/static/wasm/sx/hs-compiler.sx | 8 +------- shared/static/wasm/sx/hs-runtime.sx | 11 ++++++++++- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index 603865d5..f09c3f04 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -463,13 +463,7 @@ (list (quote fn) (list) body))))))) (define hs-reserved-var? - (fn - (name) - (or - (= name "meta") - (= name "event") - (= name "it") - (= name "result")))) + (fn (name) (or (= name "meta") (= name "event") (= name "result")))) (define emit-for (fn diff --git a/lib/hyperscript/runtime.sx b/lib/hyperscript/runtime.sx index 0f88fadb..e6557dae 100644 --- a/lib/hyperscript/runtime.sx +++ b/lib/hyperscript/runtime.sx @@ -2330,7 +2330,16 @@ ((d {})) (do (for-each - (fn (pair) (dict-set! d (first pair) (nth pair 1))) + (fn + (pair) + (let + ((name (first pair))) + (do + (dict-set! d name (nth pair 1)) + (dict-set! + d + "_order" + (append (or (get d "_order") (list)) (list name)))))) pairs) d)))) diff --git a/shared/static/wasm/sx/hs-compiler.sx b/shared/static/wasm/sx/hs-compiler.sx index 603865d5..f09c3f04 100644 --- a/shared/static/wasm/sx/hs-compiler.sx +++ b/shared/static/wasm/sx/hs-compiler.sx @@ -463,13 +463,7 @@ (list (quote fn) (list) body))))))) (define hs-reserved-var? - (fn - (name) - (or - (= name "meta") - (= name "event") - (= name "it") - (= name "result")))) + (fn (name) (or (= name "meta") (= name "event") (= name "result")))) (define emit-for (fn diff --git a/shared/static/wasm/sx/hs-runtime.sx b/shared/static/wasm/sx/hs-runtime.sx index 0f88fadb..e6557dae 100644 --- a/shared/static/wasm/sx/hs-runtime.sx +++ b/shared/static/wasm/sx/hs-runtime.sx @@ -2330,7 +2330,16 @@ ((d {})) (do (for-each - (fn (pair) (dict-set! d (first pair) (nth pair 1))) + (fn + (pair) + (let + ((name (first pair))) + (do + (dict-set! d name (nth pair 1)) + (dict-set! + d + "_order" + (append (or (get d "_order") (list)) (list name)))))) pairs) d))))