Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is @JsName annotation required for every method?

I was trying to make NodeJs work with Kotlin for a HelloWorld example here.

As per the Kotlin JS documentation, @JsName annotation is required for overloaded methods. But in my experience, it is required even for a single method. Without this annotation the compiler adds a suffix to the method name as shown in the screenshot.enter image description here

Is this a bug? Or am I missing something?

I'm using Kotlin 1.1.0 module provided by NPM (please check the GitHub link above for the complete codebase if required).

like image 763
Pravin Sonawane Avatar asked Dec 05 '25 10:12

Pravin Sonawane


1 Answers

Kotlin compiler mangles names all functions, except for those which don't take any parameters. The motivation is: you can add overloaded function later, and this should not break binary compatibility of the code. As for @JsName: it depends on your goal. I don't know it and hence I can't tell whether you shuold put @JsName annotation on each method. If you are developing a library which is intended to be used from JavaScript, yes, you probably need to put @JsName on each function you want to be accessible from JavaScript. We are going to add another annotation which turns off mangling on entire class or file.

like image 108
Alexey Andreev Avatar answered Dec 08 '25 00:12

Alexey Andreev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!