|
1 | 1 | (ns mori.macros
|
2 | 2 | (:require [cljs.compiler :as comp]
|
3 | 3 | [cljs.analyzer :as ana]
|
| 4 | + [cljs.util :as util] |
4 | 5 | [cljs.analyzer.api :as ana-api]))
|
5 | 6 |
|
6 | 7 | (alias 'core 'clojure.core)
|
|
12 | 13 | (.toString coll#)))))
|
13 | 14 |
|
14 | 15 | (defmacro make-inspectable [& xs]
|
15 |
| - `(do |
16 |
| - ~@(map make-inspectable-1 xs))) |
| 16 | + `(do ~@(map make-inspectable-1 xs))) |
17 | 17 |
|
18 | 18 | (defmacro mori-export [exportf coref]
|
19 |
| - (let [{:keys [ns name methods]} (ana-api/resolve &env coref)] |
20 |
| - `(do |
21 |
| - (js/goog.exportSymbol ~(str "mori." (core/name exportf)) ~coref) ~(list 'js* ";") |
22 |
| - ~@(when-not (= 1 (count methods)) |
23 |
| - (map |
24 |
| - (fn [{:keys [variadic max-fixed-arity]}] |
25 |
| - (if variadic |
26 |
| - `(do |
27 |
| - (js/goog.exportSymbol |
28 |
| - ~(str "mori." (core/name exportf) ".fn") |
29 |
| - ~(symbol (str ns) (str (core/name name) ".cljs$core$IFn$_invoke$variadic"))) |
30 |
| - ~(list 'js* ";")) |
31 |
| - `(do |
32 |
| - (js/goog.exportSymbol |
33 |
| - ~(str "mori." (core/name exportf) ".f" max-fixed-arity) |
34 |
| - ~(symbol (str ns) (str (core/name name) ".cljs$core$IFn$_invoke$arity$" max-fixed-arity))) |
35 |
| - ~(list 'js* ";")))) |
36 |
| - methods))))) |
| 19 | + (let [{:keys [ns name arglists]} (ana-api/resolve &env coref) |
| 20 | + arglists (cond-> arglists |
| 21 | + (= (first arglists) 'quote) rest)] |
| 22 | + (letfn [(export-method [arglist] |
| 23 | + (let [c (count arglist)] |
| 24 | + `(js/goog.exportSymbol |
| 25 | + ~(str "mori." (core/name exportf) ".f" c) |
| 26 | + ~(symbol (str ns) |
| 27 | + (str (core/name name) ".cljs$core$IFn$_invoke$arity$" c)))))] |
| 28 | + `(do |
| 29 | + (js/goog.exportSymbol ~(str "mori." (core/name exportf)) ~coref) ~(list 'js* ";") |
| 30 | + ~@(when (< 1 (count arglists)) |
| 31 | + (map export-method (remove #(some '#{&} %) arglists))))))) |
37 | 32 |
|
38 | 33 | (comment
|
39 | 34 |
|
|
0 commit comments