From 1e7877f2a4e3239d3257cd3515930d07d82a97c2 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Mon, 22 Apr 2024 11:06:41 -0500 Subject: [PATCH] infer all :static --- src/compojure/api/meta.clj | 16 ++++++++++------ test/compojure/api/integration_test.clj | 1 - test19/compojure/api/coercion/issue336_test.clj | 2 -- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/compojure/api/meta.clj b/src/compojure/api/meta.clj index 388ec1ef..775da983 100644 --- a/src/compojure/api/meta.clj +++ b/src/compojure/api/meta.clj @@ -813,7 +813,7 @@ (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))))) @@ -821,9 +821,12 @@ (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) @@ -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))))) diff --git a/test/compojure/api/integration_test.clj b/test/compojure/api/integration_test.clj index 98d18675..3cfe35d6 100644 --- a/test/compojure/api/integration_test.clj +++ b/test/compojure/api/integration_test.clj @@ -1705,7 +1705,6 @@ (fact "context" (let [app (api (context "/api" [] - :static true (for [path ["/ping" "/pong"]] (GET path [] (ok {:path path})))))] diff --git a/test19/compojure/api/coercion/issue336_test.clj b/test19/compojure/api/coercion/issue336_test.clj index b01b0f5c..07e390fc 100644 --- a/test19/compojure/api/coercion/issue336_test.clj +++ b/test19/compojure/api/coercion/issue336_test.clj @@ -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"