Fork me on GitHub
#shadow-cljs
<
2021-01-22
>
janezj15:01:10

(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.

isak15:01:02

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

thheller15:01:45

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

3
janezj18:01:08

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

thheller18:01:46

^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

thheller18:01:03

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

thheller18:01:41

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

janezj18:01:39

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?

thheller18:01:21

no you misunderstand how :advanced optimizations and externs work

thheller18:01:41

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

thheller18:01:07

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.

thheller18:01:42

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

thheller18:01:59

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

janezj22:01:54

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

thheller22:01:35

.shadow-cljs/builds/<build-id>/release/shadow.externs.js or so

gzmask19:01:18

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?

thheller19:01:00

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

thheller19:01:23

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.

gzmask20:01:58

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

gzmask22:01:35

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 : Unexpected token < in JSON at position 0
which suggests it’s looking at js instead

thheller22:01:24

that is controlled by :asset-path

thanks3 3