Is there a converter of Javascript to Dart?
Asked Answered
G

3

26

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

Garlan answered 10/10, 2011 at 23:0 Comment(9)
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.Nosy
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.Bonina
@Bonina Converting HTML to PHP is an identity conversion.Clariceclarie
I meant converting it to the original PHP that it came from.Bonina
@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.Mather
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.Bonina
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.Bonina
@Bonina - the use case is converting an existing javascript code base to Dart.Garlan
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.Midterm
G
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.

Graphic answered 9/4, 2012 at 14:13 Comment(4)
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" en.wikipedia.org/wiki/Dart_%28programming_language%29Marduk
@Clay thanks for the pointing that out, I'm not sure how I answered a different question (did the title change recently?)Graphic
Frog converts dart to js. The OP asks for js to dart.Sleepyhead
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.Apoenzyme
E
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.

Evangelinaevangeline answered 13/10, 2011 at 2:18 Comment(0)
F
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

Fondue answered 2/4, 2015 at 8:37 Comment(1)
Linked project is dead. There is archived version at github.com/dart-archive/ts2dartFondue

© 2022 - 2024 — McMap. All rights reserved.