Skip to content

Commit

Permalink
jsx demo (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Aug 10, 2022
1 parent ba23b8a commit 9ce8524
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/cherry/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,33 @@ break;}" body)
(defn transpile-form [f]
(emit f {:context :statement}))

(defn html [v]
(cond (vector? v)
(let [tag (first v)
attrs (second v)
attrs (when (map? attrs) attrs)
elts (if attrs (nnext v) (next v))
tag-name (symbol tag)]
(list 'let ['x (list* 'js* (format "<~{}~{}>%s</~{}>\n"
(str/join " " (repeat (count elts) "~{}"))
) tag-name (html attrs)
(concat (map html elts) [tag-name]))]
'x))
(map? v)
(emit v (expr-env {}))
(nil? v) (list 'js* "")
:else (list 'js* (format "{ %s }" (emit v (expr-env {}))))))

(defn jsx [form]
(html form))

(def cherry-parse-opts
(e/normalize-opts
{:all true
:end-location false
:location? seq?
:readers {'js #(vary-meta % assoc ::js true)}
:readers {'js #(vary-meta % assoc ::js true)
'jsx jsx}
:read-cond :allow
:features #{:cljc}}))

Expand Down

0 comments on commit 9ce8524

Please sign in to comment.