| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 /// Alternative compile method for dart2js commandline that stores the compiler |
| 6 /// for later inspection. |
| 7 /// |
| 8 /// Use this in testing to inspect the compiler after compilation by setting |
| 9 /// the `compileFunc` variable in `package:compiler/src/dart2js.dart` |
| 10 /// to [compiler] before calling the `internalMain` function. |
| 11 |
| 12 library dart2js.alt; |
| 13 |
| 14 import 'dart:async'; |
| 15 import 'package:compiler/compiler.dart'; |
| 16 import 'package:compiler/src/apiimpl.dart'; |
| 17 |
| 18 Compiler compiler; |
| 19 |
| 20 Future<String> compile(Uri script, |
| 21 Uri libraryRoot, |
| 22 Uri packageRoot, |
| 23 CompilerInputProvider inputProvider, |
| 24 DiagnosticHandler handler, |
| 25 [List<String> options = const [], |
| 26 CompilerOutputProvider outputProvider, |
| 27 Map<String, dynamic> environment = const {}]) { |
| 28 if (!libraryRoot.path.endsWith("/")) { |
| 29 throw new ArgumentError("libraryRoot must end with a /"); |
| 30 } |
| 31 if (packageRoot != null && !packageRoot.path.endsWith("/")) { |
| 32 throw new ArgumentError("packageRoot must end with a /"); |
| 33 } |
| 34 compiler = new Compiler(inputProvider, |
| 35 outputProvider, |
| 36 handler, |
| 37 libraryRoot, |
| 38 packageRoot, |
| 39 options, |
| 40 environment); |
| 41 return compiler.run(script).then((_) { |
| 42 String code = compiler.assembledCode; |
| 43 if (code != null && outputProvider != null) { |
| 44 code = ''; // Non-null signals success. |
| 45 } |
| 46 return code; |
| 47 }); |
| 48 } |
| OLD | NEW |