5 ms·
Can this be made to work with Kotlin?
by cutler 8y ago
Can this be made to work with Kotlin?
- cromwellian 8y agoSomeone at some point (was it an intern or OSS contributor? I forgot, or maybe I'm misremembering) made a prototype Kotlin->Java J2CL code transpiler. Basically, you just need a Kotlin backend that generates Java source instead of Bytecode. Kotlin hired the guy who wrote the TeaVM, so I think they are focusing on bytecode translation approaches to JS. We considered this for J2CL but ultimately decided to use JDT parsing from Source, because with bytecode you lose some information you have in the Java AST that requires reconstructing it. Also, Kotlin's runtime is quite large, and if you were trying to compile Kotlin -> J2CL you'd want a customized runtime that relies on JsInterop and Elemental2 to get the smallest possible code size.
- wtetzner 8y agoDoesn't Kotlin already have a JS backend?
- cromwellian 8y agoYes, but it's somewhat bloated. J2CL+Closure optimizes code better. KotlinJS requires inclusion of a bulky runtime. Last time I checked, it doesn't do dead code elimination well (on the runtime). Closure Compiler was built to optimize even untyped JS, and the way hybrid J2CL/JS apps work, extern files assist the compiler in "safely" doing global optimizations. It's not perfect, and you can confuse the compiler (but you can do the same thing in Java with reflection + Proguard), but it works well enough if you know what to watch out for.