Fork me on GitHub
#cljs-dev
<
2020-05-25
>
roman01la15:05:30

There's an interesting issue popped out with Closure library that may require a slight change in cljs's codegen. Story: Closure's Jsonp takes an instance of Uri class, which worked fine before, but now (dunno since when) it requires an instance of TrustedResourceUrl which in turn can be constructed from goog.string.Const type that takes a string literal or concatenation of string literals. Now Clojure's str emits [a,b,c].join('') which is not recognized by Closure Compiler as a static string concatenation.

roman01la15:05:07

My question is should we switch from [a,b,c].join('') to a + b + c?

roman01la15:05:54

Here's a repro https://gist.github.com/roman01la/c00bc4c8b7a3f9715e6bea47278cee4f Somehow Closure doesn't warn about Uri not matching required TrustedResourceUrl type But then at runtime you'll get [AssertionError]: Failure: expected object of type TrustedResourceUrl, got '123456' of type object but that's another story

thheller15:05:04

@roman01la you just need to construct the TrustedResourceUrl yourself. it is a bit annoying to construct but nobody is enforcing the closure rules for this so it doesn't matter that you construct it dynamically

thheller15:05:38

nothing will automatically turn Uri into a TrustedResourceUrl so it doesn't matter what str does

roman01la15:05:20

the issue is that (TrustedResourceUrl. (Const/from (str a b))) fails

roman01la15:05:32

because (str a b) emits [a,b].join('')

roman01la15:05:50

Closure exists complaining that [a,b].join('') is not a static concatenation

thheller16:05:19

yeah there is a helper fn somewhere to construct it

thheller16:05:29

with a really long annoying name

thheller16:05:56

goog.html.legacyconversions.safeUrlFromString

thheller16:05:29

goog.html.uncheckedconversions.safeUrlFromStringKnownToSatisfyTypeContract even more fun 😛

thheller16:05:13

goog.html.uncheckedconversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract

roman01la16:05:38

hm, those still require goog.string.Const as a param

roman01la16:05:37

ah I see, the param is justification

roman01la16:05:41

well... 😄

souenzzo16:05:49

Can't we open a issue in closure-compiler to make it understand that [a,b].join('') is a static string too?

roman01la16:05:17

yeah I think that would be best

thheller16:05:41

well [a,b] at not compile time constants so they won't go for that 😛

roman01la16:05:23

advanced mode is able to fold array join into a string though

thheller16:05:28

I mean you'd need to add the @const annotation probably

roman01la16:05:17

which means types info is already used for that