Compare commits

...

1 Commits

Author SHA1 Message Date
Andrey Antukh
9c0286d13d 🐛 Fix incorrect handling of schema expression on obj/reify 2026-01-26 20:04:10 +01:00

View File

@@ -225,118 +225,83 @@
get-expr)]) get-expr)])
(when set-expr (when set-expr
(concat [schema-sym schema-n
(when (and schema-n (not (list? schema-n)))
[coercer-sym `(sm/coercer ~schema-n)])
(when (and schema-n (list? schema-n)) coercer-sym `(if (and (some? ~schema-sym)
[schema-sym schema-n]) (not (fn? ~schema-sym)))
(sm/coercer ~schema-sym)
nil)
[decode-sym decode-expr] decode-sym decode-expr
[(make-sym pname "set-fn") (make-sym pname "set-fn")
(if this? `(fn [~val-sym]
`(fn [~val-sym] (let [~this-sym (~'js* "this")
(let [~@(if (and schema-n (list? schema-n)) ~fn-sym ~set-expr
[schema-sym `(~schema-sym ~val-sym)
coercer-sym `(sm/coercer ~schema-sym)] ;; We only emit schema and coercer bindings if
[]) ;; schema-n is provided
~this-sym (~'js* "this") ~@(if (some? schema-n)
~fn-sym ~set-expr [schema-sym `(if (fn? ~schema-sym)
~val-sym ~(if schema-n (~schema-sym ~val-sym)
(if decode-expr ~schema-sym)
`(~decode-sym ~val-sym)
`(~decode-sym ~val-sym ~decode-options)) coercer-sym `(if (nil? ~coercer-sym)
val-sym) (sm/coercer ~schema-sym)
~val-sym ~(if schema-n ~coercer-sym)
`(~coercer-sym ~val-sym) val-sym (if (not= decode-expr 'app.common.json/->clj)
val-sym)] `(~decode-sym ~val-sym)
(.call ~fn-sym ~this-sym ~this-sym ~val-sym))) `(~decode-sym ~val-sym ~decode-options))
`(fn [~val-sym] val-sym `(~coercer-sym ~val-sym)]
(let [~@(if (and schema-n (list? schema-n)) [])]
[schema-sym `(~schema-sym ~val-sym)
coercer-sym `(sm/coercer ~schema-sym)] ~(if this?
[]) `(.call ~fn-sym ~this-sym ~this-sym ~val-sym)
~this-sym (~'js* "this") `(.call ~fn-sym ~this-sym ~val-sym))))])
~fn-sym ~set-expr
~val-sym ~(if schema-n
(if decode-expr
`(~decode-sym ~val-sym)
`(~decode-sym ~val-sym ~decode-options))
val-sym)
~val-sym ~(if schema-n
`(~coercer-sym ~val-sym)
val-sym)]
(.call ~fn-sym ~this-sym ~val-sym))))]))
(when fn-expr (when fn-expr
(concat [schema-sym (or schema-n schema-1)
(cond coercer-sym `(if (and (some? ~schema-sym)
(and schema-n (not (list? schema-n))) (not (fn? ~schema-sym)))
[coercer-sym `(sm/coercer ~schema-n)] (sm/coercer ~schema-sym)
nil)
decode-sym decode-expr
(and schema-n (list? schema-n)) (make-sym pname "get-fn")
[schema-sym schema-n] `(fn []
(let [~this-sym (~'js* "this")
~fn-sym ~fn-expr
~fn-sym ~(if this?
`(.bind ~fn-sym ~this-sym ~this-sym)
`(.bind ~fn-sym ~this-sym))
(and schema-1 (not (list? schema-1))) ;; We only emit schema and coercer bindings if
[coercer-sym `(sm/coercer ~schema-1)] ;; schema-n or schema-1 is provided
~@(if (or schema-n schema-1)
[fn-sym `(fn* [~@(if schema-1 [val-sym] [])]
(let [~@(if schema-n
[val-sym `(into-array (cljs.core/js-arguments))]
[])
~val-sym ~(if (not= decode-expr 'app.common.json/->clj)
`(~decode-sym ~val-sym)
`(~decode-sym ~val-sym ~decode-options))
(and schema-1 (list? schema-1)) ~schema-sym (if (fn? ~schema-sym)
[schema-sym schema-1]) (~schema-sym ~val-sym)
~schema-sym)
[decode-sym decode-expr] ~coercer-sym (if (nil? ~coercer-sym)
(sm/coercer ~schema-sym)
~coercer-sym)
[(make-sym pname "get-fn") ~val-sym (~coercer-sym ~val-sym)]
`(fn [] ~(if schema-1
(let [~this-sym (~'js* "this") `(~fn-sym ~val-sym)
~fn-sym ~fn-expr `(apply ~fn-sym ~val-sym))))]
~fn-sym ~(if this? [])]
`(.bind ~fn-sym ~this-sym ~this-sym) ~(if wrap
`(.bind ~fn-sym ~this-sym)) `(~wrap-sym ~fn-sym)
fn-sym)))]))))))]
~@(if schema-1
[fn-sym `(fn* [~val-sym]
(let [~val-sym
~(if decode-expr
`(~decode-sym ~val-sym)
`(~decode-sym ~val-sym ~decode-options))
~@(if (or (and schema-n (list? schema-n))
(and schema-1 (list? schema-1)))
[schema-sym `(~schema-sym ~val-sym)
coercer-sym `(sm/coercer ~schema-sym)]
[])
~val-sym
(~coercer-sym ~val-sym)]
(~fn-sym ~val-sym)))]
[])
~@(if schema-n
[fn-sym `(fn* []
(let [~val-sym
(into-array (cljs.core/js-arguments))
~val-sym
~(if decode-expr
`(~decode-sym ~val-sym)
`(~decode-sym ~val-sym ~decode-options))
~@(if (or (and schema-n (list? schema-n))
(and schema-1 (list? schema-1)))
[schema-sym `(~schema-sym ~val-sym)
coercer-sym `(sm/coercer ~schema-sym)]
[])
~val-sym
(~coercer-sym ~val-sym)]
(apply ~fn-sym ~val-sym)))]
[])
~@(if wrap
[fn-sym `(~wrap-sym ~fn-sym)]
[])]
~fn-sym))])))))))]
`(let [~target-sym ~rsym `(let [~target-sym ~rsym
~@bindings] ~@bindings]