js-on-sx: object literal spread {...src}
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s

This commit is contained in:
2026-05-09 23:42:13 +00:00
parent f15a8d8fef
commit 25b30788b4
4 changed files with 70 additions and 8 deletions

View File

@@ -3477,6 +3477,55 @@
(dict-set! obj sk val)
val))))
(define
js-obj-spread!
(fn
(target src)
(cond
((or (= src nil) (js-undefined? src)) target)
((dict? src)
(begin
(for-each
(fn
(k)
(if
(js-key-internal? k)
nil
(js-obj-set! target k (get src k))))
(js-object-keys src))
target))
((= (type-of src) "string")
(let
((n (len src)))
(begin (js-obj-spread-string-loop! target src 0 n) target)))
((list? src)
(let
((n (len src)))
(begin (js-obj-spread-list-loop! target src 0 n) target)))
(else target))))
(define
js-obj-spread-string-loop!
(fn
(target s i n)
(cond
((>= i n) nil)
(else
(begin
(js-obj-set! target (js-to-string i) (char-at s i))
(js-obj-spread-string-loop! target s (+ i 1) n))))))
(define
js-obj-spread-list-loop!
(fn
(target arr i n)
(cond
((>= i n) nil)
(else
(begin
(js-obj-set! target (js-to-string i) (nth arr i))
(js-obj-spread-list-loop! target arr (+ i 1) n))))))
(begin
(define
js-set-prop