The following behavior was observed and confirmed from the code:
(clj->js :ns/n) => "n"
I believe this is a limitation and the namespace of the keyword should be kept while writing it to string.
The code in core.js does this while handling keywords:
(keyword? x) (name x)
while it should do this (or something similar):
(keyword? x) (str (namespace x) "/" (name x))
I have just stumbled across this one, shall we at least say it in the docstring of clj->js that we are losing the namespace part?
With the introduction of specs, the namespaced keywords are being used more and more. This issue prevents streamlined edn->json->edn transformation. I think it should be reopened. IMO the 'lossy' method should never be a default one.
Unless we are willing to break existing code, I don't think it will be possible to change the default behavior.
I'm also not sure that extending IEncodeJS is the best solution, as it affects every call to clj->js, including calls to libraries which may rely on the ns-stripping behavior.
However, the attached patch allows you to make the decision on a per-call basis.
One quibble with the patch: perhaps it would be better to use kwargs style `(clj->js v reserve-namespaces true)` in line with `js->clj`?
Comment made by: lewang
How would extending IEncodeJS work if I want to only include namespaces sometimes, and don't want to change the default behaviour for all libraries I've included? If this is not possible, it seems this is not a valid solution so this problem.
I would like to propose a solution
(First I made a patch, but I saw that the jira does not accept any more attachments, so I published in the gist)
It allows to process keywords with any function
Dont break any existing code
Use named arguments (kwargs style)