Can dart produce readable javascript libraries?
Asked Answered
V

2

9

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.

Very answered 19/1, 2016 at 0:58 Comment(1)
You probably want to use the new Dart dev compiler (DDC). It's not yet beta from what I can tell but one of its goals is to output readable js. github.com/dart-lang/dev_compiler/blob/master/README.mdHalford
E
6

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.

Eerie answered 19/1, 2016 at 6:58 Comment(0)
B
2

The Dart Dev Compiler (DDC) is an experimental development tool and transpiler.
It is at a very early stage today.
Initial commit was on Nov 17, 2014.

DDC attempts to map to idiomatic EcmaScript 6 (ES6) as cleanly as possible.

Maybe someday there will be the day when we can say with confidence: "It is a mature development tool and transpiler" but currently DDC is still in a very early stage.

Bairam answered 19/1, 2016 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.