Skip to content

Commit

Permalink
tap warning on compile ambig attrs; added some wonky tests for attrs …
Browse files Browse the repository at this point in the history
…reflection
  • Loading branch information
onionpancakes committed Feb 19, 2024
1 parent bf24b78 commit 6247fe1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/dev/onionpancakes/chassis/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@
(compilable-alias-element-children-attrs-present elem))
(if (attrs-absent? elem)
(compilable-alias-element-children-attrs-absent elem)
(compilable-alias-element-children-attrs-ambig elem))))
(do
(tap> {::warn :ambig-attrs ::elem elem})
(compilable-alias-element-children-attrs-ambig elem)))))

(defn compilable-element-children-attrs-present-evaluated
[elem]
Expand Down Expand Up @@ -340,7 +342,9 @@
(compilable-element-children-attrs-present elem))
(if (attrs-absent? elem)
(compilable-element-children-attrs-absent elem)
(compilable-element-children-attrs-ambig elem))))
(do
(tap> {::warn :ambig-attrs ::elem elem})
(compilable-element-children-attrs-ambig elem)))))

(extend-protocol CompilableNode
clojure.lang.IPersistentVector
Expand Down
33 changes: 23 additions & 10 deletions test/dev/onionpancakes/chassis/tests/test_compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,27 @@
[:div [:p "foo"] (example-elem-macro "123") [:p "bar"]]
[c/doctype-html5 [:div "foo" c/nbsp "bar"]]))

;; Attributes reflection tests
;; Warnings are emitted at compile time,
;; so warning detection is a side effect?

(def ambig-attrs-count
(atom 0))

(defonce count-ambig-attrs
(fn [m]
(when (identical? (::cc/warn m) :ambig-attrs)
(swap! ambig-attrs-count inc))))

(try
(add-tap count-ambig-attrs)
;; Compile attrs reflection examples
(let [attrs nil]
(cc/compile [:div ^java.util.Map attrs "foobar"]))
(let [^java.util.Map attrs nil]
(cc/compile [:div attrs "foobar"]))
(finally
(remove-tap count-ambig-attrs)))

(deftest test-compile-attrs-reflection
(let [attrs nil
ret (cc/compile [:div ^java.util.Map attrs "foobar"])]
;; how to write test???"
;; macroexpand doesn't capture &env
)
(let [^java.util.Map attrs nil
ret (cc/compile [:div attrs "foobar"])]
;; how to write test???"
;; macroexpand doesn't capture &env
))
(is (zero? @ambig-attrs-count)))

0 comments on commit 6247fe1

Please sign in to comment.