2021-05-31 02:06:14 -05:00
|
|
|
(ns hooks.export
|
|
|
|
(:require [clj-kondo.hooks-api :as api]))
|
|
|
|
|
|
|
|
(defn export
|
|
|
|
[{:keys [:node]}]
|
|
|
|
(let [[_ sname] (:children node)
|
|
|
|
result (api/list-node
|
|
|
|
[(api/token-node (symbol "def"))
|
|
|
|
(api/token-node (symbol (name (:value sname))))
|
|
|
|
sname])]
|
|
|
|
{:node result}))
|
2021-06-17 06:26:38 -05:00
|
|
|
|
2021-09-06 08:58:36 -05:00
|
|
|
(def registry (atom {}))
|
|
|
|
|
2021-06-17 06:26:38 -05:00
|
|
|
(defn potok-reify
|
2021-09-06 08:58:36 -05:00
|
|
|
[{:keys [:node :filename] :as params}]
|
2021-06-17 06:26:38 -05:00
|
|
|
(let [[rnode rtype & other] (:children node)
|
2021-09-06 08:58:36 -05:00
|
|
|
rsym (symbol (str "event-type-" (name (:k rtype))))
|
|
|
|
reg (get @registry filename #{})]
|
|
|
|
(when-not (:namespaced? rtype)
|
|
|
|
(let [{:keys [:row :col]} (meta rtype)]
|
|
|
|
(api/reg-finding! {:message "ptk/reify type should be namespaced"
|
|
|
|
:type :potok/reify-type
|
|
|
|
:row row
|
|
|
|
:col col})))
|
|
|
|
|
|
|
|
(if (contains? reg rsym)
|
|
|
|
(let [{:keys [:row :col]} (meta rtype)]
|
|
|
|
(api/reg-finding! {:message (str "duplicate type: " (name (:k rtype)))
|
|
|
|
:type :potok/reify-type
|
|
|
|
:row row
|
|
|
|
:col col}))
|
|
|
|
(swap! registry update filename (fnil conj #{}) rsym))
|
|
|
|
|
|
|
|
(let [result (api/list-node
|
|
|
|
(into [(api/token-node (symbol "deftype"))
|
|
|
|
(api/token-node rsym)
|
|
|
|
(api/vector-node [])]
|
|
|
|
other))]
|
|
|
|
{:node result})))
|
2021-06-18 03:23:03 -05:00
|
|
|
|
2023-07-20 03:49:46 -05:00
|
|
|
(defn penpot-with-atomic
|
|
|
|
[{:keys [node]}]
|
|
|
|
(let [[_ params & other] (:children node)
|
|
|
|
|
|
|
|
result (if (api/vector-node? params)
|
|
|
|
(api/list-node
|
|
|
|
(into [(api/token-node (symbol "clojure.core" "with-open")) params] other))
|
|
|
|
(api/list-node
|
|
|
|
(into [(api/token-node (symbol "clojure.core" "with-open"))
|
|
|
|
(api/vector-node [params params])]
|
|
|
|
other)))
|
|
|
|
|
|
|
|
]
|
|
|
|
{:node result}))
|
2023-06-20 04:11:55 -05:00
|
|
|
|
|
|
|
(defn penpot-defrecord
|
|
|
|
[{:keys [:node]}]
|
|
|
|
(let [[rnode rtype rparams & other] (:children node)
|
|
|
|
|
|
|
|
nodes [(api/token-node (symbol "do"))
|
|
|
|
(api/list-node
|
|
|
|
(into [(api/token-node (symbol (name (:value rnode)))) rtype rparams] other))
|
|
|
|
(api/list-node
|
|
|
|
[(api/token-node (symbol "defn"))
|
|
|
|
(api/token-node (symbol (str "pos->" (:string-value rtype))))
|
|
|
|
(api/vector-node
|
|
|
|
(->> (:children rparams)
|
|
|
|
(mapv (fn [t]
|
|
|
|
(api/token-node (symbol (str "_" (:string-value t))))))))
|
|
|
|
(api/token-node nil)])]
|
|
|
|
|
|
|
|
result (api/list-node nodes)]
|
|
|
|
|
|
|
|
;; (prn "=====>" (into {} rparams))
|
|
|
|
;; (prn (api/sexpr result))
|
|
|
|
{:node result}))
|
|
|
|
|
2021-06-18 03:23:03 -05:00
|
|
|
(defn clojure-specify
|
|
|
|
[{:keys [:node]}]
|
|
|
|
(let [[rnode rtype & other] (:children node)
|
|
|
|
result (api/list-node
|
|
|
|
(into [(api/token-node (symbol "extend-type"))
|
|
|
|
(api/token-node (gensym (:string-value rtype)))]
|
|
|
|
other))]
|
|
|
|
{:node result}))
|
2021-06-18 03:53:03 -05:00
|
|
|
|
|
|
|
(defn service-defmethod
|
|
|
|
[{:keys [:node]}]
|
2021-11-18 10:43:52 -05:00
|
|
|
(let [[rnode rtype ?meta & other] (:children node)
|
2021-06-18 03:53:03 -05:00
|
|
|
rsym (gensym (name (:k rtype)))
|
2022-07-13 07:29:47 -05:00
|
|
|
|
|
|
|
[?docs other] (if (api/string-node? ?meta)
|
|
|
|
[?meta other]
|
|
|
|
[nil (cons ?meta other)])
|
|
|
|
|
|
|
|
[?meta other] (let [?meta (first other)]
|
|
|
|
(if (api/map-node? ?meta)
|
|
|
|
[?meta (rest other)]
|
|
|
|
[nil other]))
|
|
|
|
|
|
|
|
nodes [(api/token-node (symbol "do"))
|
|
|
|
(api/list-node
|
|
|
|
[(api/token-node (symbol "declare"))
|
|
|
|
(api/token-node rsym)])
|
|
|
|
|
|
|
|
(when ?docs
|
|
|
|
(api/list-node
|
|
|
|
[(api/token-node (symbol "comment")) ?docs]))
|
|
|
|
|
|
|
|
(when ?meta
|
|
|
|
(api/list-node
|
|
|
|
[(api/token-node (symbol "reset-meta!"))
|
|
|
|
(api/token-node rsym)
|
|
|
|
?meta]))
|
|
|
|
(api/list-node
|
|
|
|
(into [(api/token-node (symbol "defmethod"))
|
|
|
|
(api/token-node rsym)
|
|
|
|
rtype]
|
|
|
|
other))]
|
|
|
|
result (api/list-node (filterv some? nodes))]
|
|
|
|
|
|
|
|
;; (prn "=====>" rtype)
|
2021-11-18 10:43:52 -05:00
|
|
|
;; (prn (api/sexpr result))
|
2021-06-18 03:53:03 -05:00
|
|
|
{:node result}))
|