Skip to content

Commit 2046dc8

Browse files
mfikesswannodette
authored andcommitted
CLJS-2278: JavaScript object literals are printed wth keys that cannot be read
1 parent 190fa64 commit 2046dc8

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9635,7 +9635,9 @@ reduces them without incurring seq initialization"
96359635
(do
96369636
(-write writer "#js ")
96379637
(print-map
9638-
(map (fn [k] [(keyword k) (unchecked-get obj k)]) (js-keys obj))
9638+
(map (fn [k]
9639+
[(cond-> k (some? (re-matches #"[A-Za-z][\w\*\+\?!\-']*" k)) keyword) (unchecked-get obj k)])
9640+
(js-keys obj))
96399641
pr-writer writer opts))
96409642

96419643
(array? obj)

src/test/cljs/cljs/core_test.cljs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,11 +1413,12 @@
14131413
(is (contains? (ns-imports 'clojure.string) 'StringBuffer))
14141414
(is (= (find (ns-imports 'clojure.string) 'StringBuffer)
14151415
['StringBuffer goog.string.StringBuffer]))))
1416+
14161417
(deftest test-cljs-2190
14171418
(binding [*print-namespace-maps* true]
14181419
(testing "printing a javascript map with a slash on keyword"
1419-
(is (= "#js {:foo/bar 33}" (pr-str (doto (js-obj) (gobject/set "foo/bar" 33)))))
1420-
(is (= "#js {:foo/bar #:var{:quux 66}}" (pr-str (doto (js-obj) (gobject/set "foo/bar" {:var/quux 66}))))))))
1420+
(is (= "#js {\"foo/bar\" 33}" (pr-str (doto (js-obj) (gobject/set "foo/bar" 33)))))
1421+
(is (= "#js {\"foo/bar\" #:var{:quux 66}}" (pr-str (doto (js-obj) (gobject/set "foo/bar" {:var/quux 66}))))))))
14211422

14221423
(def ^:const true-2267 true)
14231424
(def ^:const false-2267 false)
@@ -1436,6 +1437,13 @@
14361437
(is (= :then (if zero-2267 :then :else)))
14371438
(is (= :then (if non-zero-2267 :then :else))))
14381439

1440+
(deftest test-cljs-2278
1441+
(is (= "#js {:alpha 1, \"beta gamma\" 2, \"delta/epsilon\" 3}" (pr-str #js {"alpha" 1 "beta gamma" 2 "delta/epsilon" 3})))
1442+
(is (= "#js {\":abc\" 1}" (pr-str #js {":abc" 1})))
1443+
(is (= "#js {\"0abc\" 1}" (pr-str #js {"0abc" 1})))
1444+
(is (= "#js {:abc-def 1}" (pr-str #js {"abc-def" 1})))
1445+
(is (= "#js {:x*+?!-' 1}" (pr-str #js {"x*+?!-'" 1}))))
1446+
14391447
(comment
14401448
;; ObjMap
14411449
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)