ClojureScript

clj->js trims the namespace prefix from keywords while writing them to string

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:

Description

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))

Activity

Hide
Vasile added a comment -

a better (working) fix: (keyword? x) (str (if (namespace x) (str (namespace x) "/")) (name x))

Show
Vasile added a comment - a better (working) fix: (keyword? x) (str (if (namespace x) (str (namespace x) "/")) (name x))
Hide
David Nolen added a comment -

I'd be willing to take a patch that allows this behavior to be configured.

Show
David Nolen added a comment - I'd be willing to take a patch that allows this behavior to be configured.
Hide
Niklas Närhinen added a comment -

Proposed fix

Show
Niklas Närhinen added a comment - Proposed fix
Hide
Niklas Närhinen added a comment -

Fixed version of patch

Show
Niklas Närhinen added a comment - Fixed version of patch
Hide
David Nolen added a comment -

Excellent, Niklas I don't see you on the list of contributors, please send in your Contributor Agreement, http://clojure.org/contributing, so we can apply the patch.

Show
David Nolen added a comment - Excellent, Niklas I don't see you on the list of contributors, please send in your Contributor Agreement, http://clojure.org/contributing, so we can apply the patch.
Hide
David Nolen added a comment -

I looked more closely at the clj->js source, the system is already customizable. We can't determine ahead of time how you might want to emit keywords and symbols - thus you can extend Keyword and Symbol to IEncodeJS yourself and get the desired behavior.

Show
David Nolen added a comment - I looked more closely at the clj->js source, the system is already customizable. We can't determine ahead of time how you might want to emit keywords and symbols - thus you can extend Keyword and Symbol to IEncodeJS yourself and get the desired behavior.

People

  • Assignee:
    Unassigned
    Reporter:
    Vasile
Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: