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.
My question is should we switch from [a,b,c].join('')
to a + b + c
?
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
@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
nothing will automatically turn Uri
into a TrustedResourceUrl
so it doesn't matter what str
does
the issue is that (TrustedResourceUrl. (Const/from (str a b)))
fails
because (str a b)
emits [a,b].join('')
Closure exists complaining that [a,b].join('')
is not a static concatenation
yeah there is a helper fn somewhere to construct it
with a really long annoying name
goog.html.legacyconversions.safeUrlFromString
oh lol
goog.html.uncheckedconversions.safeUrlFromStringKnownToSatisfyTypeContract
even more fun 😛
goog.html.uncheckedconversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract
hm, those still require goog.string.Const
as a param
ah I see, the param is justification
well... 😄
Can't we open a issue in closure-compiler
to make it understand that [a,b].join('')
is a static string too?
yeah I think that would be best
well [a,b]
at not compile time constants so they won't go for that 😛
advanced mode is able to fold array join into a string though
I mean you'd need to add the @const
annotation probably
which means types info is already used for that