Skip to content

Commit

Permalink
CLJS-3401: dedupe '+ and '_PLUS symbols with :optimize-constants (#203)
Browse files Browse the repository at this point in the history
Co-authored-by: Michiel Borkent <michielborkent@gmail.com>
  • Loading branch information
swannodette and borkdude committed Apr 10, 2023
1 parent 30171a3 commit 0ccd19f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,16 @@
(symbol? value) "cst$sym$"
:else
(throw
#?(:clj (Exception. (str "constant type " (type value) " not supported"))
:cljs (js/Error. (str "constant type " (type value) " not supported")))))
#?(:clj (Exception. (str "constant type " (type value) " not supported"))
:cljs (js/Error. (str "constant type " (type value) " not supported")))))
name (if (keyword? value)
(subs (str value) 1)
(str value))
name (if (= "." name)
"_DOT_"
(-> name
(string/replace "_" "__")
(string/replace "$" "$$")
(string/replace "-" "_DASH_")
(munge)
(string/replace "." "$")
Expand Down
6 changes: 6 additions & 0 deletions src/test/clojure/cljs/analyzer_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1512,3 +1512,9 @@
(Foo. nil nil)))))
(is (= 1 (count @ws)))
(is (string/starts-with? (first @ws) "Wrong number of args (2) passed to Foo"))))

(deftest test-cljs-3401
(is (not= (ana/gen-constant-id '_PLUS_)
(ana/gen-constant-id '+)))
(is (not= (ana/gen-constant-id 'foo.bar)
(ana/gen-constant-id 'foo$bar))))

0 comments on commit 0ccd19f

Please sign in to comment.