HS: as Date/Set/Map return real JS host objects (+4 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 45s

- hs-coerce "Date": new case returns (host-new "Date" value)
- hs-coerce "Set": creates real JS Set via host-new + for-each add (was SX list)
- hs-coerce "Map": creates real JS Map via host-new + for-each set (was SX list)
- hs-make "Set"/"Map": use host-new instead of (list)/(dict)
- hs-add-to!, hs-remove-from!, hs-empty-like, hs-append: handle real JS Sets
- hs-run-filtered.js: add hs-is-set? and hs-is-map? natives
- generator: MANUAL_TEST_BODIES for converts-as-Date (×2), as-Set, as-Map
asExpression suite: 36/42 (was 32/42)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 10:04:51 +00:00
parent e9ddf31181
commit 6a40e991b3
4 changed files with 64 additions and 25 deletions

View File

@@ -470,6 +470,7 @@
(some (fn (x) (= x value)) target)
target
(append target (list value))))
((hs-is-set? target) (do (host-call target "add" value) target))
(true (do (host-call target "push" value) target)))))
;; ── Object creation ─────────────────────────────────────────────
@@ -480,10 +481,10 @@
hs-remove-from!
(fn
(value target)
(if
(list? target)
(filter (fn (x) (not (= x value))) target)
(host-call target "splice" (host-call target "indexOf" value) 1))))
(cond
((list? target) (filter (fn (x) (not (= x value))) target))
((hs-is-set? target) (do (host-call target "delete" value) target))
(true (host-call target "splice" (host-call target "indexOf" value) 1)))))
;; ── Behavior installation ───────────────────────────────────────
@@ -965,6 +966,7 @@
(some (fn (x) (= x value)) target)
target
(append target (list value))))
((hs-is-set? target) (do (host-call target "add" value) target))
((hs-element? target)
(do
(dom-insert-adjacent-html
@@ -1260,22 +1262,24 @@
value)
value))
((= type-name "Set")
(if
(list? value)
(reduce
(fn
(acc x)
(if (some (fn (a) (= a x)) acc) acc (append acc (list x))))
(list)
value)
value))
(let
((s (host-new "Set")))
(do
(when
(list? value)
(for-each (fn (x) (host-call s "add" x)) value))
s)))
((= type-name "Map")
(if
(dict? value)
(let
((ks (if (dict-has? value "_order") (get value "_order") (filter (fn (k) (not (= k "_order"))) (keys value)))))
(map (fn (k) (list k (get value k))) ks))
value))
(let
((m (host-new "Map")))
(do
(when
(dict? value)
(for-each
(fn (k) (host-call m "set" k (get value k)))
(filter (fn (k) (not (= k "_order"))) (keys value))))
m)))
((= type-name "Date") (host-new "Date" value))
(true value))))
(define
@@ -1471,8 +1475,8 @@
(cond
((= type-name "Object") (dict))
((= type-name "Array") (list))
((= type-name "Set") (list))
((= type-name "Map") (dict))
((= type-name "Set") (host-new "Set"))
((= type-name "Map") (host-new "Map"))
(true (dict)))
(apply host-new (cons type-name args)))))))
(define
@@ -1871,6 +1875,8 @@
(cond
((list? v) (list))
((dict? v) (dict))
((hs-is-set? v) (host-new "Set"))
((hs-is-map? v) (host-new "Map"))
((string? v) "")
((nil? v) nil)
(true v))))