Advanced compiler renames console.groupCollapsed.



In the lein-cljsbuild simple sample app, I enabled advanced compilation and changed the example.hello namespace to the following:

(ns example.hello)

;; taken unchanged from
(defn log-exceptions [f & args]
  (try (apply f args)
       (catch js/Error e
         (.groupCollapsed js/console "Caught exception" e)
         (.log js/console "Was applying function\n" f)
         (.log js/console "With arguments" (pr-str args))
         (.log js/console "Re-throwing error...")
         (.groupEnd js/console)
         (throw e))))

(defn ^:export greet [name]
     (js/alert (str "Hello " name))
     (throw (js/Error "whatever")))))

Then ran lein cljsbuild once, loaded the project in my browser (google chrome) and in the browser call example.hello.greet("me")

This results in an error, but not the one we expect. Instead we get TypeError: Object #<Console> has no method 'wb'.

This is because the log-exceptions function was compiled to the following. Notice how console.groupCollapsed has been renamed to console.wb.

function mf(a, b) {
  try {
    return $b.b(a, b)
  }catch(c) {
    c instanceof Error && (console.wb("Caught exception", c), console.log("Was applying function\n", a), console.log("With arguments", lf.j(P([b], 0))), console.log("Re-throwing error..."), console.groupEnd()), e(c)

I did a little more digging, and found this recent commit in the google closure history. It adds an extern to the list of default externs for groupCollapsed. It's pretty new (Jun 7) so presumably the clojurescript compiler is still using an older version.

I think all that needs to be done is to update the version of closure used?

As a workaround, add the two lines below to your externs file.

function Console() {};
Console.prototype.groupCollapsed = function(var_args) {};



Vote (0)
Watch (0)


  • Created: