|
235 | 235 | (declare emit-map emit-list emit-vector emit-set emit-js-object emit-js-array
|
236 | 236 | emit-with-meta emit-constants-comma-sep emit-constant)
|
237 | 237 |
|
| 238 | +(defn all-distinct? [xs] |
| 239 | + (apply distinct? xs)) |
| 240 | + |
238 | 241 | #?(:clj
|
239 | 242 | (defn emit-constant-no-meta [x]
|
240 | 243 | (cond
|
241 | 244 | (seq? x) (emit-list x emit-constants-comma-sep)
|
242 |
| - (map? x) (emit-map (keys x) (vals x) emit-constants-comma-sep #(apply distinct? %)) |
| 245 | + (map? x) (emit-map (keys x) (vals x) emit-constants-comma-sep all-distinct?) |
243 | 246 | (vector? x) (emit-vector x emit-constants-comma-sep)
|
244 |
| - (set? x) (emit-set x emit-constants-comma-sep) |
| 247 | + (set? x) (emit-set x emit-constants-comma-sep all-distinct?) |
245 | 248 | :else (emit-constant* x)))
|
246 | 249 | :cljs
|
247 | 250 | (defn emit-constant-no-meta [x]
|
248 | 251 | (cond
|
249 | 252 | (ana/cljs-seq? x) (emit-list x emit-constants-comma-sep)
|
250 |
| - (ana/cljs-map? x) (emit-map (keys x) (vals x) emit-constants-comma-sep #(apply distinct? %)) |
| 253 | + (ana/cljs-map? x) (emit-map (keys x) (vals x) emit-constants-comma-sep all-distinct?) |
251 | 254 | (ana/cljs-vector? x) (emit-vector x emit-constants-comma-sep)
|
252 |
| - (ana/cljs-set? x) (emit-set x emit-constants-comma-sep) |
| 255 | + (ana/cljs-set? x) (emit-set x emit-constants-comma-sep all-distinct?) |
253 | 256 | :else (emit-constant* x))))
|
254 | 257 |
|
255 | 258 | (defn emit-constant [v]
|
|
513 | 516 | (and (every? #(= (:op %) :const) items)
|
514 | 517 | (= (count (into #{} items)) (count items)))))
|
515 | 518 |
|
516 |
| -(defn emit-set [items comma-sep] |
| 519 | +(defn emit-set [items comma-sep distinct-constants?] |
517 | 520 | (cond
|
518 | 521 | (empty? items)
|
519 | 522 | (emits "cljs.core.PersistentHashSet.EMPTY")
|
|
527 | 530 | (defmethod emit* :set
|
528 | 531 | [{:keys [items env]}]
|
529 | 532 | (emit-wrap env
|
530 |
| - (cond |
531 |
| - (empty? items) |
532 |
| - (emits "cljs.core.PersistentHashSet.EMPTY") |
533 |
| - |
534 |
| - (distinct-constants? items) |
535 |
| - (emits "new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, " (count items) ", [" |
536 |
| - (comma-sep (interleave items (repeat "null"))) "], null), null)") |
537 |
| - |
538 |
| - :else (emits "cljs.core.PersistentHashSet.createAsIfByAssoc([" (comma-sep items) "])")))) |
| 533 | + (emit-set items comma-sep distinct-constants?))) |
539 | 534 |
|
540 | 535 | (defn emit-js-object [items emit-js-object-val]
|
541 | 536 | (emits "({")
|
|
0 commit comments