File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -11887,7 +11887,9 @@ reduces them without incurring seq initialization"
11887
11887
(str_ ret " |\\ $" ))))))
11888
11888
DEMUNGE_PATTERN )
11889
11889
11890
- (defn- ^string munge-str [name]
11890
+ (defn ^string munge-str
11891
+ " Munge string `name` without considering `..` or JavaScript reserved keywords."
11892
+ [name]
11891
11893
(let [sb (StringBuffer. )]
11892
11894
(loop [i 0 ]
11893
11895
(if (< i (. name -length))
@@ -11899,7 +11901,13 @@ reduces them without incurring seq initialization"
11899
11901
(recur (inc i)))))
11900
11902
(.toString sb)))
11901
11903
11902
- (defn munge [name]
11904
+ (defn munge
11905
+ " Munge symbol or string `name` for safe use in JavaScript.
11906
+
11907
+ - Replaces '..' with '_DOT__DOT_'.
11908
+ - Appends '$' to JavaScript reserved keywords.
11909
+ - Returns a symbol if `name` was a symbol, otherwise a string."
11910
+ [name]
11903
11911
(let [name' (munge-str (str_ name))
11904
11912
name' (cond
11905
11913
(identical? name' " .." ) " _DOT__DOT_"
Original file line number Diff line number Diff line change 142
142
ss (map rf (string/split ss #"\. " ))
143
143
ss (string/join " ." ss)
144
144
ms #?(:clj (clojure.lang.Compiler/munge ss)
145
- :cljs (#'cljs.core/ munge-str ss))]
145
+ :cljs (munge-str ss))]
146
146
(if (symbol? s)
147
147
(symbol ms)
148
148
ms)))))
Original file line number Diff line number Diff line change 1136
1136
(is (= " _DOT__DOT_" (munge " .." )))
1137
1137
(is (= " abstract$" (munge " abstract" )))
1138
1138
(is (= 'abc (munge 'abc)))
1139
- (is (= " toString" (munge " toString" ))))
1139
+ (is (= " toString" (munge " toString" )))
1140
+ (is (= " function$" (munge " function" ))))
1141
+
1142
+ (deftest test-munge-str
1143
+ (is (= " function" (munge-str " function" ))))
1140
1144
1141
1145
(defprotocol IFooBar
1142
1146
(a-method [t]))
1952
1956
(is (= " 12" (apply cljs.core/str_ 1 [2 ])))
1953
1957
(is (= " 1two:threefour#{:five}[:six]#{:seven}{:eight :nine}"
1954
1958
(apply cljs.core/str_ 1 [" two" :three 'four #{:five } [:six ] #{:seven } {:eight :nine }])))
1955
- (is (= " 1234" (apply cljs.core/str_ 1 2 [3 4 ]))))
1959
+ (is (= " 1234" (apply cljs.core/str_ 1 2 [3 4 ]))))
You can’t perform that action at this time.
0 commit comments