cljs-dev

ClojureScript compiler & std lib dev, https://clojurescript.org/community/dev
2020-05-25T15:17:30.245Z

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.

2020-05-25T15:18:07.245800Z

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

2020-05-25T15:34:54.246900Z

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

thheller 2020-05-25T15:57:04.248200Z

@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

thheller 2020-05-25T15:57:38.248900Z

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

2020-05-25T15:58:20.249700Z

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

2020-05-25T15:58:32.250200Z

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

2020-05-25T15:59:50.250800Z

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

thheller 2020-05-25T16:00:19.251100Z

yeah there is a helper fn somewhere to construct it

thheller 2020-05-25T16:00:29.251400Z

with a really long annoying name

thheller 2020-05-25T16:00:56.251800Z

goog.html.legacyconversions.safeUrlFromString

2020-05-25T16:01:10.252Z

oh lol

thheller 2020-05-25T16:02:29.252200Z

goog.html.uncheckedconversions.safeUrlFromStringKnownToSatisfyTypeContract even more fun 😛

thheller 2020-05-25T16:03:13.252400Z

goog.html.uncheckedconversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract

2020-05-25T16:06:38.252700Z

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

2020-05-25T16:07:37.253100Z

ah I see, the param is justification

2020-05-25T16:07:41.253300Z

well... 😄

souenzzo 2020-05-25T16:16:49.255500Z

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

2020-05-25T16:17:17.255800Z

yeah I think that would be best

thheller 2020-05-25T16:25:41.256800Z

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

2020-05-25T16:26:23.257400Z

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

thheller 2020-05-25T16:26:28.257600Z

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

2020-05-25T16:27:17.258300Z

which means types info is already used for that