This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-09
Channels
- # aws (3)
- # babashka (48)
- # babashka-sci-dev (1)
- # beginners (143)
- # calva (62)
- # clj-kondo (6)
- # clj-otel (3)
- # cljs-dev (59)
- # cljsrn (4)
- # clojure (39)
- # clojure-austin (5)
- # clojure-europe (60)
- # clojure-losangeles (1)
- # clojure-nl (2)
- # clojure-romania (4)
- # clojure-spec (3)
- # clojure-uk (2)
- # clojurescript (32)
- # datomic (17)
- # events (3)
- # figwheel-main (4)
- # graphql (3)
- # gratitude (2)
- # holy-lambda (52)
- # introduce-yourself (3)
- # jobs (1)
- # juxt (5)
- # kaocha (2)
- # lsp (33)
- # nyc (3)
- # off-topic (9)
- # other-languages (4)
- # overtone (1)
- # portal (21)
- # reitit (2)
- # remote-jobs (5)
- # shadow-cljs (65)
- # tools-deps (2)
- # xtdb (8)
@timothypratley that is definitely part of the default svg externs, so should be fine. do you have a repro?
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.
Here's a minimal example
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
It doesn't happen if the svg is not wrapped in an atom... it seems that perhaps the deref
is preventing the extern.
The first version I posted wasn't in an atom
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
The first example was bad because I didn't set the infer-externs
flag on
as I said this is not an inference issue. nothing to infer here. it is part of the default externs.
I believe you, I'm just relaying my observations :))
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.
¯\(ツ)/¯
When you say "works fine in shadow-cljs" do you mean this example is O.K. for you under advanced compilation??
Oh, that's surprising to me! o_O
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
https://github.com/google/closure-compiler/commit/c3ab4a23b55e8c0537eb1c26bdaffa9c355cd43c
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.SVGLength
methods are broken in the same fashion.
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???
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
however the infer-externs warnings you won't get since shadow-cljs loads the default externs and doesn't warn about properties contained there
(it gets those via Compiler.getExternProperties
, just a set of strings it will then ignore regarding the warnings)
still doesn't explain the different behavior though. that really only affects the warnings, and neither the inferred externs nor the used externs
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
it's not so hard to check - https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/externs.clj#L388-L395
actually it doesn't appear that SVG externs are included by default? I don't see them in the closure-compiler-externs?
#object[com.google.javascript.jscomp.SourceFile 0x2c708a7e "externs.zip//svg.js"]
from the default externs. its in there
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^^ it does contain webkit_dom.js
(->
(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.the only explination I can find is we are calling different class implementations in Closure (for svg.js missing)
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
I guess it might be a version thing then? shadow-cljs is on closure-compiler v20220301
(sort (set (map #(.getName %) (com.google.javascript.jscomp.CommandLineRunner/getDefaultExterns))))
contains externs.zip//svg.js
ClojureScript is on 0.0-20211011-0726fdeb, quite different, I'll try with your version.
oh... got it. v20210808
I'll change that.
Yup just confirming I see svg.js with that version dependency
I'll confirm that compiling the example works now.
starnge that the file is 5 years old. guess they just didn't include it until recently
hahahaha
yeah 😕 😕
confirmed ClojureScript has no errors when upgraded the compiler version to same as Shadow.