ClojureScript and closure: how to protect attributes from renaming by closing

I'm trying to create some kind of HTML5 drawing, and I ran into a problem with advanced compilation mode. I would like to demonstrate this using the mozDash property of mozDash browsers (although this question is quite important for the attribute optimization function) https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D#Gecko-specific_attributes

The javascript code canvas.mozDash = ... can be expressed as [1] ( (set! (.-mozDash canvas) ...) or [2] (aset canvas "mozDash" ...) in Clojurescript.

I used [1] earlier, and it worked in most cases, however, with the mozDash attribute, the mozDash identifier disappeared as a result of extended compilation. So I tried [2], and it seems that the mozDash identifier mozDash saved using the aset option.

My questions:

  • Is this the intended difference between these designations?
  • Why is the behavior different ([1] and [2]) for (.-fillStyle canvas) ?

I suspect that standard HTML properties are protected by default, while non-standard properties (e.g. mozDash ) are not supported.

+4
source share
1 answer

The closure compiler is allowed to rename attributes with direct access that are not specified in externs or export.

See https://developers.google.com/closure/compiler/docs/api-tutorial3#propnames

In particular, (aset x "y" z) converted to x["y"] = z , which is freed from minimization, and (set! (.-yx) z) translates to xy = z and can be minimized, if xy is not specified as extern or exported.

I would suggest that the mozDash property is not specified in the externs files that you use for Canvas.

+5
source

Source: https://habr.com/ru/post/1486574/


All Articles