Skip to content

Commit 061244f

Browse files
committed
prune-dependencies: consider :as names in cljs strings requires as objects in themselves
Fixes #383
1 parent 765bf96 commit 061244f

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/refactor_nrepl/ns/prune_dependencies.clj

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,25 @@
4343
(some (set symbols-in-file) (map str (vals rename))))
4444

4545
(defn- libspec-in-use?
46-
[{:keys [refer] :as libspec} symbols-in-file current-ns]
47-
(when (or (if (= refer :all)
48-
(some (partial libspec-in-use-with-refer-all? libspec current-ns)
49-
symbols-in-file)
50-
(some (partial libspec-in-use-without-refer-all? libspec)
51-
symbols-in-file))
52-
(libspec-in-use-with-rename? libspec symbols-in-file))
53-
libspec))
46+
[{libspec-refer :refer
47+
libspec-ns :ns
48+
libspec-as :as
49+
:as libspec} symbols-in-file current-ns]
50+
(let [refer-all? (= libspec-refer :all)
51+
libspec-as-str (str libspec-as)
52+
symbols-in-file (cond-> symbols-in-file
53+
(and (string? libspec-ns)
54+
(not refer-all?)
55+
libspec-as
56+
(contains? (set symbols-in-file) libspec-as-str))
57+
(conj (str (symbol libspec-ns libspec-as-str))))]
58+
(when (or (if refer-all?
59+
(some (partial libspec-in-use-with-refer-all? libspec current-ns)
60+
symbols-in-file)
61+
(some (partial libspec-in-use-without-refer-all? libspec)
62+
symbols-in-file))
63+
(libspec-in-use-with-rename? libspec symbols-in-file))
64+
libspec)))
5465

5566
(defn- referred-symbol-in-use?
5667
[symbol-ns used-syms sym]

test-resources/cljsns.cljs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
["react" :as react]
1111
["underscore$default" :as underscore]
1212
["react-UNUSED" :as react-unused]
13-
["underscore-UNUSEd$default" :as underscore-unused])
13+
["underscore-UNUSED$default" :as underscore-unused]
14+
["@react-native-async-storage/async-storage" :as AsyncStorage])
1415
(:require-macros [cljs.test :refer [testing]]
1516
[cljs.analyzer.macros :as am]
1617
cljs.analyzer.api)
@@ -29,6 +30,12 @@
2930
[]
3031
(react/foo underscore/bar))
3132

33+
;; https://github.com/clojure-emacs/clj-refactor.el/issues/529
34+
(defn use-as
35+
"Uses an `:as` name as an object in itself"
36+
[]
37+
(.getItem AsyncStorage "foo"))
38+
3239
(deftest tt
3340
(testing "whatever"
3441
(is (= 1 1))))

test-resources/cljsns_cleaned.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns cljsns
2-
(:require ["react" :as react]
2+
(:require ["@react-native-async-storage/async-storage" :as AsyncStorage]
3+
["react" :as react]
34
["underscore$default" :as underscore]
45
[cljs.pprint :as pprint]
56
[cljs.test :refer-macros [deftest is]]

0 commit comments

Comments
 (0)