Skip to content

Commit 2b8d5ae

Browse files
mfikesdnolen
authored andcommitted
CLJS-2585: Bad code gen for and / or expressions
1 parent 07ba758 commit 2b8d5ae

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/main/clojure/cljs/core.cljc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@
855855
(map #(cljs.analyzer/no-warn (cljs.analyzer/analyze &env %)) forms))
856856
(core/let [and-str (core/->> (repeat (count forms) "(~{})")
857857
(interpose " && ")
858+
(#(concat ["("] % [")"]))
858859
(apply core/str))]
859860
(bool-expr `(~'js* ~and-str ~@forms)))
860861
`(let [and# ~x]
@@ -873,6 +874,7 @@
873874
(map #(cljs.analyzer/no-warn (cljs.analyzer/analyze &env %)) forms))
874875
(core/let [or-str (core/->> (repeat (count forms) "(~{})")
875876
(interpose " || ")
877+
(#(concat ["("] % [")"]))
876878
(apply core/str))]
877879
(bool-expr `(~'js* ~or-str ~@forms)))
878880
`(let [or# ~x]

src/test/cljs/cljs/core_test.cljs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,18 @@
15251525
(deftest test-cljs-2552
15261526
(is (boolean? (tap> nil))))
15271527

1528+
;; Delete a bogus property from the beta? fn
1529+
;; Without the fix this js-delete form code-gens to code that deletes the alpha? fn:
1530+
;; delete (cljs.core_test.alpha_2585_QMARK_) && (cljs.core_test.beta_2585_QMARK_)["bogus-property"]
1531+
(defn ^boolean alpha-2585? [] true)
1532+
(defn ^boolean beta-2585? [] true)
1533+
(js-delete (and alpha-2585? beta-2585?) "bogus-property")
1534+
1535+
(deftest test-cljs-2585
1536+
(is (= true ((or int? string?) 1)))
1537+
;; Make sure we didn't delete the alpha? fn
1538+
(is (some? alpha-2585?)))
1539+
15281540
(comment
15291541
;; ObjMap
15301542
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)