OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
7 import 'package:compiler/src/options.dart' show CompilerOptions; | 7 import 'package:compiler/src/options.dart' show CompilerOptions; |
8 import 'package:compiler/src/null_compiler_output.dart'; | 8 import 'package:compiler/src/null_compiler_output.dart'; |
9 import 'memory_source_file_helper.dart'; | 9 import 'memory_source_file_helper.dart'; |
10 | 10 |
11 Future<Map<String, String>> generate(String code, | 11 Future<Map<String, String>> generate(String code, |
12 [List<String> options = const []]) { | 12 [List<String> options = const []]) { |
13 Uri script = currentDirectory.resolveUri(Platform.script); | 13 Uri script = currentDirectory.resolveUri(Platform.script); |
14 Uri libraryRoot = script.resolve('../../../sdk/'); | 14 Uri libraryRoot = script.resolve('../../../sdk/'); |
15 Uri packageRoot = script.resolve('./packages/'); | 15 Uri packageRoot = script.resolve('./packages/'); |
16 | 16 |
17 var provider = new MemorySourceFileProvider({ 'main.dart': code }); | 17 var provider = new MemorySourceFileProvider({'main.dart': code}); |
18 var handler = new FormattingDiagnosticHandler(provider); | 18 var handler = new FormattingDiagnosticHandler(provider); |
19 | 19 |
20 Uri uri = Uri.parse('memory:main.dart'); | 20 Uri uri = Uri.parse('memory:main.dart'); |
21 CompilerImpl compiler = new CompilerImpl(provider, | 21 CompilerImpl compiler = new CompilerImpl( |
22 const NullCompilerOutput(), | 22 provider, |
23 handler, | 23 const NullCompilerOutput(), |
24 new CompilerOptions.parse( | 24 handler, |
25 entryPoint: uri, | 25 new CompilerOptions.parse( |
26 libraryRoot: libraryRoot, | 26 entryPoint: uri, |
27 packageRoot: packageRoot, | 27 libraryRoot: libraryRoot, |
28 options: options)); | 28 packageRoot: packageRoot, |
| 29 options: options)); |
29 return compiler.run(uri).then((success) { | 30 return compiler.run(uri).then((success) { |
30 Expect.isTrue(success); | 31 Expect.isTrue(success); |
31 Map<String, String> result = new Map<String, String>(); | 32 Map<String, String> result = new Map<String, String>(); |
32 var backend = compiler.backend; | 33 var backend = compiler.backend; |
33 for (var element in backend.generatedCode.keys) { | 34 for (var element in backend.generatedCode.keys) { |
34 if (element.compilationUnit.script.readableUri != uri) continue; | 35 if (element.compilationUnit.script.readableUri != uri) continue; |
35 var name = element.name; | 36 var name = element.name; |
36 var code = backend.getGeneratedCode(element); | 37 var code = backend.getGeneratedCode(element); |
37 result[name] = code; | 38 result[name] = code; |
38 } | 39 } |
39 return result; | 40 return result; |
40 }); | 41 }); |
41 } | 42 } |
OLD | NEW |