how do I escape backticks when executing raw JS in...
# javascript
j
how do I escape backticks when executing raw JS in KotlinJS? Example, this doesn't compile:
Copy code
js("""{ console.log(`test`) }""")
putting the backtick in a val also fails to compile
Copy code
val bt: Char = '`'
	js("""{ console.log(${bt}test${bt}) }""")
even though
Copy code
console.log(`test`)
is perfectly valid in the browser console.
e
Template literals are an ES6 feature. The parser used by
js("...")
is ES5 compliant.
j
mmm, that would make sense so this is then probably being ignored in my case
Copy code
js(IR) {
		binaries.executable()
		useEsModules()

		compilerOptions {
			target = "es2015"
			useEsClasses = true
		}
e
I recall discussing about the
js
validation a while back. Slack sucks at searching stuff damn. But yes, ES2015 there is not valid for that function unfortunately.
j
linking this here for completeness sake had no idea validation was being done on the content of
js(...)
https://kotlinlang.slack.com/archives/C0B8L3U69/p1721376461686789?thread_ts=1721295266.143179&cid=C0B8L3U69
e
Small correction, Rhino 1.5R3 supports ES3, not ES5.
I've opened a PR for the docs website. https://github.com/JetBrains/kotlin-web-site/pull/4701
a
It's true, however, we are going to rework the parser to support all the modern features.
K 3
🎉 2