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"
1188711887 (str_ ret " |\\ $" ))))))
1188811888 DEMUNGE_PATTERN )
1188911889
11890- (defn- ^string munge-str [name]
11890+ (defn ^string munge-str
11891+ " Munge string `name` without considering `..` or JavaScript reserved keywords."
11892+ [name]
1189111893 (let [sb (StringBuffer. )]
1189211894 (loop [i 0 ]
1189311895 (if (< i (. name -length))
@@ -11899,7 +11901,13 @@ reduces them without incurring seq initialization"
1189911901 (recur (inc i)))))
1190011902 (.toString sb)))
1190111903
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]
1190311911 (let [name' (munge-str (str_ name))
1190411912 name' (cond
1190511913 (identical? name' " .." ) " _DOT__DOT_"
Original file line number Diff line number Diff line change 142142 ss (map rf (string/split ss #"\. " ))
143143 ss (string/join " ." ss)
144144 ms #?(:clj (clojure.lang.Compiler/munge ss)
145- :cljs (#'cljs.core/ munge-str ss))]
145+ :cljs (munge-str ss))]
146146 (if (symbol? s)
147147 (symbol ms)
148148 ms)))))
Original file line number Diff line number Diff line change 11361136 (is (= " _DOT__DOT_" (munge " .." )))
11371137 (is (= " abstract$" (munge " abstract" )))
11381138 (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" ))))
11401144
11411145(defprotocol IFooBar
11421146 (a-method [t]))
19521956 (is (= " 12" (apply cljs.core/str_ 1 [2 ])))
19531957 (is (= " 1two:threefour#{:five}[:six]#{:seven}{:eight :nine}"
19541958 (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