Skip to content

Commit f5af28f

Browse files
committed
CLJS-2323: Wrong return value for data readers with records
add analyzer-record case to analyzer. add emission for record values. still need to finish test case
1 parent a62747d commit f5af28f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,6 +3406,25 @@
34063406
:children items
34073407
:tag (if (map? val) 'object 'array)}))
34083408

3409+
(defn analyze-record
3410+
[env x]
3411+
(let [items (disallowing-recur
3412+
(analyze (assoc env :context :expr) (into {} x)))
3413+
[ns name] (map symbol
3414+
#?(:clj
3415+
((juxt (comp #(string/join "." %) butlast) last)
3416+
(string/split (.getName ^Class (type x)) #"\."))
3417+
:cljs
3418+
(string/split (pr-str (type x)) #"/")))]
3419+
{:op :record-value
3420+
:ns ns
3421+
:name name
3422+
:env env
3423+
:form x
3424+
:items items
3425+
:children [items]
3426+
:tag name}))
3427+
34093428
(defn elide-reader-meta [m]
34103429
(dissoc m :file :line :column :end-column :end-line :source))
34113430

@@ -3509,6 +3528,7 @@
35093528
(cond
35103529
(symbol? form) (analyze-symbol env form)
35113530
(and (seq? form) (seq form)) (analyze-seq env form name opts)
3531+
(record? form) (analyze-record env form)
35123532
(map? form) (analyze-map env form)
35133533
(vector? form) (analyze-vector env form)
35143534
(set? form) (analyze-set env form)
@@ -3530,6 +3550,7 @@
35303550
(cond
35313551
(symbol? form) (analyze-symbol env form)
35323552
(and (cljs-seq? form) (some? (seq form))) (analyze-seq env form name opts)
3553+
(record? form) (analyze-record env form)
35333554
(cljs-map? form) (analyze-map env form)
35343555
(cljs-vector? form) (analyze-vector env form)
35353556
(cljs-set? form) (analyze-set env form)

src/main/clojure/cljs/compiler.cljc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@
460460
(emits "})"))
461461
(emits "[" (comma-sep items) "]"))))
462462

463+
(defmethod emit* :record-value
464+
[{:keys [items ns name items env]}]
465+
(emit-wrap env
466+
(emits ns ".map__GT_" name "(" items ")")))
467+
463468
(defmethod emit* :constant
464469
[{:keys [form env]}]
465470
(when-not (= :statement (:context env))

src/test/clojure/cljs/build_api_tests.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,17 @@
398398
(build/build (build/inputs (io/file inputs "data_readers_test")) opts cenv)
399399
(is (contains? (-> @cenv ::ana/data-readers) 'test/custom-identity))))
400400

401+
(comment
402+
(let [out "out"
403+
{:keys [inputs opts]} {:inputs (str (io/file "src" "test" "cljs"))
404+
:opts {:main 'data-readers-test.records
405+
:output-dir out
406+
:optimizations :none
407+
:closure-warnings {:check-types :off}}}
408+
cenv (env/default-compiler-env)]
409+
(build/build (build/inputs (io/file inputs "data_readers_test")) opts cenv))
410+
)
411+
401412
(deftest test-cljs-2249
402413
(let [out (io/file (test/tmp-dir) "cljs-2249-out")
403414
root (io/file "src" "test" "cljs_build")

0 commit comments

Comments
 (0)