Skip to content
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

Closed
Frozenlock opened this issue Jun 15, 2019 · 4 comments
Closed

Error in cljr-clean-ns when js literal is present #443

Frozenlock opened this issue Jun 15, 2019 · 4 comments

Comments

@Frozenlock
Copy link

Expected behavior

Cleaning the namespace with cljr-clean-ns.

Actual behavior

Error when encountering #js.

cljr--maybe-rethrow-error: clojure.lang.ExceptionInfo: [line 10, col 4] No reader function for tag js. {:type :reader-exception, :ex-kind :reader-error, :file "<my-file>", :line 10, :col 4}

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

@aiba
Copy link
Contributor

aiba commented Nov 23, 2019

My personal workaround for this is to use the j/lit macro from the appliedsciencestudio/js-interop library, but it would be great if this was fixed in clj-refactor.

@Frozenlock
Copy link
Author

Frozenlock commented Dec 13, 2019

I found 2 fixes, but I'm not familiar enough with the rest of the code to know if it's acceptable.
Both fixes apply to find/symbols-in-file.

1

Similarly 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.

2

Alternatively, 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?

@expez
Copy link
Member

expez commented Dec 14, 2019

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!

Frozenlock added a commit to Frozenlock/refactor-nrepl that referenced this issue Dec 14, 2019
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.
Frozenlock added a commit to Frozenlock/refactor-nrepl that referenced this issue Dec 14, 2019
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.
@Frozenlock
Copy link
Author

PR submitted clojure-emacs/refactor-nrepl#280.

expez pushed a commit to clojure-emacs/refactor-nrepl that referenced this issue Dec 15, 2019
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.
@expez expez closed this as completed Dec 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants