Skip to content

Commit 3f2c52a

Browse files
committed
fix demunge, add test
add cljs.js/file->ns
1 parent 9cdab40 commit 3f2c52a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9898,7 +9898,8 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
98989898
(defn- demunge-str [munged-name]
98999899
(let [r (js/RegExp. (demunge-pattern) "g")
99009900
munged-name (if (gstring/endsWith munged-name "$")
9901-
(.substring munged-name 0 (dec (. munged-name -length))))]
9901+
(.substring munged-name 0 (dec (. munged-name -length)))
9902+
munged-name)]
99029903
(loop [ret "" last-match-end 0]
99039904
(if-let [match (.exec r munged-name)]
99049905
(let [[x] match]

src/main/cljs/cljs/js.cljs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
[ns-sym]
3333
(string/replace (ana/munge-path ns-sym) \. \/))
3434

35+
(defn file->ns
36+
[file]
37+
(let [lib-name (subs (string/replace file "/" ".")
38+
0 (- (count file) 5))]
39+
(symbol (demunge lib-name))))
40+
3541
(defn atom? [x]
3642
(instance? Atom x))
3743

src/test/cljs/cljs/core_test.cljs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,6 +2875,10 @@
28752875
arguments)))
28762876
[])))
28772877

2878+
(deftest test-munge-demunge
2879+
(is (= 'cljs.core/first?
2880+
(demunge (munge 'cljs.core/first?)))))
2881+
28782882
(comment
28792883
;; ObjMap
28802884
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)