Skip to content

Commit 4470993

Browse files
author
dnolen
committed
CLJS-1462: self-host unit tests regressed with CLJS-1457
Fix self hosting regression caused by CLJS-1457. `int` to get character code and `format` is meaningless under ClojureScript
1 parent 5c8a787 commit 4470993

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,21 @@
367367
`(binding [*cljs-warning-handlers* ~handlers]
368368
~@body)))
369369

370+
(defn- repeat-char [c n]
371+
(loop [ret c n n]
372+
(if (pos? n)
373+
(recur (str ret c) (dec n))
374+
ret)))
375+
376+
(defn- hex-format [s pad]
377+
#?(:clj (str "_u" (format (str "%0" pad "x") (int (first s))) "_")
378+
:cljs (let [hex (.toString (.charCodeAt s 0) 16)
379+
len (. hex -length)
380+
hex (if (< len pad)
381+
(str (repeat-char "0" (- pad len)) hex)
382+
hex)]
383+
(str "_u" hex "_"))))
384+
370385
(defn gen-constant-id [value]
371386
(let [prefix (cond
372387
(keyword? value) "cst$kw$"
@@ -384,8 +399,7 @@
384399
(string/replace "-" "_DASH_")
385400
(munge)
386401
(string/replace "." "$")
387-
(string/replace #"(?i)[^a-z0-9$_]"
388-
#(str "_u" (format "%04x" (int (first %))) "_"))))]
402+
(string/replace #"(?i)[^a-z0-9$_]" #(hex-format % 4))))]
389403
(symbol (str prefix name))))
390404

391405
(defn- register-constant!

0 commit comments

Comments
 (0)