Skip to content

Commit 1e7877f

Browse files
committed
infer all :static
1 parent eba3d6c commit 1e7877f

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/compojure/api/meta.clj

+10-6
Original file line numberDiff line numberDiff line change
@@ -813,17 +813,20 @@
813813
(static-form? &env form'))))))
814814

815815
(defn- constant-form? [&env form]
816-
(or ((some-fn nil? keyword? number? boolean?) form)
816+
(or ((some-fn nil? keyword? number? boolean? string?) form)
817817
(and (seq? form)
818818
(= 2 (count form))
819819
(= 'quote (first form)))))
820820

821821
(defn- static-binder? [&env bv]
822822
(and (vector? bv)
823823
(even? (count bv))
824-
(every? (fn [[_ init]]
825-
(static-body? &env init))
826-
(partition 2 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))))
827830

828831
(defn- static-let? [&env body]
829832
(and (seq? body)
@@ -832,9 +835,10 @@
832835
(let [v (resolve &env (first body))]
833836
(when (var? v)
834837
(contains?
835-
'#{clojure.core/let compojure.api.sweet/let-routes compojure.api.core/let-routes}
838+
'#{clojure.core/let clojure.core/for
839+
compojure.api.sweet/let-routes compojure.api.core/let-routes}
836840
(symbol v)))))
837-
(let [[_ bv & body] body]
841+
(let [[_ bv & body] (macroexpand-1 (list* `let (next body)))]
838842
(and (static-binder? &env bv)
839843
(static-body? &env body)))))
840844

test/compojure/api/integration_test.clj

-1
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,6 @@
17051705
(fact "context"
17061706
(let [app (api
17071707
(context "/api" []
1708-
:static true
17091708
(for [path ["/ping" "/pong"]]
17101709
(GET path [] (ok {:path path})))))]
17111710

test19/compojure/api/coercion/issue336_test.clj

-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@
3939
(context "/api" []
4040
:tags ["api"]
4141
:coercion :spec
42-
:static true
4342

4443
(context "/jr1" []
45-
:static true
4644
(resource
4745
{:get
4846
{:summary "Number of successful full-text article requests by month and journal"

0 commit comments

Comments
 (0)