[JS IR] Fix referencing Kotin variables in inline JS code
Fixed by outlining JS code that uses Kotlin variables making usages of these locals explicit and preventing bugs due to one-sided variable renaming. This prevents using Kotlin variables as lvalue in JS code.
This commit is contained in:
@@ -12,3 +12,19 @@ internal fun <T : Enum<T>> enumValuesIntrinsic(): Array<T> =
|
||||
@PublishedApi
|
||||
internal fun <T : Enum<T>> enumValueOfIntrinsic(@Suppress("UNUSED_PARAMETER") name: String): T =
|
||||
throw IllegalStateException("Should be replaced by compiler")
|
||||
|
||||
|
||||
/**
|
||||
* Implements annotated function in JavaScript.
|
||||
* [code] string must contain JS expression that evaluates to JS function with signature that matches annotated kotlin function
|
||||
*
|
||||
* For example, a function that adds two Doubles:
|
||||
*
|
||||
* @JsFun("(x, y) => x + y")
|
||||
* fun jsAdd(x: Double, y: Double): Double =
|
||||
* error("...")
|
||||
*
|
||||
* Code gets inserted as is without syntax verification.
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
|
||||
internal annotation class JsFun(val code: String)
|
||||
Reference in New Issue
Block a user