diff --git a/src/dev/onionpancakes/chassis/compiler.clj b/src/dev/onionpancakes/chassis/compiler.clj index 97a1b60..5d47aa1 100644 --- a/src/dev/onionpancakes/chassis/compiler.clj +++ b/src/dev/onionpancakes/chassis/compiler.clj @@ -39,22 +39,27 @@ (defmacro compile* [node] (binding [*env* &env] - (-> (c/tree-serializer branch? children node) - (compact) - (vec) - (vary-meta assoc ::c/content true)))) + (let [rch (fn [node] + (mapv resolved (children node))) + ret (->> (resolved node) + (c/tree-serializer branch? rch) + (compact) + (vec))] + (vary-meta ret assoc ::c/content true)))) (defmacro compile [node] (binding [*env* &env] - (let [ret (-> (c/tree-serializer branch? children node) - (compact) - (vec) - (vary-meta assoc ::c/content true))] + (let [rch (fn [node] + (mapv resolved (children node))) + ret (->> (resolved node) + (c/tree-serializer branch? rch) + (compact) + (vec))] (case (count ret) 0 nil 1 (nth ret 0) - ret)))) + (vary-meta ret assoc ::c/content true))))) ;; CompilableForm @@ -135,7 +140,7 @@ (evaluated? [_] false) ;; But not macro barriers. (resolved [this] - (macroexpand-1 this)) + (macroexpand this)) clojure.lang.Symbol (attrs? [this] (or (attrs-symbol? this) @@ -350,12 +355,11 @@ clojure.lang.IPersistentVector (branch? [_] true) (children [this] - (let [resv (resolved this)] - (if (c/element-vector? resv) - (if (c/alias-element? resv) - (compilable-alias-element-children resv) - (compilable-element-children resv)) - resv))) + (if (c/element-vector? this) + (if (c/alias-element? this) + (compilable-alias-element-children this) + (compilable-element-children this)) + this)) Object (branch? [_] false) (children [_] nil) diff --git a/test/dev/onionpancakes/chassis/tests/test_compiler.clj b/test/dev/onionpancakes/chassis/tests/test_compiler.clj index d2ca3eb..a0aa860 100644 --- a/test/dev/onionpancakes/chassis/tests/test_compiler.clj +++ b/test/dev/onionpancakes/chassis/tests/test_compiler.clj @@ -23,6 +23,10 @@ [arg] [:p arg]) +(defmacro example-elem-macro-nested + [arg] + `(example-elem-macro ~arg)) + (defmethod c/resolve-alias ::Foo [_ _ attrs content] [:p.alias attrs content]) @@ -55,6 +59,7 @@ [:div example-attrs] [:div (example-elem-fn "foo")] [:div (example-elem-macro "foo")] + [:div (example-elem-macro-nested "foo")] [:div (for [i (range 4)] [:p i])] (map inc (range 5)) @@ -80,7 +85,10 @@ [:div {:foo "bar"} "123"] [:div {:foo example-constant}] [:div [:p "foo"] [:p "bar"]] + (example-elem-macro "123") + (example-elem-macro-nested "123") [:div [:p "foo"] (example-elem-macro "123") [:p "bar"]] + [:div [:p "foo"] (example-elem-macro-nested "123") [:p "bar"]] [c/doctype-html5 [:div "foo" c/nbsp "bar"]])) ;; Attributes reflection tests