ClojureScript

Advanced compiler renames console.groupCollapsed.

Details

Description

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 io.pedestal.app.util.platform
(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]
  (log-exceptions
   #(do
     (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) {};

Activity

Hide
David Nolen added a comment -

We could probably track Google Closure more closely, but we don't as this usually requires a considerable amount of testing to make sure that things don't break. We also need to make our own release of Google Closure since we depend on third party libraries. Stuart Sierra is more or less in charge of this process. We'll probably do another bump again soon but there's no rush as this particular issue is easily worked around.

Show
David Nolen added a comment - We could probably track Google Closure more closely, but we don't as this usually requires a considerable amount of testing to make sure that things don't break. We also need to make our own release of Google Closure since we depend on third party libraries. Stuart Sierra is more or less in charge of this process. We'll probably do another bump again soon but there's no rush as this particular issue is easily worked around.
Hide
David Nolen added a comment -

this can be worked around by supplying an externs file.

Show
David Nolen added a comment - this can be worked around by supplying an externs file.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: