From a7d4b24cc9ff767b4255993cf9c4a6e33ba3c067 Mon Sep 17 00:00:00 2001 From: Enzzo Cavallo Date: Fri, 29 Nov 2024 23:41:59 -0300 Subject: [PATCH] cljs-2292 refer-clojure rename should also exclude --- src/main/clojure/cljs/analyzer.cljc | 6 +++++- src/test/cljs/cljs/ns_test.cljs | 4 ++++ src/test/clojure/cljs/analyzer_tests.clj | 10 +++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/clojure/cljs/analyzer.cljc b/src/main/clojure/cljs/analyzer.cljc index 887ae349a..8c61c4586 100644 --- a/src/main/clojure/cljs/analyzer.cljc +++ b/src/main/clojure/cljs/analyzer.cljc @@ -2907,7 +2907,7 @@ (parse-ns-error-msg spec "Each of :as and :refer options may only be specified once in :require / :require-macros")))))) -(defn parse-ns-excludes [env args] +(defn- parse-ns-excludes-impl [env args] (reduce (fn [s [k & filters]] (if (= k :refer-clojure) @@ -2947,6 +2947,10 @@ {:excludes #{} :renames {}} args)) +(defn parse-ns-excludes [env args] + (let [s (parse-ns-excludes-impl env args)] + (update s :excludes into (keys (:renames s))))) + (defn use->require [env [lib & filters :as spec]] (when-not (and (symbol? lib) (odd? (count spec))) (throw diff --git a/src/test/cljs/cljs/ns_test.cljs b/src/test/cljs/cljs/ns_test.cljs index 2cb85865c..7243eae0a 100644 --- a/src/test/cljs/cljs/ns_test.cljs +++ b/src/test/cljs/cljs/ns_test.cljs @@ -48,3 +48,7 @@ (deftest test-cljs-3399 (is (= ::fake/foo :fake.ns/foo) (is (= `fake/foo 'fake.ns/foo)))) + +(deftest test-cljs-2292 + (is (= false (exists? mapv))) + (is (= true (exists? core-mapv)))) diff --git a/src/test/clojure/cljs/analyzer_tests.clj b/src/test/clojure/cljs/analyzer_tests.clj index e96b6ae3f..f1b639938 100644 --- a/src/test/clojure/cljs/analyzer_tests.clj +++ b/src/test/clojure/cljs/analyzer_tests.clj @@ -338,7 +338,7 @@ '(ns foo.core (:refer-clojure :rename {when always map core-map}))))] - (is (= (-> parsed-ns :excludes) #{})) + (is (= (-> parsed-ns :excludes) '#{when map})) (is (= (-> parsed-ns :rename-macros) '{always cljs.core/when})) (is (= (-> parsed-ns :renames) '{core-map cljs.core/map}))) (is (thrown? Exception (env/with-compiler-env test-cenv @@ -379,6 +379,14 @@ :renames {}})) (is (set? (:excludes parsed))))) + +(deftest test-cljs-2292 + (let [parsed (ana/parse-ns-excludes {} '((:refer-clojure :rename {map clj-map})))] + (is (= parsed + '{:excludes #{map} + :renames {map clj-map}})) + (is (set? (:excludes parsed))))) + (deftest test-cljs-1785-js-shadowed-by-local (let [ws (atom [])] (ana/with-warning-handlers [(collecting-warning-handler ws)]