Skip to content

Commit 9a4c682

Browse files
committed
Fix :as-alias handling for .cljc files
1 parent 45db051 commit 9a4c682

File tree

6 files changed

+31
-18
lines changed

6 files changed

+31
-18
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 3.5.2
6+
7+
* [#378](https://github.com/clojure-emacs/refactor-nrepl/issues/378): Fix `:as-alias` handling for .cljc files.
8+
59
## 3.5.1
610

711
* Refine `:as-alias` detection.

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Be aware that this isn't the case if you connect to an already running REPL proc
2626
Add the following, either in your project's `project.clj`, or in the `:user` profile found at `~/.lein/profiles.clj`:
2727

2828
```clojure
29-
:plugins [[refactor-nrepl "3.5.1"]
29+
:plugins [[refactor-nrepl "3.5.2"]
3030
[cider/cider-nrepl "0.28.3"]]
3131
```
3232

@@ -360,12 +360,12 @@ If you want to use `mranderson` while developing locally with the REPL, the sour
360360

361361
When you want to release locally to the following:
362362

363-
PROJECT_VERSION=3.5.1 make install
363+
PROJECT_VERSION=3.5.2 make install
364364

365365
And here's how to deploy to Clojars:
366366

367367
```bash
368-
git tag -a v3.5.1 -m "3.5.1"
368+
git tag -a v3.5.2 -m "3.5.2"
369369
git push --tags
370370
```
371371

src/refactor_nrepl/find/symbols_in_file.clj

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
reader/*data-readers* (merge (when (= dialect :cljs)
6969
{'js identity})
7070
*data-readers*)
71-
clojure.tools.reader/*alias-map* ns-aliases]
71+
reader/*alias-map* ns-aliases]
7272
(let [rdr (-> path slurp core/file-content-sans-ns
7373
readers/indexing-push-back-reader)
7474
rdr-opts {:read-cond :allow :features #{dialect} :eof :eof}
@@ -98,7 +98,6 @@
9898
(when (not= form :eof)
9999
(walk/prewalk collect-symbols form)
100100
(recur (reader/read rdr-opts rdr))))
101-
(->> @syms
102-
(map
103-
(partial fix-ns-of-backquoted-symbols (dialect parsed-ns)))
104-
set))))))))
101+
(into #{}
102+
(map (partial fix-ns-of-backquoted-symbols (dialect parsed-ns)))
103+
@syms))))))))

src/refactor_nrepl/ns/ns_parser.clj

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@
148148
e.g {str clojure.string}"
149149
[libspecs]
150150
(->> libspecs
151-
(map (fn alias [{:keys [ns as]}]
152-
(when as
153-
{as ns})))
154-
(remove nil?)
151+
(keep (fn alias [{:keys [ns as as-alias]}]
152+
(cond-> {}
153+
as (assoc as ns)
154+
as-alias (assoc as-alias ns))))
155155
(apply merge)))

test-resources/clean_ns/as_alias.cljc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(ns as-alias
2+
(:require
3+
[foo :as-alias f]
4+
[unused :as-alias clean-me-up]))
5+
6+
(def bar ::f/bar)

test/refactor_nrepl/ns/clean_ns_test.clj

+10-6
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@
176176
(:import java.util.Date)))
177177

178178
(deftest test-pprint-artifact-ns
179-
(are [setting filename]
180-
(let [actual (config/with-config {:insert-newline-after-require setting}
181-
(pprint-ns (with-meta artifact-ns nil)))
182-
expected (-> filename File. .getAbsolutePath slurp)]
183-
(is (= expected actual))
184-
true)
179+
(are [setting filename] (let [actual (config/with-config {:insert-newline-after-require setting}
180+
(pprint-ns (with-meta artifact-ns nil)))
181+
expected (-> filename File. .getAbsolutePath slurp)]
182+
(is (= expected actual))
183+
true)
185184
true "test-resources/artifacts_pprinted"
186185
false "test-resources/artifacts_pprinted_traditional_newline"))
187186

@@ -269,3 +268,8 @@
269268
(deftest npm-string-sorting
270269
(is (= (pprint-ns (clean-ns ns-with-npm-strs))
271270
(pprint-ns (read-string (slurp (:path ns-with-npm-strs-clean)))))))
271+
272+
(core/with-clojure-version->= {:major 1 :minor 11}
273+
(deftest as-alias
274+
(is (= '(ns as-alias (:require [foo :as-alias f]))
275+
(clean-ns (clean-msg "test-resources/clean_ns/as_alias.cljc"))))))

0 commit comments

Comments
 (0)