26

Is there an automatic converter of javascript code to Dart? Or is it too soon?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
ripper234
  • 222,824
  • 274
  • 634
  • 905
  • 2
    Nothing yet, Google are working on an IDE called Brightly at the moment which will compile Dart to ECMAScript but I'm not sure about the other way round. – Clive Oct 10 '11 at 23:01
  • 2
    Incredibly unlikely. That's like converting HTML to PHP. The only code that could be feasibly converted from JS to Dart is code that was generated by Dart in the first place, and even that would be challenging. – mellamokb Oct 10 '11 at 23:02
  • 1
    @mellamokb Converting HTML to PHP is an identity conversion. – Paŭlo Ebermann Oct 10 '11 at 23:06
  • I meant converting it to the original PHP that it came from. – mellamokb Oct 10 '11 at 23:08
  • @mellamokb, language translators are pretty common. Most of the time, they aren't meant to produce human readable code, but it has been done successfully. – mikerobi Oct 11 '11 at 15:21
  • 2
    OK. Pardon my ignorance, I want to learn something here :-) You want JavaScript in the end anyway, so you're going to convert and then convert back... what's the point? Since Dart is *compiled* to JavaScript, a better example would be converting `Assembly` to `C`. Sure, you could do it, but good luck doing anything useful with the code at the `C` level. You've lost all of the semantic information, plus you have optimizations and many ambiguities from compilation. You might as well just change the Assembly directly at that point or hunt down the original source. – mellamokb Oct 11 '11 at 15:58
  • Or directed toward OP: What's the use case? I understand converting from ASP to PHP like Joel Spolsky does, because they are at the same semantic level. – mellamokb Oct 11 '11 at 16:03
  • 4
    @mellamokb - the use case is converting an existing javascript code base to Dart. – ripper234 Oct 11 '11 at 17:42
  • I wouldn't be suprised to see Google extend it's Closure Compiler with a Dart backend. It already does most of the necessary work, all that's left is writing the Dart backend. – Patrick Oct 12 '11 at 11:11

3 Answers3

9

There's a recent tool called JSParser and does all its magic using Dart itself, that is the parser is written in Dart.

On a related noted there is Frog (and it comes with the standard SDK) which converts Dart to Javascript, it's also written in Dart making it a good showcase for the language.

Chris S
  • 64,770
  • 52
  • 221
  • 239
  • Link is broken. And wikipedia indicates that FROG is a Dart-> Javascript compiler (not the other way around) : "Frog was the second instance of a Dart-to-JavaScript compiler" http://en.wikipedia.org/wiki/Dart_%28programming_language%29 – Clay Nichols Jun 04 '12 at 20:03
  • @Clay thanks for the pointing that out, I'm not sure how I answered a different question (did the title change recently?) – Chris S Jun 13 '12 at 09:50
  • 3
    Frog converts dart to js. The OP asks for js to dart. – noɥʇʎԀʎzɐɹƆ Dec 18 '16 at 22:53
  • From the JSParser repo, the last commit is dated on 2013-02-23, so I assume this whole discussion is quite outdated in general and there's nothing as plug-and-play for js-2-dart right now. – boldnik Apr 28 '20 at 22:04
5

Probably too soon.

I believe Dart came out earlier this week. As some of the others have mentioned, there might never be a converter for JavaScript->Dart. I asked another question if it was/will be possible to call JavaScript code from Dart, there is no official answer on this. Another thing I have heard someone ask for on Google Plus is a CoffeeScript->Dart translator. I don't know what the feasibility of this is, but would be a nice way to stick with the more traditional environments, until Dart can be adopted.

Community
  • 1
  • 1
TMB
  • 4,683
  • 4
  • 25
  • 44
2

Angular 2 team is building one.

Why isn’t Angualr 2 just built in Dart?

Answer: the Angular folks want to deliver a great framework for BOTH Javascript and Dart.

Dart generates great Javascript for browsers, but we have work to do to generate reusable Javascript libraries.

The Angular team needs to generate reusable Javascript libraries.

quoted from http://work.j832.com/2015/03/angulartsjsatdartwtf.html

Their Javascript (Typescript) to Dart transpiler can be found at https://github.com/angular/angular/tree/master/tools/transpiler/src

Community
  • 1
  • 1
user7610
  • 25,267
  • 15
  • 124
  • 150