| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library compiler; | 5 library compiler; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'implementation/apiimpl.dart'; | 8 import 'implementation/apiimpl.dart'; |
| 9 | 9 |
| 10 // Unless explicitly allowed, passing [:null:] for any argument to the | 10 // Unless explicitly allowed, passing [:null:] for any argument to the |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 * Deprecated: if no [outputProvider] is given, the future completes | 78 * Deprecated: if no [outputProvider] is given, the future completes |
| 79 * to the compiled script. This behavior will be removed in the future | 79 * to the compiled script. This behavior will be removed in the future |
| 80 * as the compiler may create multiple files to support lazy loading | 80 * as the compiler may create multiple files to support lazy loading |
| 81 * of libraries. | 81 * of libraries. |
| 82 */ | 82 */ |
| 83 Future<String> compile(Uri script, | 83 Future<String> compile(Uri script, |
| 84 Uri libraryRoot, | 84 Uri libraryRoot, |
| 85 Uri packageRoot, | 85 Uri packageRoot, |
| 86 CompilerInputProvider inputProvider, | 86 CompilerInputProvider inputProvider, |
| 87 DiagnosticHandler handler, | 87 DiagnosticHandler handler, |
| 88 [List<String> options = const [], | 88 [List<String> options = const [], |
| 89 CompilerOutputProvider outputProvider, | 89 CompilerOutputProvider outputProvider, |
| 90 Map<String, dynamic> environment = const {}]) { | 90 Map<String, dynamic> environment = const {}]) { |
| 91 if (!libraryRoot.path.endsWith("/")) { | 91 if (!libraryRoot.path.endsWith("/")) { |
| 92 throw new ArgumentError("libraryRoot must end with a /"); | 92 throw new ArgumentError("libraryRoot must end with a /"); |
| 93 } | 93 } |
| 94 if (packageRoot != null && !packageRoot.path.endsWith("/")) { | 94 if (packageRoot != null && !packageRoot.path.endsWith("/")) { |
| 95 throw new ArgumentError("packageRoot must end with a /"); | 95 throw new ArgumentError("packageRoot must end with a /"); |
| 96 } | 96 } |
| 97 // TODO(ahe): Consider completing the future with an exception if | 97 // TODO(ahe): Consider completing the future with an exception if |
| 98 // code is null. | 98 // code is null. |
| 99 Compiler compiler = new Compiler(inputProvider, | 99 Compiler compiler = new Compiler(inputProvider, |
| 100 outputProvider, | 100 outputProvider, |
| 101 handler, | 101 handler, |
| 102 libraryRoot, | 102 libraryRoot, |
| 103 packageRoot, | 103 packageRoot, |
| 104 options, | 104 options, |
| 105 environment); | 105 environment); |
| 106 // TODO(ahe): Use the value of the future (which signals success or failure). | 106 // TODO(ahe): Use the value of the future (which signals success or failure). |
| 107 return compiler.run(script).then((_) { | 107 return compiler.run(script).then((_) { |
| 108 String code = compiler.assembledCode; | 108 String code = compiler.assembledCode; |
| 109 if (code != null && outputProvider != null) { | 109 if (code != null && outputProvider != null) { |
| 110 String outputType = 'js'; | |
| 111 if (options.contains('--output-type=dart')) { | |
| 112 outputType = 'dart'; | |
| 113 } | |
| 114 outputProvider('', outputType) | |
| 115 ..add(code) | |
| 116 ..close(); | |
| 117 code = ''; // Non-null signals success. | 110 code = ''; // Non-null signals success. |
| 118 } | 111 } |
| 119 return code; | 112 return code; |
| 120 }); | 113 }); |
| 121 } | 114 } |
| 122 | 115 |
| 123 /** | 116 /** |
| 124 * Kind of diagnostics that the compiler can report. | 117 * Kind of diagnostics that the compiler can report. |
| 125 */ | 118 */ |
| 126 class Diagnostic { | 119 class Diagnostic { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 final String name; | 178 final String name; |
| 186 | 179 |
| 187 /** | 180 /** |
| 188 * This constructor is not private to support user-defined | 181 * This constructor is not private to support user-defined |
| 189 * diagnostic kinds. | 182 * diagnostic kinds. |
| 190 */ | 183 */ |
| 191 const Diagnostic(this.ordinal, this.name); | 184 const Diagnostic(this.ordinal, this.name); |
| 192 | 185 |
| 193 String toString() => name; | 186 String toString() => name; |
| 194 } | 187 } |
| OLD | NEW |