r/Clojure • • Aug 18 '22

ClavaScript: a ClojureScript syntax to JS compiler

Introducing ClavaScript, a ClojureScript syntax to JavaScript compiler!

The primary use case for clava (its short name, not to be confused with Calva) is to produce JavaScript using ClojureScript syntax while producing ultra-small bundle sizes, by leveraging the JS platform directly. Clava does not protect you from the pitfalls of JS (mutability, equality), but lets you use the concepts you already know from ClojureScript and maps them more or less directly to JS where this makes sense. It comes with a standard library which has many of the core functions you know: map-indexed , for example, works like you would expect, but returns a mutable JS array instead of an immutable vector.

Repo: https://github.com/clavascript/clavascript

Npm: npm install clavascript

Read Differences with ClojureScript for... well, the differences with ClojureScript.

It has support for async/await and JSX.

Clava is open to contribution, especially in the area of porting core functions.

An example of a SolidJS app written using Clava:

https://clavascript.github.io/demos/clava/solidjs/ (source)

Give it a spin and let us know what you think.

81 Upvotes

10 comments sorted by

View all comments

1

u/lucywang000 Aug 20 '22

May I ask how does it compare with nbb? https://github.com/babashka/nbb

4

u/Borkdude Aug 20 '22

You may! nbb is a ClojureScript interpreter for Node.js (based on SCI). You can run scripts with it directly and nbb is batteries included: it has libraries that you will commonly need for scripting. Nbb preserves CLJS semantics and what you get there are the data structures you're used to with CLJS. ClavaScript is a more general tool which compiles directly to JS and does _not_ include CLJS data structures: it returns plain JS objects and arrays in most cases. The benefit of doing so is that you can write JS using CLJS syntax and get really small bundle sizes, at the cost of not using the CLJS data structures.

1

u/noomey Aug 20 '22

I've been closely following your work on ClavaScript on twitter and I admit I find it a bit intriguing as I'm still not 100% clear on when I should use this compared to ShadowCLJS (as a confirmed js/ts developer and clojure/cljs beginner). I feel like I'm getting a better grasp thanks to your comment though, and now I'm wondering wether this proposition https://github.com/tc39/proposal-record-tuple could help ClavaScript to better "mimic" the immutable data structures of Clojure?

1

u/Borkdude Aug 20 '22

ClavaScript and Cherry are currently experimental. If you want to build a production application I would currently recommend shadow-cljs.