我想尝试使用生成ES6的Dart dev编译器.我安装了它
pub global activate -sgit git@github.com:dart-lang/dev_compiler.git
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个简单的Dart类:
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";
}
Run Code Online (Sandbox Code Playgroud)
然后我试着编译它:
dartdev -o ./ person.dart
Run Code Online (Sandbox Code Playgroud)
但我得到一个例外:
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)
Run Code Online (Sandbox Code Playgroud)
看起来像这样一个简单的例子应该有效.我究竟做错了什么?dev_compiler还没准备好试用吗?
更新:
dart开发编译器正在Dart版本1.24中的pub中构建.请参见https://github.com/dart-lang/sdk/blob/master/CHANGELOG.md#tool-changes-1
如果你想使用它,只需使用Dart 1.24并添加到pubspec.yaml以下
web:
compiler:
debug: dartdevc # Use DDC for pub serve
release: dartdevc # Use DDC for pub build
Run Code Online (Sandbox Code Playgroud)
原版的:
自从我开始工作以来回答我自己的问题.上面的主要问题是输出目录.如果您没有指定输出目录,它似乎什么都不做.因此,您必须为输出目录指定名称.当前目录显然不起作用.绝对路径似乎确实有效.
有效的例子:
dartdevc -o mydir input.dart
dartdevc -o /path/to/dir input.dart
不起作用的示例:
dartdevc -o ./ input.dart
上例的输出是:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
455 次 |
| 最近记录: |