Has anyone got a Dart dev_compiler to work?

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

pub global activate -sgit git@github.com :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) 

It seems like such a simple example should work. What am I doing wrong? Is dev_compiler not ready yet to try?

+6
source share
2 answers

UPDATE:

A dart development compiler is built into the 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 the following to your pubspec.yaml

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

ORIGINAL:

Answering my own question since I got his job. The main problem above is the output directory. If you do not specify an output directory, it does nothing. Therefore, you must provide a name for the output directory. The current directory does not seem to be working. The absolute way seems to work.

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

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

The output for the above example:

 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 
+7
source

This is super early. Many things are not working yet (including the base libraries), and much of what you see will change.

With that said, you can see:

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

to understand how things relate to each other, and you can run in Chrome Canary (and, ultimately, more stable versions with ES 6).

+2
source

Source: https://habr.com/ru/post/983552/


All Articles