What are the situations where the compiler adds a ...
# javascript
g
What are the situations where the compiler adds a postfix to methods and properties when it generates them? Sometimes it happens in the generated code and then sometimes it doesn't. For the wrapper I'm making it would be nice to know when that is going to happen so that I can handle it appropriately
d
No idea how compiler makes the decision, but you can use @JsName annotation to enforce specific name (it's a bit cumbersome if you integrate with js a lot though).
g
Yeah seems like that is the best route to go
b
It’s not one simple rule, but the main is a suffix will be added if a function doesn’t have any parameters. Most of the related code is here https://github.com/JetBrains/kotlin/blob/master/js/js.frontend/src/org/jetbrains/kotlin/js/naming/NameSuggestion.kt
And you can control generating name using
JsName
annotation, you can find more info here https://kotlinlang.org/docs/reference/js-to-kotlin-interop.html#jsname-annotation
g
Ok thanks. More specifically what I need is how the name is generated for top-most methods and properties on classes. It looks like NameSuggestion.kt is is exactly what I need. If you know of any other code I look at for that please let me know
b
If you just want control names
JsName
is your choice. Also, note names for public API are stable enough and it’s ok to rely on them if you don’t mind to have such names with suffixes.