js-on-sx: js-add unwraps wrapper objects before string-concat decision
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 20s

This commit is contained in:
2026-05-09 05:25:06 +00:00
parent 41dbac55b8
commit 76d6528c51
2 changed files with 22 additions and 4 deletions

View File

@@ -1957,14 +1957,30 @@
((= (char-at s i) "0") (js-strip-zeros-loop s (+ i 1) n))
(else (js-string-slice s i n)))))
(define
js-add-unwrap
(fn
(v)
(cond
((not (= (type-of v) "dict")) v)
((contains? (keys v) "__js_string_value__")
(get v "__js_string_value__"))
((contains? (keys v) "__js_number_value__")
(get v "__js_number_value__"))
((contains? (keys v) "__js_boolean_value__")
(get v "__js_boolean_value__"))
(else v))))
(define
js-add
(fn
(a b)
(cond
((or (= (type-of a) "string") (= (type-of b) "string"))
(str (js-to-string a) (js-to-string b)))
(else (+ (js-to-number a) (js-to-number b))))))
(let
((ap (js-add-unwrap a)) (bp (js-add-unwrap b)))
(cond
((or (= (type-of ap) "string") (= (type-of bp) "string"))
(str (js-to-string ap) (js-to-string bp)))
(else (+ (js-to-number ap) (js-to-number bp)))))))
(define js-sub (fn (a b) (- (js-to-number a) (js-to-number b))))