|
668 | 668 | 'compojure.api.resource/resource))
|
669 | 669 |
|
670 | 670 | (def routes-vars #{'compojure.api.sweet/routes
|
671 |
| - 'compojure.api.resource/routes}) |
| 671 | + 'compojure.api.core/routes}) |
672 | 672 |
|
673 | 673 | (declare static-body?)
|
674 | 674 |
|
|
682 | 682 | (when (symbol? sym)
|
683 | 683 | (when-some [v (resolve &env sym)]
|
684 | 684 | (when (var? v)
|
685 |
| - (or (endpoint-vars (symbol v)) |
686 |
| - (and (routes-vars (symbol v)) |
687 |
| - (static-body? &env (next form))))))))))) |
| 685 | + (let [sym (symbol v)] |
| 686 | + (or (endpoint-vars sym) |
| 687 | + (and (routes-vars sym) |
| 688 | + (static-body? &env (next form)))))))))))) |
688 | 689 |
|
689 | 690 | (def context-vars (into #{}
|
690 | 691 | (mapcat (fn [n]
|
|
818 | 819 | (= 2 (count form))
|
819 | 820 | (= 'quote (first form)))))
|
820 | 821 |
|
821 |
| -(defn- static-binder? [&env bv] |
822 |
| - (and (vector? bv) |
823 |
| - (even? (count bv)) |
824 |
| - (reduce (fn [&env [l init]] |
825 |
| - (if-not (or (simple-symbol? l) |
826 |
| - (static-form? init)) |
827 |
| - (reduced false) |
828 |
| - (assoc &env l true))) |
829 |
| - &env (partition 2 bv)))) |
830 |
| - |
831 |
| -(defn- static-let? [&env body] |
832 |
| - (and (seq? body) |
833 |
| - (symbol? (first body)) |
834 |
| - (or (= 'let* (first body)) |
835 |
| - (let [v (resolve &env (first body))] |
836 |
| - (when (var? v) |
837 |
| - (contains? |
838 |
| - '#{clojure.core/let clojure.core/for |
839 |
| - compojure.api.sweet/let-routes compojure.api.core/let-routes} |
840 |
| - (symbol v))))) |
841 |
| - (let [[_ bv & body] (macroexpand-1 (list* `let (next body)))] |
842 |
| - (and (static-binder? &env bv) |
843 |
| - (static-body? &env body))))) |
| 822 | +(defn- static-binder-env [&env bv] |
| 823 | + (when (and (vector? bv) |
| 824 | + (even? (count bv))) |
| 825 | + (reduce (fn [&env [l init]] |
| 826 | + (if-not (or (simple-symbol? l) |
| 827 | + (simple-keyword? l) ;;for |
| 828 | + (static-form? init)) |
| 829 | + (reduced nil) |
| 830 | + (cond-> &env |
| 831 | + (simple-symbol? l) |
| 832 | + (assoc l true)))) |
| 833 | + (or &env {}) (partition 2 bv)))) |
| 834 | + |
| 835 | +(defn- static-let? [&env form] |
| 836 | + (and (seq? form) |
| 837 | + (symbol? (first form)) |
| 838 | + (when-some [op (or (when (= 'let* (first form)) |
| 839 | + 'let*) |
| 840 | + (let [v (resolve &env (first form))] |
| 841 | + (when (var? v) |
| 842 | + (let [sym (symbol v)] |
| 843 | + (when (contains? |
| 844 | + '#{clojure.core/let clojure.core/for |
| 845 | + compojure.api.sweet/let-routes compojure.api.core/let-routes} |
| 846 | + sym) |
| 847 | + sym)))))] |
| 848 | + (let [;; expand destructuring |
| 849 | + [_ bv & body] (macroexpand |
| 850 | + (if ('#{compojure.api.sweet/let-routes compojure.api.core/let-routes} op) |
| 851 | + form |
| 852 | + (list* `let (next form))))] |
| 853 | + (when-some [&env (static-binder-env &env bv)] |
| 854 | + (static-body? &env body)))))) |
844 | 855 |
|
845 | 856 | (defn- static-vector? [&env body]
|
846 | 857 | (and (vector? body)
|
|
0 commit comments