Kotlin to TypeScript data-structure transpiler
Uses tree-sitter via Node.js bindings with Kotlin grammar
Prototype - proof of concept
- The focus lies on transpiling data classes or POJOs. It is not planned to try to convert any logic.
- Simplicity (usage of the tree-sitter AST is even easier than using regular expressions?)
- Resistant to syntax changes (compared to regular expressions)
- Easy to adapt to different source (and output?) languages
Kotlin input:
data class Apple(
var id: Long?,
val color: String,
val size: Int,
val updated: LocalDate
)
Generated TypeScript output: (At least that is what is planned, we are not there yet)
interface IApple {
readonly id: number | null
readonly color: string
readonly size: number
readonly updated: Date
}
export class Apple implements IApple {
constructor (
public readonly id: number | null,
public readonly color: string,
public readonly size: number,
public readonly updated: Date,
) {}
copy(update: Partial<Apple>): Apple {
return /* new object with updated fields */
}
static from(obj: IApple): Apple {}
}
... tbd ...
This project currently uses shadow-cljs to compile ClojureScript. This makes it very easy to add npm dependencies and requires nearly zero configuration.
- (Optionally)
shadow-cljs server start
Speeds up the following commands shadow-cljs watch :test
to compile the :test target (and recompile on changes)
Pros:
- Simple
Cons:
- Prone to unforseen syntax changes
Pros:
- Integrated into compilation via kapt, no extra setup (but not with IntelliJ's build system)
Cons:
- Integrated into compilaton, can't be run on it's own
kapt
the Kotlin annotation processing tool is quite slow- The Java annotation processing API is not easy to use with Kotlin sources