This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-21
Channels
- # announcements (3)
- # aws (8)
- # babashka (14)
- # beginners (39)
- # biff (22)
- # cider (5)
- # clj-kondo (1)
- # cljs-dev (12)
- # cljsjs (4)
- # clojure (16)
- # clojure-europe (47)
- # clojure-germany (6)
- # clojure-uk (2)
- # clojurescript (36)
- # core-async (29)
- # cursive (19)
- # datalevin (14)
- # etaoin (10)
- # helix (1)
- # hyperfiddle (6)
- # introduce-yourself (5)
- # kaocha (43)
- # keechma (1)
- # lsp (7)
- # nbb (68)
- # new-channels (1)
- # off-topic (12)
- # pathom (11)
- # quil (14)
- # rdf (3)
- # re-frame (5)
- # reitit (6)
- # shadow-cljs (88)
quick question about inferring externs. The documentation says: > No hint required, externs inferred automatically >
(js/Some.Thing.coolFunction)
but does this also extend to objects create via js/f
calls? e.g. in (let [d (js/Date. x)] (.toLocaleDateString d))
would d
be correctly inferred to be a js object in the let clause?any more general advice on how to find places where externs are needed? :S the advanced compilation output is difficult to get information out of
I have a bunch of JS files from an ancient JS lib and I have a Clojure namespace that is wrapping parts of them
I get runtime errors such as
main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:145 TypeError: f.Sf is not a function
at c.<anonymous> (main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:2192:336)
at c.componentDidMount (main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:1647:332)
at uj (main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:147:464)
at Ej (main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:183:21)
at ea.unstable_runWithPriority (main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:27:21)
at Ac (main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:80:117)
at bd (main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:176:83)
at Fg (main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:168:106)
at main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:80:407
at ea.unstable_runWithPriority (main.0943529B7909B0E1E5BADC7C3B265449.js?-2052149777:27:21)
so I get the general area and I have tried annotating js/BlabBla
where needed, but to no avail.I guess Iām just gonna keep trying things out, but itās a shame that this externs inference step seems to revert my workflow to āfix bugs, recompile, repeat ad infinitumā like in the old days :P
but you didn't really answer my question. "I have a bunch of JS files from an ancient JS lib". how are you including them?
just entirely separately outside of the shadow-cljs build? or included in the build somehow? depending on how they are included affects how and what externs are needed
I guess, but I guess some are missed, likely by my own efforts. Gonna try your suggestion and add pseduo-names
should be easy to identify with pseudo names enabled. it'll just rename .methodName
properties to .$methodName$
or so
can I annotate using ^js/Timeline._Impl
(Timeline._Impl.prototype is where the troublesome methods are defined in the JS files) or do I need to use ^js
only like is used in the shadow-cljs documentation?
@simongray you can annotate like that but the end result is exactly the same as just ^js
. nothing else is gained. it doesn't magically gain knowledge of more properties or something
Iāve tried adding ^js everywhere it makes sense, but it doesnāt seem to do anything
I donāt think Iāve turned it off. I do get a warning for something in tick-rc6, but that doesnāt seem to affect the project.
hmm yeah something is definitely off in this project. If I just add
(defn yo [x]
(.whyUNOINFER x))
anywhere I don't get any inference warnings. on all my other projects I dowell, the issue surfaced when I recently updated the deps and I think I had to add that line due to some conflict between shadow-cljs and the latest version of tick
I don't get why that even affects inference in any way. its not even remotely close code wise
Are you saying that for once it wasnāt myself who fucked up, but it was actually a bug in shadow-cljs??
@simongray try 2.19.4
. at the very least you should be getting inference warnings again. and the tags should be respected and actually generate externs.
When the manual says shadow-cljs doesn't support CLJSJS "at all", does that mean it doesn't support dependencies that themselves rely on CLJSJS? Or does shadow-cljsjs
take care of that?
Never mind, reading the section again, it appears shadow-cljsjs
does take care of that.
Thanks!
If I want to add a file to shadow-cljsjs, is adding a dependency to a local copy and an exclusion enough or does shadow-cljsjs do something special to pull in shadow-cljsjs
?
thheller/shadow-cljsjs {:local/root "../../../shadow-cljsjs"}
thheller/shadow-cljs {:mvn/version "2.11.23" :exclusions [thheller/shadow-cljsjs] }
(Eventually I'll submit a PR but I want to get it working first)Okay, it appears that does work, I just forgot to replace the hyphen in my new file's name with an underscore.
@actuallyalys_slack you don't need to add files to shadow-cljsjs. just add the file to your own classpath (ie. one of your :paths
)
if my shadow project has a .cljc file on the path that contains the expression (println "x") should i expect to see "x" my terminal when i watch the build?
I feel like the answer is defiantly yes, yet i feel like that more or less what i'm not seeing in my current project so i'm trying to sanity check some concepts....
if i put a clj or cljc file on shadows path, it reads it because it's compiling the cljs to js using clj (correct me if i'm wrong). So it should absolutely see that file, and execute any expressions in it.
It is required. But yea, i assume so to.
Ah ok. Have you tried changing it to spit out a file or something instead? It could be something with the out being redirected or something. I would test something that won't be affected by that.
@U0DJ4T5U1 .cljc
means nothing. the question you need to answer in which context the thing is eval'd
when it is compiled as CLJS you will see the println when it is loaded in the JS runtime (eg. browser)
when it is compiled in CLJ you will see it during compilation (although where is not entirely clear since it goes to *out*
, which may not be where you are looking)
I'll check again, i don't see it in either context so i must have a path issue. I'll check what *out*
is bound to.
Thanks I'll check how it's loaded again to.
since regular CLJS compilation will not actually eval any CLJS code, it is just translated to JS
as for *out*
it defaults to wherever shadow-cljs was started. dunno how you are starting it
It runs via my terminal with the cmd line shadow-cljs watch app. When it compiles (println "hello") into js won't that run when the browser gets the .js file and interprets it?
Yep, that's what i understand happens as well. Ty. In the morning this will all seem as clear as day I'm sure