cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.45k stars 159 forks source link

Kotlin support #713

Closed LifeIsStrange closed 2 years ago

LifeIsStrange commented 2 years ago

That would be amazing :)

lgrignon commented 2 years ago

Hello @LifeIsStrange that would be amazing indeed :) but is totally out of scope sorry. If any MR shows up, I would be glad to review :) What about https://kotlinlang.org/docs/js-overview.html ?

LifeIsStrange commented 2 years ago

Unfortunately I won't be able to submit PRs.

The thing is the scope is somewhat reduced as Kotlin is fully interoperable with Java and transpile to JS natively extremely well. In essence, with JSweet and KotlinJS, both Java and Kotlin transpile to JS/TS. The issue is to test interoperability between the JS generated by Java and Kotlin.As for separate source files, since the generated codes are mostly independant I don't think there would be many issues regarding interop but that is something to test. The biggest issue is about unifying the build process (guidelines on how to make a project with kotlin and java files both transpile to JS in a single gradle command) and more importantly about IDE interop and hybrid Java in Kotlin. If a kotlin function has a variable that instanciate a Java class, the goal would be for JSweet to have a Kotlin compiler plugin (as can be "easily" built with this library https://github.com/arrow-kt/arrow ) and to emit js transpilation by JSweet only for the Java classes in Kotlin code. This step would happen before regular Kotlin Js transpilation. Then maybe the Kotlin Js transpilation would need to refer to the JSweet generated JS/TS (best world). An easier alternative would be to generate js for detected Java classes in Kotlin files. and put the generated code into a JS ES/commonjs module. That way the developper could include the Java code in the Kotlin code by specifying to the Kotlin compiler that the code come from a JS module (kotlin can already import JS code). Once there would be support for this, Kotlin compiler devs would simply have to detect the use of JSweet (via a flag or other) and so not to throw errors at Java code in Kotlin, when targeting JS.

That is the idea, I understand that it has some complexities and that it is for now out of scope. Since this is highly in the interest of both Java and Kotlin ecosystem (given how prominent the web platform is), I'm sure that Kotlin compiler devs would be interested in helping and giving guidance, as eventually they'll have to prioritarize this for true multiplatform. @elizarov @udalov