Kotlin/js template literals


Are there any support for transpiling into javascript template literals?

i.e., something like:

foo`hello ${42}`

where foo is a function receiving an array as its first argument which will contain the list of chunks between interpolations and the interpolated values.
(in this case foo will be invoked with the arguments: (["hello "], 42) )


I am not sure why you care how the expressions look in the output.


I’m curious, what’s your use case?


I would like to port the following library to kotlin:

Unlike react, angular or veu, this library does not use any special file formats or have a complex building requirements, it is fast, simple, small and starting to get traction lately so it seems like a great fit for kotlin/js projects

but in order to do so - it will be best to have template literals support…


I have to disagree that it is a great fit for Kotlin. On the contrary, it is designed to make use of syntactic sugar specific to JS, which means the idea does not extend to any language that does not have the same feature.

The problem is not so much that we cannot compile Kotlin into JS code containing template literals. We just need the compiler to output the desugared version i.e. foo(["hello"], 42) and it will work just fine. The problem is that the Kotlin language does not have template literals. That means that even if we could output template literals, we would still be unable to write Kotlin code that looks anywhere near what we would write in JS.

If you want a convenient way of building DOM trees in Kotlin, then you are better off looking for libraries designed to make use of Kotlin specific features, such as kotlinx.html.


The reason I believe that this library is a great fit to port to Kotlin is that the library depends only on standard Javascript without any extensions - unlike most of the other client frameworks.

Should kotlin support any standard javascript capability is of course debatable… But in this case a simple interop function - something like template(foo, "${42}") similar to the js("<code>") or even a special @Template annotation that makes the compiler output the required code could have worked just fine without adding any new keywords to the language

About the kotlinx.html style - I believe there must be a better way - in my eyes it looks and feel complex and less maintainable in addition to be yet another abstraction over html and css that the programmer need to consider…