Index: pkg/compiler/lib/compiler.dart |
diff --git a/pkg/compiler/lib/compiler.dart b/pkg/compiler/lib/compiler.dart |
index 82b8c3b85b42f5ffd88908b3c65bb0528f7c4ca7..100153dd85b9f990bb384222179d1681b6819da7 100644 |
--- a/pkg/compiler/lib/compiler.dart |
+++ b/pkg/compiler/lib/compiler.dart |
@@ -65,6 +65,30 @@ typedef EventSink<String> CompilerOutputProvider(String name, |
typedef void DiagnosticHandler(Uri uri, int begin, int end, |
String message, Diagnostic kind); |
+/// Information resulting from the compilation. |
+class CompilationResult { |
+ /// `true` if the compilation succeeded. |
floitsch
2015/01/05 10:39:33
Specify that "succeeded" means "valid program" and
Johnni Winther
2015/01/05 13:54:10
Done.
|
+ final bool isSuccess; |
+ |
+ /// The compiler object used for the compilation. |
+ /// |
+ /// Note: The type of [compiler] is implementation dependent and may vary. |
+ /// Use only for debugging and testing. |
+ final compiler; |
+ |
+ /// The compilation resulted in this exception. |
+ final exception; |
+ |
+ /// The compilation resulted in an exception with this stack trace. |
+ final trace; |
+ |
+ CompilationResult(this.compiler, {this.isSuccess: true}) |
+ : exception = null, trace = null; |
+ |
+ CompilationResult.error(this.exception, this.trace) |
+ : compiler = null, isSuccess = false; |
+} |
+ |
/** |
* Returns a future that completes to a non-null String when [script] |
* has been successfully compiled. |
@@ -80,14 +104,15 @@ typedef void DiagnosticHandler(Uri uri, int begin, int end, |
* as the compiler may create multiple files to support lazy loading |
* of libraries. |
*/ |
-Future<String> compile(Uri script, |
- Uri libraryRoot, |
- Uri packageRoot, |
- CompilerInputProvider inputProvider, |
- DiagnosticHandler handler, |
- [List<String> options = const [], |
- CompilerOutputProvider outputProvider, |
- Map<String, dynamic> environment = const {}]) { |
+Future<CompilationResult> compile( |
+ Uri script, |
+ Uri libraryRoot, |
+ Uri packageRoot, |
+ CompilerInputProvider inputProvider, |
+ DiagnosticHandler handler, |
+ [List<String> options = const [], |
+ CompilerOutputProvider outputProvider, |
+ Map<String, dynamic> environment = const {}]) { |
if (!libraryRoot.path.endsWith("/")) { |
throw new ArgumentError("libraryRoot must end with a /"); |
} |
@@ -103,13 +128,8 @@ Future<String> compile(Uri script, |
packageRoot, |
options, |
environment); |
- // TODO(ahe): Use the value of the future (which signals success or failure). |
- return compiler.run(script).then((_) { |
- String code = compiler.assembledCode; |
- if (code != null && outputProvider != null) { |
- code = ''; // Non-null signals success. |
- } |
- return code; |
+ return compiler.run(script).then((bool success) { |
+ return new CompilationResult(compiler, isSuccess: success); |
}); |
} |