File tree Expand file tree Collapse file tree 3 files changed +42
-18
lines changed
test/cljs/data_readers_test Expand file tree Collapse file tree 3 files changed +42
-18
lines changed Original file line number Diff line number Diff line change 3572
3572
:children [:items ]
3573
3573
:tag 'array}))))
3574
3574
3575
+ (defn record-ns+name [x]
3576
+ (map symbol
3577
+ #?(:clj
3578
+ ((juxt (comp #(string/join " ." %) butlast) last)
3579
+ (string/split (.getName ^Class (type x)) #"\. " ))
3580
+ :cljs
3581
+ (string/split (pr-str (type x)) #"/" ))))
3582
+
3575
3583
(defn analyze-record
3576
3584
[env x]
3577
- (let [items (disallowing-recur
3585
+ (let [; ; register constansts
3586
+ _items_ (disallowing-recur
3578
3587
(analyze (assoc env :context :expr ) (into {} x)))
3579
- [ns name] (map symbol
3580
- #?(:clj
3581
- ((juxt (comp #(string/join " ." %) butlast) last)
3582
- (string/split (.getName ^Class (type x)) #"\. " ))
3583
- :cljs
3584
- (string/split (pr-str (type x)) #"/" )))]
3585
- {:op :record-value
3586
- :ns ns
3587
- :name name
3588
+ [ns name] (record-ns+name x)]
3589
+ {:op :const
3590
+ :val x
3588
3591
:env env
3589
3592
:form x
3590
- :items items
3591
- :children [:items ]
3592
3593
:tag (symbol (str ns ) (str name))}))
3593
3594
3594
3595
(defn elide-reader-meta [m]
Original file line number Diff line number Diff line change 233
233
(defmulti emit-constant* type ))
234
234
235
235
(declare emit-map emit-list emit-vector emit-set emit-js-object emit-js-array
236
- emit-with-meta emit-constants-comma-sep emit-constant )
236
+ emit-with-meta emit-constants-comma-sep emit-constant emit-record-value )
237
237
238
238
(defn all-distinct? [xs]
239
239
(apply distinct? xs))
242
242
(defn emit-constant-no-meta [x]
243
243
(cond
244
244
(seq? x) (emit-list x emit-constants-comma-sep)
245
+ (record? x) (let [[ns name] (ana/record-ns+name x)]
246
+ (emit-record-value ns name #(emit-constant (into {} x))))
245
247
(map? x) (emit-map (keys x) (vals x) emit-constants-comma-sep all-distinct?)
246
248
(vector? x) (emit-vector x emit-constants-comma-sep)
247
249
(set? x) (emit-set x emit-constants-comma-sep all-distinct?)
250
252
(defn emit-constant-no-meta [x]
251
253
(cond
252
254
(ana/cljs-seq? x) (emit-list x emit-constants-comma-sep)
255
+ (record? x) (let [[ns name] (ana/record-ns+name x)]
256
+ (emit-record-value ns name #(emit-constant (into {} x))))
253
257
(ana/cljs-map? x) (emit-map (keys x) (vals x) emit-constants-comma-sep all-distinct?)
254
258
(ana/cljs-vector? x) (emit-vector x emit-constants-comma-sep)
255
259
(ana/cljs-set? x) (emit-set x emit-constants-comma-sep all-distinct?)
554
558
(emit-wrap env
555
559
(emit-js-array items comma-sep)))
556
560
557
- (defmethod emit* :record-value
558
- [{:keys [items ns name items env]}]
559
- (emit-wrap env
560
- (emits ns " .map__GT_" name " (" items " )" )))
561
+ (defn emit-record-value
562
+ [ns name items]
563
+ (emits ns " .map__GT_" name " (" items " )" ))
561
564
562
565
(defmethod emit* :quote
563
566
[{:keys [expr]}]
Original file line number Diff line number Diff line change 3
3
4
4
(defrecord Foo [a b])
5
5
6
- (assert (= (Foo. 1 2 ) #data_readers_test.records.Foo{:a 1 :b 2 }))
6
+ (assert (= (Foo. 1 2 ) #data_readers_test.records.Foo{:a 1 :b 2 }))
7
+ (assert (= (Foo. 1 2 )
8
+ '#data_readers_test.records.Foo{:a 1 :b 2 }))
9
+ (assert (= (Foo. 1 2 )
10
+ (second ''#data_readers_test.records.Foo{:a 1 :b 2 })))
11
+ (assert (= (Foo. 'a 'b)
12
+ (let [a 1
13
+ b 2 ]
14
+ #data_readers_test.records.Foo{:a a :b b}))
15
+ (pr-str
16
+ (let [a 1
17
+ b 2 ]
18
+ #data_readers_test.records.Foo{:a a :b b})))
19
+ (assert (= (Foo. 'a 'b)
20
+ (let [a 1
21
+ b 2 ]
22
+ '#data_readers_test.records.Foo{:a a :b b}))
23
+ (pr-str
24
+ (let [a 1
25
+ b 2 ]
26
+ '#data_readers_test.records.Foo{:a a :b b})))
You can’t perform that action at this time.
0 commit comments