Skip to content

Commit 790d3a9

Browse files
mfikesswannodette
authored andcommitted
CLJS-1476: Self-host: Protocol prefixing broken for three- (or more) segment namespaces
Fixes protocol-prefix fn (two copies, one in core and one in compiler) for use in self-host. At its core, this function need to take a string like alpha.beta.gamma/IFoo and turn it into alpha$beta$gamma$IFoo$ and it was failing to replace the multiple dot characters when in self-host mode owing to the fact that .replace in JavaScript is not a global replace. This fix adds the "g" flag.
1 parent 6ae18eb commit 790d3a9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/main/clojure/cljs/compiler.cljc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,10 @@
906906
(when (= :expr context) (emits "})()"))))
907907

908908
(defn protocol-prefix [psym]
909-
(symbol (str (-> (str psym) (.replace \. \$) (.replace \/ \$)) "$")))
909+
(symbol (str (-> (str psym)
910+
(.replace #?(:clj \. :cljs (js/RegExp. "\\." "g")) \$)
911+
(.replace \/ \$))
912+
"$")))
910913

911914
(defmethod emit* :invoke
912915
[{:keys [f args env] :as expr}]

src/main/clojure/cljs/core.cljc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,10 @@
11901190
;;; end of reducers macros
11911191

11921192
(core/defn- protocol-prefix [psym]
1193-
(core/str (core/-> (core/str psym) (.replace \. \$) (.replace \/ \$)) "$"))
1193+
(core/str (core/-> (core/str psym)
1194+
(.replace #?(:clj \. :cljs (js/RegExp. "\\." "g")) \$)
1195+
(.replace \/ \$))
1196+
"$"))
11941197

11951198
(def #^:private base-type
11961199
{nil "null"

0 commit comments

Comments
 (0)