I have a delegated property name
in kotlin code. In compiled javascript code, it is transformed into an object property name_pw16at$_0
. My experiments show that this suffix is independent of the type of delegate and the actual type of property. In the official documentation describes how delegated properties are represented in jvm classes: with the suffix $delegate
added to the real name of property, but there is no information about javascript case. So, can i find out, which algorithm is used to generate this suffix in javascript compiled code?
Hi! You can change the name of the property with @JsName annotation but unfortunately it doesn’t work with delegated properties. I’ve created an issue in the tracker: https://youtrack.jetbrains.com/issue/KT-35580
Hi!
Unfortunately, right, for JS we don’t have such convention for backing fields for delegated properties, moreover, we can’t use so simple convention due to the fact that EcmaScript 5, which we target now, doesn’t have builtin private fields. So we have to guarantee somehow this name will not clash with another one in a derived class.
Note we don’t provide any guarantee about names of declarations that are not part of public API. And the algorithm could be changed between releases.
Also it will work differently in the new compiler backend for JS.
In short, it calculates suffix using the “fully qualified name” of property.
For details, you can take a look this points
InitializerUtils#generateInitializerForDelegate
-
InitializerUtils#generateInitializerForDelegate
at InitializerUtils.java:52 -
StaticContext#getNameForBackingField
at StaticContext.java:378 -
NameSuggestion.getPrivateMangledName
at NameSuggestion.kt:324