shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
janezj 2021-01-22T15:12:10.010200Z

(defn parse-dtime
([parser stime]
   (let
    [d (js/Date. 0 0 0 0 0 0 0)
     n (.strictParse parser stime d  
--------------^-----------------------------------------------------------------
Cannot infer target type in expression (. parser strictParse stime d)
How to tell compiler, that parser is instance of goog.i18n.DateTimeParse. DateTimeParse.strictParse is from goog library and is renamed during advanced compilation.

isak 2021-01-22T15:39:02.010300Z

Try to switch [parser stime] to [^js parser stime]. Does that work?

thheller 2021-01-22T15:54:45.010500Z

if its safe to rename you can do [^goog parser stime]. ^js is fine too but prevents the renaming

1
janezj 2021-01-22T18:04:08.010800Z

Thanks, code is compiled without errors and it is working properly. But I don't understand a shadow-cljs and compiler's magic powers ^js => strictParse is not renamed, and there is a code strictParse = function(a, b, c) # how compiler knows that strictParse must be exposed, what happens when there are more classes with strictParse? how compiler ^goog.i18n.DateTimeParse, ^goog => in both cases, result is the same, method is renamed and it works properly. I just don't get it how ^goog provides enough information

thheller 2021-01-22T18:11:46.011Z

^goog just tells externs inference that it does NOT need to collect externs for this and as such the closure compiler is free to rename it

thheller 2021-01-22T18:12:03.011200Z

^js creates externs for strictParse and as such closure will not rename it

thheller 2021-01-22T18:12:41.011400Z

completely fine to just use ^js since the code size difference will be so tiny it won't matter

janezj 2021-01-22T18:24:39.011600Z

I know about the size, I just want to understand my code. the renaming must happen on two places in my code and in the google library. So compiler will rename all strictParse (marked as renamable) globally, not case by case, so ^goog means all "attachments - properties, methods" of this object. This is undocumented feature?

thheller 2021-01-22T18:33:21.011800Z

no you misunderstand how :advanced optimizations and externs work

thheller 2021-01-22T18:33:41.012Z

the CLJS compiler generates identical code with ^js or ^goog. it does not affect the generated JS at all.

thheller 2021-01-22T18:34:07.012200Z

externs then control whether the closure compiler is allowed to rename something or not. the CLJS compiler is out of the picture at that time.

thheller 2021-01-22T18:34:42.012400Z

so as far as the closure compiler is concerned there is no such thing as the closure library or CLJS code. it just sees a bunch of JS code

thheller 2021-01-22T18:34:59.012600Z

and the renaming it does is documented, just not sure where

gzmask 2021-01-22T19:00:18.014800Z

hello! pretty new to cljs: for browser target I tried to eval a quoted code list into Clojurescript runtime. while cljs.js/eval works with simple things like [1 2 3, anything that needs core NS stuff will tell me they are undefine with warning: i.e

(cjs/eval
 (cjs/empty-state)
 (parse-string "(cljs.core/println \"ehhlo bootstrapped\")")
 {:eval cjs/js-eval
  :source-map true
  :context :expr}
 (fn [r] r))
but if I choose browser target, start the browser, connect to cljs-repl, and change to bootstrap target midflight, it works . If I choose bootstrap target, browser fails to connect to my cljs-repl; Can I just use browser or bootstrap target instead of the mid-flight switch hack to make it work?

thheller 2021-01-22T19:55:00.015700Z

if you want to do self-hosted stuff you need to do the setup described here https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html

thheller 2021-01-22T19:56:23.016600Z

don't know what kind of hackery you are trying but browser+bootstrap are supposed to be 2 separate builds. it does not work otherwise.

gzmask 2021-01-22T20:04:58.017400Z

ah, I see, they are meant to be separated and call in certain orders. That’s probably why my hack kinda work. Thanks!

janezj 2021-01-22T22:25:54.017500Z

So for every cljs file shadow-cljs generates a .js file, but the file is not affected by annotations, where are all externs written?

gzmask 2021-01-22T22:27:35.018300Z

is source map path hardcoded? I set my output-dir to be out and I am getting

DevTools failed to load SourceMap: Could not parse content for <http://127.0.0.1:8080/js/cljs-runtime/goog.dom.nodetype.js.map>: Unexpected token &lt; in JSON at position 0
which suggests it’s looking at js instead

thheller 2021-01-22T22:27:35.018400Z

.shadow-cljs/builds/&lt;build-id&gt;/release/shadow.externs.js or so

thheller 2021-01-22T22:28:24.019200Z

that is controlled by :asset-path

1