Skip to content

Commit

Permalink
Don't make style names that start with -
Browse files Browse the repository at this point in the history
Can happen under advanced compilation if the fn's name starts with _
  • Loading branch information
dhleong committed Sep 28, 2019
1 parent bc12c0d commit 9d64aec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/spade/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
(defn factory->name [factory]
(-> (.-name factory)
(str/replace "_factory$" "")
(str/replace #"[_$]" "-")))
(str/replace #"[_$]" "-")
(str/replace #"^-" "_")))

(defn sanitize [s]
(-> s
Expand Down
5 changes: 3 additions & 2 deletions test/spade/runner.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns spade.runner
(:require [doo.runner :refer-macros [doo-tests doo-all-tests]]
[spade.core-test]))
(:require [doo.runner :refer-macros [doo-all-tests]]
[spade.core-test]
[spade.util-test]))

(doo-all-tests #"spade\..*-test")
11 changes: 11 additions & 0 deletions test/spade/util_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns spade.util-test
(:require [cljs.test :refer-macros [deftest testing is]]
[spade.util :refer [factory->name]]))

(deftest factory->name-test
(testing "Never prefix with illegal characters"
; simulate a fn under advanced compilation having
; a name that starts with _
(is (= "_advanced-compile"
(factory->name #js {:name "_advanced_compile"})))))

0 comments on commit 9d64aec

Please sign in to comment.