-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in cljr-clean-ns
when js literal is present
#443
Comments
My personal workaround for this is to use the |
I found 2 fixes, but I'm not familiar enough with the rest of the code to know if it's acceptable. 1Similarly to how it's done here, the reader could be augmented with the built-in cljs tag literals. However I'm not sure it's okay to impose a Clojurescript requirement in this namespace. 2Alternatively, we could add a default data reader that would simply drop the tag and return the form. If it's anything else than valid Clojure it could throw an error, but without a default reader we're already throwing anyway. [*ns* file-ns
reader/*data-readers* *data-readers*
reader/*default-data-reader-fn* (fn [_tag form] form) ;; <---- added
mranderson048.toolsreader.v1v1v1.clojure.tools.reader/*alias-map* ns-aliases] Should I open an issue in refactor-nrepl instead? |
I like alternative 2) here. You're right that the discussion belongs to the refactor-nrepl so feel free to open a PR over there. Thanks for investigating, @Frozenlock! |
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.
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.
PR submitted clojure-emacs/refactor-nrepl#280. |
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.
Expected behavior
Cleaning the namespace with
cljr-clean-ns
.Actual behavior
Error when encountering
#js
.No error with other tag literal such as
#inst "1985-04-12"
.Steps to reproduce the problem
Create a clojurescript file with a js literal such as
#js {:a 1}
.Try to run
cljr-clean-ns
.Environment & Version information
clj-refactor.el version information
clj-refactor 2.4.0, refactor-nrepl 2.4.0
CIDER version information
CIDER 0.21.0 (New York), nREPL 0.6.0
Clojure 1.10.0, Java 1.8.0_212
Leiningen or Boot version
Leiningen 2.9.1 on Java 1.8.0_212 OpenJDK 64-Bit Server VM
Emacs version
Emacs 26.2
Operating system
Ubuntu 18.04.2 LTS
The text was updated successfully, but these errors were encountered: