Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anyone gotten the Dart dev_compiler to work?

I wanted to experiment using the Dart dev compiler that generates ES6. I installed it

pub global activate -sgit [email protected]:dart-lang/dev_compiler.git

Then I created a simple Dart class:

library wat;

class Person {
    String first_name;
    String last_name;
    int amountOfAwesomeness;

    Person(this.first_name, this.last_name, [this.amountOfAwesomeness = 0]);
    String get name => "$first_name $last_name is awesome:$amountOfAwesomeness";
}

Then I tried to compile it:

dartdev -o ./ person.dart

but I get an exception:

Unhandled exception:
'package:dev_compiler/src/dependency_graph.dart': Failed assertion: line 60 pos 16: 'false' is not true.
#0      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:27)
#1      SourceGraph.nodeFromUri.<anonymous closure> (package:dev_compiler/src/dependency_graph.dart:60:16)
#2      _CompactLinkedHashMap.putIfAbsent (dart:collection-patch/compact_hash.dart:193) 
#3      SourceGraph.nodeFromUri (package:dev_compiler/src/dependency_graph.dart:50:29)
#4      Compiler.Compiler (package:dev_compiler/devc.dart:76:38)
#5      main (http://localhost:60878/devc.dart:42:22)
#6      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:253)
#7      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:142)

Seems like a simple example like this should work. What am I doing wrong? Is the dev_compiler just not ready to try out yet?

like image 721
Rob Avatar asked Mar 09 '15 23:03

Rob


2 Answers

UPDATE:

The dart development compiler is being built into pub in Dart version 1.24. See here https://github.com/dart-lang/sdk/blob/master/CHANGELOG.md#tool-changes-1

If you want to use it, just use Dart 1.24 and add to your pubspec.yaml the following

  web:
    compiler:
      debug: dartdevc # Use DDC for pub serve
      release: dartdevc # Use DDC for pub build

ORIGINAL:

Answering my own question since I got it working. The main problem above is the output directory. If you do not specify an output directory, it appears to do nothing. So you must specify a name for the output directory. The current directory apparently does not work. An absolute path does seem to work.

Examples that work: dartdevc -o mydir input.dart dartdevc -o /path/to/dir input.dart

Example that does not work: dartdevc -o ./ input.dart

The output for the above example is:

var person;
(function(exports) {
  'use strict';
  class Person extends dart.Object {
    Person(first_name, last_name, amountOfAwesomeness) {
      if (amountOfAwesomeness === void 0)
        amountOfAwesomeness = 0;
      this.first_name = first_name;
      this.last_name = last_name;
      this.amountOfAwesomeness = amountOfAwesomeness;
    }
    get name() {
      return `${this.first_name} ${this.last_name} is awesome: ${this.amountOfAwesomeness}`;
    }
  }
  // Exports:
  exports.Person = Person;
})(person || (person = {}));
//# sourceMappingURL=person.js.map
like image 63
Rob Avatar answered Sep 20 '22 11:09

Rob


It's super early. A lot of stuff doesn't work yet (including basic libraries), and a lot of what you see will change.

With that said, you can look at:

https://github.com/dart-lang/dev_compiler/blob/master/test/sunflower/sunflower.html

to get a feel for how things are linked together and you can run in Chrome Canary (and eventually more stable versions as ES 6 lands).

like image 39
Vijay Menon Avatar answered Sep 22 '22 11:09

Vijay Menon