JS to Dart Conversion


This is a 2 part question. I am not lazy, simply not fundamentally fluent enough in JS to convert an entire library while referencing the Dart Synonyms page it seems. The Dart:js documentation explains how to access the JS global object as shown in this snippet, but if i’m not mistaken it’s not what i’m looking for.

Q1: In the example snippet below, it wouldn’t increase Angular’s performance by utilizing Dart, correct?

var angular = context(['angular']);
var myapp = angular.module('myApp', ['ngResource','ngRoute']);

If I’m right, and I do need to convert libraries unavailable in Dart, jsparser and dart-synonym are really stumping me — I can’t find any simple documentation and when I look through the actual darts I get lost.

Dart Editor kicks an error when I try to run and build jsparser:

Unhandled exception:
‘file:///C:/Work Root/Dart/jsparser-ec65c9e7467f/jsparser.dart’: malformed type: line 26 pos 27: type ‘Options’ is not loaded
List args = new Options().arguments;

So I tried dart-synonym; it ran and built correctly, but then showed a clone of the Dart Synonyms page.

Q2: If accomplishing an automatic conversion is even possible, how do I use either of these?


Dart-synonym does not automatically convert other languages to Dart, it only provides a static synonym reference to allow manual conversion.

jsparser is meant to provide automatic conversion but the last commit is from more than a year ago. A lot has changed since then, and I doubt it will run without significant tweaks to the source. For instance, the Options class was removed a while back which is why you receive that malformed type error.

If you want to use Angular in Dart, you can use Google’s own port: AngularDart

Answered By – Pixel Elephant

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *