3

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).

Pravin Sonawane
  • 1,803
  • 4
  • 18
  • 32

1 Answers1

3

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.

Alexey Andreev
  • 1,980
  • 2
  • 17
  • 29
  • 1
    Thanks. I think it would be helpful if you can add 'Kotlin compiler mangles names all functions, except for those which don't take any parameters.' to the documentation. – Pravin Sonawane May 31 '17 at 06:32