项目作者: t-gebauer

项目描述 :
Prototype: Kotlin to TypeScript data-structure transpiler
高级语言: Clojure
项目地址: git://github.com/t-gebauer/replant.git
创建时间: 2020-07-25T14:25:21Z
项目社区:https://github.com/t-gebauer/replant

开源协议:MIT License

下载


replant

Kotlin to TypeScript data-structure transpiler

Uses tree-sitter via Node.js bindings with Kotlin grammar

Status

Prototype - proof of concept

Goals

  • 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

Examples

Data classes

Kotlin input:

  1. data class Apple(
  2. var id: Long?,
  3. val color: String,
  4. val size: Int,
  5. val updated: LocalDate
  6. )

Generated TypeScript output:
(At least that is what is planned, we are not there yet)

  1. interface IApple {
  2. readonly id: number | null
  3. readonly color: string
  4. readonly size: number
  5. readonly updated: Date
  6. }
  7. export class Apple implements IApple {
  8. constructor (
  9. public readonly id: number | null,
  10. public readonly color: string,
  11. public readonly size: number,
  12. public readonly updated: Date,
  13. ) {}
  14. copy(update: Partial<Apple>): Apple {
  15. return /* new object with updated fields */
  16. }
  17. static from(obj: IApple): Apple {}
  18. }

Enums

… tbd …

Development

This project currently uses shadow-cljs to compile ClojureScript. This makes it very easy to add npm dependencies and requires nearly zero configuration.

  1. (Optionally) shadow-cljs server start Speeds up the following commands
  2. shadow-cljs watch :test to compile the :test target (and recompile on changes)

Comparison to alternative implementations

Regular Expressions

Pros:

  • Simple

Cons:

  • Prone to unforseen syntax changes

Annotation Processor

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