Skip to content

Commit c23c00b

Browse files
Frozenlockexpez
authored andcommitted
[clj-refactor.el #443] Add support for js literal
As described in clojure-emacs/clj-refactor.el#443, it was impossible to use clj-clean-ns when a js literal was present: 'No reader function for tag js' One possible solution was to use *default-data-reader-fn* with the function `(fn [_tag value] value)`. However this had the potential of swallowing useful error messages when dealing with other undefined tags. The chosen solution is to provide a dummy reader function specifically for the #js tag (and only for the :cljs dialect). Rather than transforming the provided form into a JS object, it returns the clojure form, which can then be analyzed normally.
1 parent 5e179a9 commit c23c00b

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
* [clojure-emacs/clj-refactor.el#443](https://github.com/clojure-emacs/clj-refactor.el/issues/443) `clean-ns` support namespaces with js literal (#js).
56
* [#251](https://github.com/clojure-emacs/refactor-nrepl/pull/251) `clean-ns` support extra message key `relative-path`, which will be used if `path` does not exist.
67
* [#256](https://github.com/clojure-emacs/refactor-nrepl/pull/256) ignore malformed artifact coordinates when fetching from Clojars.
78
* [#264](https://github.com/clojure-emacs/refactor-nrepl/pull/264) less bandwidth used to fetch artifacts from Clojars

src/refactor_nrepl/find/symbols_in_file.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
(ns-parser/get-libspecs-from-file :cljs (io/file path)))
5757
(ns-aliases file-ns))]
5858
(binding [*ns* file-ns
59-
reader/*data-readers* *data-readers*
59+
reader/*data-readers* (merge (when (= dialect :cljs)
60+
{'js identity})
61+
*data-readers*)
6062
clojure.tools.reader/*alias-map* ns-aliases]
6163
(let [rdr (-> path slurp core/file-content-sans-ns
6264
readers/indexing-push-back-reader)

test/resources/cljsns.cljs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[cljsjs.js-yaml] ; this one should not be pruned as it contains externs
55
[clojure.string :refer [split-lines join]]
66
[cljs.pprint :as pprint]
7+
[resources.js-literal-ns :as js-literal]
78
[resources.keyword-ns :as kw]
89
[clojure.set :as set])
910
(:require-macros [cljs.test :refer [testing]]
@@ -35,6 +36,8 @@
3536
(cljs.analyzer.api/no-warn
3637
:body)
3738

39+
#js [{:foo #js [::js-literal/bar]}]
40+
3841
;; Caused reader to crash for cljs
3942
;; https://github.com/clojure-emacs/clj-refactor.el/issues/353
4043
::kw/foo

test/resources/cljsns_cleaned.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
cljsjs.js-yaml
55
[clojure.set :as set]
66
[clojure.string :refer [join split-lines]]
7+
[resources.js-literal-ns :as js-literal]
78
[resources.keyword-ns :as kw])
89
(:require-macros cljs.analyzer.api
910
[cljs.analyzer.macros :as am]

test/resources/js_literal_ns.cljs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(ns resources.js-literal-ns)
2+
3+
::bar

0 commit comments

Comments
 (0)