js-on-sx: object literal spread {...src}
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s
This commit is contained in:
@@ -620,6 +620,10 @@
|
||||
(append!
|
||||
kvs
|
||||
{:value (jp-parse-assignment st) :computed-key key-expr :key ""}))))
|
||||
((and (= (get t :type) "punct") (= (get t :value) "..."))
|
||||
(do
|
||||
(jp-advance! st)
|
||||
(append! kvs {:spread (jp-parse-assignment st)})))
|
||||
(else (error (str "Unexpected in object: " (get t :type))))))))
|
||||
|
||||
(define
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -482,14 +482,21 @@
|
||||
(map
|
||||
(fn
|
||||
(entry)
|
||||
(list
|
||||
(js-sym "js-obj-set!")
|
||||
(js-sym "_obj")
|
||||
(if
|
||||
(contains? (keys entry) :computed-key)
|
||||
(list (js-sym "js-to-string") (js-transpile (get entry :computed-key)))
|
||||
(get entry :key))
|
||||
(js-transpile (get entry :value))))
|
||||
(cond
|
||||
((contains? (keys entry) :spread)
|
||||
(list
|
||||
(js-sym "js-obj-spread!")
|
||||
(js-sym "_obj")
|
||||
(js-transpile (get entry :spread))))
|
||||
(else
|
||||
(list
|
||||
(js-sym "js-obj-set!")
|
||||
(js-sym "_obj")
|
||||
(if
|
||||
(contains? (keys entry) :computed-key)
|
||||
(list (js-sym "js-to-string") (js-transpile (get entry :computed-key)))
|
||||
(get entry :key))
|
||||
(js-transpile (get entry :value))))))
|
||||
entries)
|
||||
(list (js-sym "_obj")))))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user