Fork me on GitHub
#cljs-dev
<
2022-05-09
>
thheller05:05:23

@timothypratley that is definitely part of the default svg externs, so should be fine. do you have a repro?

timothypratley06:05:57

It's reproducible in my app 🙂 - it needs the ^js or it breaks: (.getScreenCTM ^js @svg) If it helps I can make a standalone project.

timothypratley06:05:54

Here's a minimal example

thheller06:05:29

hmm odd. works fine in shadow-cljs with just the default externs and nothing inferred. wonder if maybe there is a problem in the default externs loading in cljs.main

timothypratley06:05:31

It doesn't happen if the svg is not wrapped in an atom... it seems that perhaps the deref is preventing the extern.

timothypratley06:05:19

The first version I posted wasn't in an atom

thheller06:05:22

normally if the closure compiler cannot identify the type of a thing it considers all externs. so as long as its somewhere it shouldn't get renamed

thheller06:05:44

I still see the renaming in the first example?

timothypratley06:05:06

The first example was bad because I didn't set the infer-externs flag on

thheller06:05:11

var t=document.createElementNS("","svg");console.log(t.g());

thheller06:05:28

as I said this is not an inference issue. nothing to infer here. it is part of the default externs.

timothypratley06:05:43

I believe you, I'm just relaying my observations :))

timothypratley06:05:30

The behavior I see is: without the atom, and without infer-externs, it breaks. without the atom and with infer-externs, it works, with the atom and with infer-externs, it breaks.

timothypratley06:05:30

When you say "works fine in shadow-cljs" do you mean this example is O.K. for you under advanced compilation??

timothypratley06:05:08

Oh, that's surprising to me! o_O

thheller06:05:36

with or without atom doesn't matter either

dnolen13:05:10

somewhat skeptical about this but you have reproducer can you create JIRA ticket, probably not going to block this for release because I know people use SVG and I haven't heard of this one before, maybe because of the atom being involved

dnolen14:05:17

oh, but getScreenCTM maybe this was added later, that happens occasionally of course

thheller15:05:36

I checked. added 5 years ago, should be fine.

dnolen15:05:33

ok I'm skeptical, is this true for all SVG methods or just this one thing?

thheller15:05:05

contains .getScreenCTM several times

dnolen15:05:54

I mean about the report not the inclusion of the extern 🙂

dnolen15:05:14

if all SVG methods are broken something wrong w/ extern inclusion likely

dnolen15:05:29

if just this one, then something weirder

timothypratley16:05:25

All (3) methods of SVGElement fail for me:

(defn main []
  (let [svg (atom (js/document.createElementNS "" "svg"))]
    (println "BBox")
    (try
      (js/console.log (.getBBox @svg))
      (catch :default ex
        (println "FAIL:" ex)))
    (println "CTM")
    (try
      (js/console.log (.getCTM @svg))
      (catch :default ex
        (println "FAIL:" ex)))
    (println "ScreenCTM")
    (try
      (js/console.log (.getScreenCTM @svg))
      (catch :default ex
        (println "FAIL:" ex)))))

=>

BBox
webapp-main.js:234 FAIL: #object[TypeError TypeError: ab(...).Wb is not a function]
webapp-main.js:234 CTM
webapp-main.js:234 FAIL: #object[TypeError TypeError: ab(...).Xb is not a function]
webapp-main.js:234 ScreenCTM
webapp-main.js:234 FAIL: #object[TypeError TypeError: ab(...).Yb is not a function]
I will try some other types and see about those.

timothypratley17:05:24

SVGLength methods are broken in the same fashion.

timothypratley17:05:23

The atom thing makes sense to me... without the atom, the call sites will be "poisoned" and infer externs will create an extern. I agree with Thomas that in either case (with or without infer externs) these cases seem like the should just work... I'm also confused why shadowcljs would work but using clojurescript directly would not... is there an extra thing that shadow does wrt the default externs? Could it be a Closure compiler version dependency thing???

thheller17:05:02

I can't think of anything shadow-cljs does with the default externs that regular doesn't. just the CommandLineRunner/getDefaultExterns or whatever that is called

