This issue is somewhat to be expected if you're going to use `js->clj`. This issue has nothing to do with ClojureScript compiler versions - you just got lucky before. Google Closure will collapse properties, but some of these collapsed properties are going to be used to determine protocol membership. That's it.
I suggest just avoiding `js->clj` and using your own simple helper for recursively converting JSON into Clojure values. Changing the (admittedly questionable) behavior of `js->clj` will only lead to more breakage. HTH, David On Sat, Oct 15, 2016 at 11:43 AM, John Szakmeister <j...@szakmeister.net> wrote: > I've been using ClojureScript rather successfully for a year now, but > ran into an interesting issue recently. > > I've discovered that js->clj isn't quite working as expected. After > quite a bit of tearing things down and apart, I discovered it was one > of the keys in some JSON data coming back from the server that looks > like: > > "Bi": 8 > > And the resultant error would be: > > No protocol method IEncodeClojure.-js->clj defined for type > object: [object Object] > > I don't know why this particular sequence caused a problem, but I > ended trying to vary things a bit just to see what happens. If I use: > > "Bi": 0 > > I don't see the issue. Any non-zero value though does seem to bring > the problem about for this sequence of letters though. Similarly, I > tried varying the two letter sequence, and discovered two others with > similar problems: Ai, and ba. The latter brought about a different > error: > > [object Object] is not ISeqable > > And the pattern with the value needing to be non-zero follows. If the > value associated with the key is 0, then I don't see a problem. > > As I wasn't seeing this issue before, I backpedaled my version of the > ClojureScript compiler and eventually found that 1.9.56 didn't seem to > sufffer from the problem. After checking out ClojureScript, and > bisecting more I found that commit > bcf60ce194e5292fbc5c4b2d89dfc5a7b886b94c is when the behavior changed > from behaving correctly to behaving badly, but I think it's a false > positive. > > I then created a much smaller test case, with no other libraries > involved. This time it's a different set of values that are broken: > > * "Ta" with a non-zero value gives: [object Object] is not ISeqable > > * "Ub" with a non-zero value gives: No protocol method > IEmptyableCollection.-empty defined for type object: [object Object] > > * "Wb" with a non-zero value gives: No protocol method > IEncodeClojure.-js->clj defined for type object: [object Object] > > If I back up to before the previously mentioned commit, I can still > cause the problem, though the letter sequences change a bit. > > Also, this only appears to happen with advanced optimizations. With > no optimizations or with whitespace optimizations, there's no issues. > So it smells like a strange interaction between the ClojureScript > runtime and the compiler. > > Has anyone seen an issue like this before? Does anyone have any ideas > what is going on? We have these short keys in our data, and it'd be > pretty painful to make them something else (especially since the names > are meaningful to those in the know, despite them being cryptic--they > refer to bit settings on various motors). > > I'd be happy to file a ticket, if that's what needs to get done too. > > Thanks! > > -John > > PS Here's the code I used to hunt down problematic keys: > > (def alphabet [\a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t > \u > \v \w \x \y \z \A \B \C \D \E \F \G \H \I \J \K \L \M \N \O > \P > \Q \R \S \T \U \V \W \X \Y \Z]) > > (enable-console-print!) > > (defn ^:export main-page [] > (println"Starting...") > (doseq [c1 alphabet > c2 alphabet > i (range 256)] > (let [s (str "{\"" c1 c2 "\": " i "}")] > (try > ;; (prn :parse-s (js/JSON.parse s)) > ;; (prn :js-clj-parse (js->clj (js/JSON.parse s))) > (js->clj (js/JSON.parse s)) > (catch js/Error e > (println "didn't work" s (str e)))) > )) > (println "Done!")) > > Then you can observe the results from the JS console. > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.