Random idea: we may need a ClojureScript to JavaScript converter

Normally we write ClojureScript and compile to JavaScript to make sure it’s use immutable data and in functional styles. I’m NOT talking about that case.

In my case, I want to translate Clojure code into JavaScript/TypeScript directly. I don’t even need it to run correctly. I experimented my function in ClojureScript but my company is using JavaScript/TypeScript. What I need it a converter that turning my code into JavaScript and then I can annotate types.

Do you think it would be useful in your case?

For immutable data, maybe immer is a good choice. To convert:

(def a {:a 1})

(def b {assoc a :b 2})

into

import produce from "immer"

const a = {a: 1}

const b = produce(a, (draft) => {
  draft.b = 2
})

If you are just looking for lisp syntax and macros you can have a look at eslisp.

I haven’t spent a lot of time with it but it looks interesting, and I’ve been thinking about experimenting with adding some support for immutable data structures to it.

I think that idiomatic ClojureScript looks nothing like typical JavaScript/TypeScript code and therefore any attempt at translating it will end in something that is not idiomatic for either side. You are far better off writing TypeScript directly rather than writing it in CLJS, translating it and then “fixing” the problems. IMHO, YMMV.

After I finished my prototype in ClojureScript I just feel so lazy to handwrite the code again. However code generated from ClojureScript is so large I can use it directly.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.