OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// A library for compiling Dart code and manipulating analyzer parse trees. | 5 /// A library for compiling Dart code and manipulating analyzer parse trees. |
6 library pub.dart; | 6 library pub.dart; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 | 23 |
24 /// Returns [entrypoint] compiled to JavaScript (or to Dart if [toDart] is | 24 /// Returns [entrypoint] compiled to JavaScript (or to Dart if [toDart] is |
25 /// true). | 25 /// true). |
26 /// | 26 /// |
27 /// By default, the package root is assumed to be adjacent to [entrypoint], but | 27 /// By default, the package root is assumed to be adjacent to [entrypoint], but |
28 /// if [packageRoot] is passed that will be used instead. | 28 /// if [packageRoot] is passed that will be used instead. |
29 /// | 29 /// |
30 /// If [inputProvider] and [diagnosticHandler] are omitted, uses a default | 30 /// If [inputProvider] and [diagnosticHandler] are omitted, uses a default |
31 /// [compiler.CompilerInputProvider] that loads directly from the filesystem. | 31 /// [compiler.CompilerInputProvider] that loads directly from the filesystem. |
32 /// If either is provided, both must be. | 32 /// If either is provided, both must be. |
33 Future<String> compile(String entrypoint, {String packageRoot, | 33 Future<String> compile(String entrypoint, { |
34 bool toDart: false, compiler.CompilerInputProvider inputProvider, | 34 String packageRoot, |
35 bool toDart: false, | |
36 bool minify: true, | |
37 compiler.CompilerInputProvider inputProvider, | |
35 compiler.DiagnosticHandler diagnosticHandler}) { | 38 compiler.DiagnosticHandler diagnosticHandler}) { |
nweiz
2013/10/29 23:18:53
What are the criteria for whether a set or paramet
Bob Nystrom
2013/10/29 23:53:25
Good question. I pulled the trigger here because i
| |
36 return new Future.sync(() { | 39 return new Future.sync(() { |
37 var options = <String>['--categories=Client,Server', '--minify']; | 40 var options = <String>['--categories=Client,Server']; |
38 if (toDart) options.add('--output-type=dart'); | 41 if (toDart) options.add('--output-type=dart'); |
42 if (minify) options.add('--minify'); | |
43 | |
39 if (packageRoot == null) { | 44 if (packageRoot == null) { |
40 packageRoot = path.join(path.dirname(entrypoint), 'packages'); | 45 packageRoot = path.join(path.dirname(entrypoint), 'packages'); |
41 } | 46 } |
42 | 47 |
43 // Must either pass both of these or neither. | 48 // Must either pass both of these or neither. |
44 if ((inputProvider == null) != (diagnosticHandler == null)) { | 49 if ((inputProvider == null) != (diagnosticHandler == null)) { |
45 throw new ArgumentError("If either inputProvider or diagnosticHandler " | 50 throw new ArgumentError("If either inputProvider or diagnosticHandler " |
46 "is passed, then both must be."); | 51 "is passed, then both must be."); |
47 } | 52 } |
48 | 53 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 } | 182 } |
178 | 183 |
179 String toString() => "$message\n$stackTrace"; | 184 String toString() => "$message\n$stackTrace"; |
180 } | 185 } |
181 | 186 |
182 /// An exception thrown when dart2js generates compiler errors. | 187 /// An exception thrown when dart2js generates compiler errors. |
183 class CompilerException extends ApplicationException { | 188 class CompilerException extends ApplicationException { |
184 CompilerException(String entrypoint) | 189 CompilerException(String entrypoint) |
185 : super('Failed to compile "$entrypoint".'); | 190 : super('Failed to compile "$entrypoint".'); |
186 } | 191 } |
OLD | NEW |