thheller17:05:26

however the infer-externs warnings you won't get since shadow-cljs loads the default externs and doesn't warn about properties contained there

thheller17:05:02

(it gets those via Compiler.getExternProperties, just a set of strings it will then ignore regarding the warnings)

thheller17:05:18

still doesn't explain the different behavior though. that really only affects the warnings, and neither the inferred externs nor the used externs

timothypratley17:05:13

Interesting. I don't see anywhere in the ClojureScript code a call to getExternProperties -- there is a call to getDefaultExterns which is marked as deprecated o_O but as you say it shouldn't matter at all. I've updated the 3 examples as zip projects on the ticket: https://clojure.atlassian.net/browse/CLJS-3374

thheller17:05:29

getExternProperties is only used be shadow-cljs yes

👍 1
dnolen17:05:56

note the warning issue is separate the externs being missing

dnolen18:05:53

actually it doesn't appear that SVG externs are included by default? I don't see them in the closure-compiler-externs?

thheller18:05:23

#object[com.google.javascript.jscomp.SourceFile 0x2c708a7e "externs.zip//svg.js"] from the default externs. its in there

timothypratley18:05:54

On ClojureScript master branch:

(set (map #(.getName %) (CommandLineRunner/getDefaultExterns)))
=>
#{"externs.zip//w3c_touch_event.js"
  "externs.zip//w3c_trusted_types.js"
  "externs.zip//w3c_audio.js"
  "externs.zip//w3c_rtc.js"
  "externs.zip//wicg_trust_token.js"
  "externs.zip//web_animations.js"
  "externs.zip//web_app_manifest.js"
  "externs.zip//es5.js"
  "externs.zip//w3c_permissions.js"
  "externs.zip//w3c_selection.js"
  "externs.zip//nonstandard_fileapi.js"
  "externs.zip//w3c_xml.js"
  "externs.zip//nonstandard_audio.js"
  "externs.zip//w3c_mediacapabilities.js"
  "externs.zip//w3c_requestidlecallback.js"
  "externs.zip//w3c_geolocation.js"
  "externs.zip//w3c_abort.js"
  "externs.zip//google_legacy.js"
  "externs.zip//w3c_midi.js"
  "externs.zip//w3c_clipboard.js"
  "externs.zip//w3c_worklets.js"
  "externs.zip//w3c_device_sensor_event.js"
  "externs.zip//ie_event.js"
  "externs.zip//w3c_serviceworker.js"
  "externs.zip//w3c_indexeddb.js"
  "externs.zip//w3c_fileapi.js"
  "externs.zip//es6.js"
  "externs.zip//w3c_screen_orientation.js"
  "externs.zip//w3c_css3d.js"
  "externs.zip//w3c_composition_event.js"
  "externs.zip//w3c_speech.js"
  "externs.zip//url.js"
  "externs.zip//w3c_event.js"
  "externs.zip//w3c_gamepad.js"
  "externs.zip//ie_dom.js"
  "externs.zip//w3c_batterystatus.js"
  "externs.zip//nonstandard_anim_timing.js"
  "externs.zip//fido.js"
  "externs.zip//html5.js"
  "externs.zip//w3c_keyboardlock.js"
  "externs.zip//w3c_selectors.js"
  "externs.zip//wicg_floc.js"
  "externs.zip//intl.js"
  "externs.zip//es6_collections.js"
  "externs.zip//es3.js"
  "externs.zip//w3c_pointer_events.js"
  "externs.zip//webkit_usercontent.js"
  "externs.zip//whatwg_encoding.js"
  "externs.zip//w3c_anim_timing.js"
  "externs.zip//w3c_elementtraversal.js"
  "externs.zip//webgl.js"
  "externs.zip//nonstandard_console.js"
  "externs.zip//deprecated.js"
  "externs.zip//wicg_resizeobserver.js"
  "externs.zip//w3c_navigation_timing.js"
  "externs.zip//flash.js"
  "externs.zip//w3c_referrer_policy.js"
  "externs.zip//webkit_dom.js"
  "externs.zip//gecko_event.js"
  "externs.zip//w3c_clipboardevent.js"
  "externs.zip//iphone.js"
  "externs.zip//nonstandard_rtc.js"
  "externs.zip//v8.js"
  "externs.zip//webgl2_compute.js"
  "externs.zip//nonstandard_selection.js"
  "externs.zip//w3c_event3.js"
  "externs.zip//ie_css.js"
  "externs.zip//wicg_compression_stream.js"
  "externs.zip//wicg_uach.js"
  "externs.zip//w3c_dom1.js"
  "externs.zip//ie_vml.js"
  "externs.zip//w3c_screen_wake_lock.js"
  "externs.zip//fetchapi.js"
  "externs.zip//mediakeys.js"
  "externs.zip//w3c_dom3.js"
  "externs.zip//webkit_notifications.js"
  "externs.zip//w3c_css.js"
  "externs.zip//w3c_netinfo.js"
  "externs.zip//gecko_css.js"
  "externs.zip//page_visibility.js"
  "externs.zip//w3c_payment_request.js"
  "externs.zip//nonstandard_indexeddb.js"
  "externs.zip//w3c_permissions_policy.js"
  "externs.zip//gecko_dom.js"
  "externs.zip//streamsapi.js"
  "externs.zip//es6_proxy.js"
  "externs.zip//webkit_event.js"
  "externs.zip//nonstandard_navigation_timing.js"
  "externs.zip//w3c_geometry1.js"
  "externs.zip//wicg_file_system_access.js"
  "externs.zip//webkit_css.js"
  "externs.zip//webstorage.js"
  "externs.zip//w3c_eventsource.js"
  "externs.zip//webassembly.js"
  "externs.zip//webgl2.js"
  "externs.zip//window.js"
  "externs.zip//w3c_pointerlock.js"
  "externs.zip//whatwg_console.js"
  "externs.zip//gecko_xml.js"
  "externs.zip//intersection_observer.js"
  "externs.zip//w3c_vibration.js"
  "externs.zip//w3c_webcrypto.js"
  "externs.zip//w3c_dom2.js"
  "externs.zip//mediasource.js"
  "externs.zip//w3c_range.js"
  "externs.zip//w3c_dom4.js"}
^^ This list does not include svg.js

timothypratley19:05:07

^^ it does contain webkit_dom.js

thheller19:05:58

thats super weird. why does my contain svg.js?

timothypratley19:05:01

(->
    (filter
      (fn [s]
        (= "externs.zip//webkit_dom.js" (.getName s)))
      (CommandLineRunner/getDefaultExterns))
    first parse-externs index-externs
    (find 'console) first meta)
returns nil though... because the result of index-externs does not contain 'console.

timothypratley19:05:38

the only explination I can find is we are calling different class implementations in Closure (for svg.js missing)

timothypratley19:05:43

It does say when I navigate to the definition that it is decompiling Java 8 .class file which surprises me in light of the "Closure Compiler now requires OpenJDK 11", I wonder if it is somehow related to that /shrug

thheller19:05:44

I guess it might be a version thing then? shadow-cljs is on closure-compiler v20220301

thheller19:05:28

(sort (set (map #(.getName %) (com.google.javascript.jscomp.CommandLineRunner/getDefaultExterns)))) contains externs.zip//svg.js

timothypratley19:05:39

ClojureScript is on 0.0-20211011-0726fdeb, quite different, I'll try with your version.

thheller19:05:50

closure compiler, not closure library

timothypratley19:05:16

oh... got it. v20210808

timothypratley19:05:24

I'll change that.

timothypratley19:05:40

Yup just confirming I see svg.js with that version dependency

timothypratley19:05:51

I'll confirm that compiling the example works now.

thheller19:05:39

starnge that the file is 5 years old. guess they just didn't include it until recently

timothypratley19:05:47

confirmed ClojureScript has no errors when upgraded the compiler version to same as Shadow.

timothypratley19:05:31

I'll submit a patch to update the compiler version [DONE]

1