0

I have the following in a cljs file

(defn load-coords []
  (let [svg (.getSVGDocument (. js/document (getElementById "game-board")))
        s (ef/from svg
      :coords "#circles circle"
      (fn [circle]
        {:x (.-baseVal.value (.-cx circle))
         :y (.-baseVal.value (.-cy circle))
         }))]
.....

When I try to compile the project using :optimisations :advanced I get the following error message when running the project js in the browser

TypeError: document.getElementById(...).eh is not a function

Seems like .getSVGDocument might be getting "mangled" in the compiler is there any way to "exclude" things like this from happening other than externs of :optimisation :simple?

I'm not even sure how to include it in the externs as it is part of the js element specifications...like how do I write that in the externs?

Kendall
  • 5,065
  • 10
  • 45
  • 70

1 Answers1

2

getSVGDocument is not part of the externs in Closure-compiler. However, you can provide your own extern to correct the problem. See https://stackoverflow.com/a/21122560/1211524

You'll need to know what type of element you will be adding the definition to. For instance, if you wanted to add it to the HTMLElement type, it might look something like:

/**
 * @fileoverview
 * @externs
 */

/**
 * @return {HTMLElement} this should really be SVGElement -
 *    but closure-compiler doesn't recognize that type
 */
HTMLElement.prototype.getSVGDocument = function();
Community
  • 1
  • 1
Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57