Can dart produce readable javascript libraries?

Issue

Goal

I would like to write a javascript library (framework), but need OOP and mixins.

Was giving a go to typescript, but it doesn’t support mixins (the handbook says it does, but the compiler/specifications has nothing that is mixin related).

Typescript

In typescript, the following code:

class Greeter {
    greeting: string;
    constructor(message: string) {
        this.greeting = message;
    }
    greet() {
        return "Hello, " + this.greeting;
    }
}

Compiles to:

var Greeter = (function () {
    function Greeter(message) {
        this.greeting = message;
    }
    Greeter.prototype.greet = function () {
        return "Hello, " + this.greeting;
    };
    return Greeter;
})();

Then clients can simply call:

var greeter = new Greeter("world");

Dart

Can dart do something similar? Can someone show how?

The main goal is that the produced javascript code is readable, preferably with all the dart extras residing in a different script.

I’ve seen this question and this answer, but neither seem to yield a readable JS file, like in the typescript example above.

Solution

As @SetLadd mentioned https://github.com/dart-lang/dev_compiler was built for this purpose (beside others). Some reported that they were able to produce usable output already a while back.

dev_compiler has a commandline tool dartdevc.

Answered By – Günter Zöchbauer

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

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