janvladimirmostert
02/02/2022, 12:55 PMfunction blah(...args) { console.log(args) }
running this:
blah`testing-${1}-${2}-${3}`
I get a list of parts (separators between ${}), pre/post-fix and values
0: (4) ['testing-', '-', '-', '', raw: Array(4)]
1: 1
2: 2
3: 3
length: 4
Is there anything planned for Kotlin that would allows taking a String template and splitting it up like that at compile time?
(similar to how to trimIndent() is processed at compile time, a compile time mechanism that can decompose a String template into its static and dynamic parts)
val blah = """
testing-${1}-$var2-${var3 + 1}
""".trimIndent()
blah.decompose() // outputting the static parts, listOf("testing", "-", "-", "") and the dynamic parts, listOf(1, var2, { var3 + 1}())
Just wondering how else one would replicate what lit-html, lit-element, uhtml and many of these JS frameworks are doing in pure JavaScriptGrégory Lureau
02/02/2022, 4:02 PMjanvladimirmostert
02/02/2022, 8:28 PMtemplate = arrayOf(
"<div>",
this.firstName,
"</div>",
"""<div><input value=" """,
this.lastName,
"""/></div>)
but that would about as usable as it looks
I'm not sure if KSP can do it, it certainly sits in the right place to do it and so does ArrowMeta
In order to do server side rendering with a JVM framework that then re-uses the same templates in the browser with ES6 template literals (which btw is blazing fast), you will need some sort of mechanism that can split String templates at compile time.
Short term I'll most likely need to build a compiler plugin to achieve this
A good read for some context:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
and:
https://viperhtml.js.org/hyperhtml/documentation/#introduction-0