Git Product home page Git Product logo

javascript-to-clojurescript's Introduction

If you like what I do, consider supporting my work via donation

JavaScript to ClojureScript translator

This tool tries to translate as much JavaScript code into ClojureScript as it can. Keep in mind that it might fail or the result will be non-idiomatic Clojure code due to substantial differences between languages.

e.g. Clojure explicitly distincts global and local vars, but JavaScript does not

(def x 1) ;; global
(let [x 2] ;; local
  (/ x 2))

Clojure's data structures are immutable by defalt

(let [x {}]
  [(assoc x :y 1) x])
  ;; [{:y 1} {}]

Use for educational purpose.

How to contribute

If something is not translated properly, file an issue

javascript-to-clojurescript's People

Contributors

aliaksandr-s avatar roman01la avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

javascript-to-clojurescript's Issues

JSON objects not recognized

I am not an advanced developer otherwise I would attempt a fix myself...

Through trial and error using your amazing translator, I whittled down one of the possible reasons why the large block of js code I tried was not working, it seems to not recognise the JSON formatting, as follows;

const assetData = { "type": "MyType", "item": mydata };

It would be great if you could add a translation rule to deal with JSON

Keep up the good work

Thanks

a[0]=1;

var a=[];
a[0]=1;
(def a #js [])

(set! (aget a 0) 1)

cljs.core.ExceptionInfo@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:2073:47
cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:2076:72
cljs.core.ex_info@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:2075:177
cljs.analyzer.error.cljs$core$IFn$_invoke$arity$3@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:2653:92
cljs.analyzer.error@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:2652:203
cljs.analyzer.error.cljs$core$IFn$_invoke$arity$2@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:2652:479
cljs.analyzer.error@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:2652:112
@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:2952:105
g@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:1998:213
a@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:2013:361
cljs.analyzer.analyze_seq_STAR_@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:3195:142
cljs.analyzer.analyze_seq_STAR__wrap@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:3195:306
cljs.analyzer.analyze_seq.cljs$core$IFn$_invoke$arity$4@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:3199:446
cljs.analyzer.analyze_seq@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:3196:214
cljs.analyzer.analyze_form@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:3235:243
cljs.analyzer.analyze_STAR_@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:3238:360
cljs.analyzer.analyze.cljs$core$IFn$_invoke$arity$4@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:3242:275
cljs.analyzer.analyze@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:3239:295
x/I<@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:13022:34
x@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:13022:232
x/</<@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:13029:167
cljs.core.trampoline.cljs$core$IFn$_invoke$arity$1@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:1944:144
cljs.core.trampoline.cljs$core$IFn$_invoke$arity$variadic@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:1944:289
cljs.core.trampoline@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:1943:302
cljs.js.compile_str_STAR_@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:13015:353
cljs.js.compile_str.cljs$core$IFn$_invoke$arity$5@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:13035:34
cljs.js.compile_str@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:13032:313
j2c.core.evalExpr@https://roman01la.github.io/javascript-to-clojurescript/compiler.js:13089:60
handleJSChange@webpack:///./src/ui.js?:92:14
debounce/</id<@webpack:///./src/ui.js?:72:7

Wrong translation direct Object prototype

I am trying to translate Blotter JS sample from the site to Clojurescript

var text = new Blotter.Text("observation", {
  family : "'EB Garamond', serif",
  size : 27,
  fill : "#171717",
  paddingLeft : 40,
  paddingRight : 40
});

from the Translator I get the result (I add js/ by myself)

(def text
  (new (.Text js/Blotter)
    "observation"
    #js {:family "'EB Garamond', serif", :size 27, :fill "#171717", :paddingLeft 40, :paddingRight 40}))

which should be

(def text
  (new js/Blotter.Text 
    "observation"
    #js {:family "'EB Garamond', serif", :size 27, :fill "#171717", :paddingLeft 40, :paddingRight 40}))

the translated one is wrong because the Blotter is called the constructor new Blotter() (I think, correct me if I'm wrong).

ForOfStatement is not implemented

Just want to say that this tool has saved me time and time again. Really appreciate it existing.
Hope you have the time and interest to keep evolving it.

Here's something that popped up as a limitation for me. Error: ForOfStatement is not implemented
A sample of code that triggered it

  var deviceId;
  for (deviceInfo of deviceInfos) {
    if (deviceInfo.kind === 'videoinput' && deviceInfo.label === 'Reincubate Camo') {
      deviceId = deviceInfo.deviceId
      break;
    }
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.