Skip to content

Commit

Permalink
infer all :static
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Apr 22, 2024
1 parent eba3d6c commit 1e7877f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/compojure/api/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -813,17 +813,20 @@
(static-form? &env form'))))))

(defn- constant-form? [&env form]
(or ((some-fn nil? keyword? number? boolean?) form)
(or ((some-fn nil? keyword? number? boolean? string?) form)
(and (seq? form)
(= 2 (count form))
(= 'quote (first form)))))

(defn- static-binder? [&env bv]
(and (vector? bv)
(even? (count bv))
(every? (fn [[_ init]]
(static-body? &env init))
(partition 2 bv))))
(reduce (fn [&env [l init]]
(if-not (or (simple-symbol? l)
(static-form? init))
(reduced false)
(assoc &env l true)))
&env (partition 2 bv))))

(defn- static-let? [&env body]
(and (seq? body)
Expand All @@ -832,9 +835,10 @@
(let [v (resolve &env (first body))]
(when (var? v)
(contains?
'#{clojure.core/let compojure.api.sweet/let-routes compojure.api.core/let-routes}
'#{clojure.core/let clojure.core/for
compojure.api.sweet/let-routes compojure.api.core/let-routes}
(symbol v)))))
(let [[_ bv & body] body]
(let [[_ bv & body] (macroexpand-1 (list* `let (next body)))]
(and (static-binder? &env bv)
(static-body? &env body)))))

Expand Down
1 change: 0 additions & 1 deletion test/compojure/api/integration_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,6 @@
(fact "context"
(let [app (api
(context "/api" []
:static true
(for [path ["/ping" "/pong"]]
(GET path [] (ok {:path path})))))]

Expand Down
2 changes: 0 additions & 2 deletions test19/compojure/api/coercion/issue336_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@
(context "/api" []
:tags ["api"]
:coercion :spec
:static true

(context "/jr1" []
:static true
(resource
{:get
{:summary "Number of successful full-text article requests by month and journal"
Expand Down

0 comments on commit 1e7877f

Please sign in to comment.