I'm exporting a bunch of classes from a library us...
# javascript
d
I'm exporting a bunch of classes from a library using @JsExport and friends. For some reason, a private inner class in a completely separate module, that I haven't annotated to be exported in any form, is conflicting "Javascript name generated for this declaration clashes with another declaration". Any thoughts?
b
Recent versions of kotlin removed js namespacing so if you have a class with the same name in two different kotlin dependencies it might cause these clashes when both are transpiled to js
Don't quote me on this though 😀
d
Neither the outer class nor the inner class is a duplicate name. It's very strange.
Also, why would they remove the namespacing?
b
¯⁠\⁠_⁠(⁠ツ⁠)⁠_⁠/⁠¯ people complained that it looked weird from js side
d
I guess I can see that. I'm figuring out that trying to make a Kotlin/JS library accessible from JS is a tricky proposition and a little wild west.
On a different note it would be nice if the compiler automatically renamed overloaded functions, perhaps based on the parameters.
c
^ the compiler does, that's the
_a5d3z
postfix you can see on function names when you don't specify
@JsName
it's not really readable of course
d
Does it? Because the compiler fails for me saying that javascript name clashes for overloaded functions.
For exported classes.
Also, getting errors around the fact that extensions inside a class clash when the method name is the same even if the classes that are being extended are different. Here is an example:
Copy code
@ExperimentalJsExport
@JsExport
class TheClass() {

  fun TextLine.before(charIndex: Int): TextLine {
    ...
  }

  fun Pair<String, TextAttributes>.before(index: Int): Pair<String, TextAttributes> {
    ...  
  }
}
This causes an error ... but why?
JavaScript name (before) generated for this declaration clashes with another declaration: fun TextLine.before(charIndex: Int): TextLine
c
Interesting, maybe name mangling is disabled when using
@JsExport
? I'm pretty sure this compiles fine if you don't export it
That would make sense, mangling is very ugly when seen from JS