Is it possible to detect somehow which backend (le...
# javascript
r
Is it possible to detect somehow which backend (legacy or ir) was used to compile the Kotlin/JS code?
b
It's specified in gradle metadata so you could parse that
s
In terms of generated JS: If you see stdlib imported with the name “Kotlin” and names are mangled with base64 hash like this
println_s8jyv4$
— it is a legacy compiler.
In terms of kotlin libraries: IR is published as klib, legacy — jar with JS inside.
r
In fact I needed to detect how a data class is represented in JS code (legacy - plain fields, ir with
@JsExport
- defined properties with getters and setters). For know I've created this "hack":
Copy code
val prototype = js("Object").getPrototypeOf(obj)
    val prototypeProps: Array<String> = js("Object").getOwnPropertyNames(prototype)
    val isLegacy = prototypeProps.filterNot { prototype.propertyIsEnumerable(it) }.toSet() == setOf("constructor")
It seems to work for my use cases 😉
BTW any chance of resolving https://youtrack.jetbrains.com/issue/KT-41162 ? It's a nightmare when it comes to integration with external JS libraries.
b
@Robert Jaros we are considering it
1