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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
7 | 7 |
8 import 'memory_source_file_helper.dart'; | 8 import 'memory_source_file_helper.dart'; |
9 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart" | |
10 show SourceString; | |
11 | 9 |
12 Future<Map<String, String>> generate(String code, | 10 Future<Map<String, String>> generate(String code, |
13 [List<String> options = const []]) { | 11 [List<String> options = const []]) { |
14 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); | 12 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); |
15 Uri libraryRoot = script.resolve('../../../sdk/'); | 13 Uri libraryRoot = script.resolve('../../../sdk/'); |
16 Uri packageRoot = script.resolve('./packages/'); | 14 Uri packageRoot = script.resolve('./packages/'); |
17 | 15 |
18 var provider = new MemorySourceFileProvider({ 'main.dart': code }); | 16 var provider = new MemorySourceFileProvider({ 'main.dart': code }); |
19 var handler = new FormattingDiagnosticHandler(provider); | 17 var handler = new FormattingDiagnosticHandler(provider); |
20 | 18 |
21 Compiler compiler = new Compiler(provider.readStringFromUri, | 19 Compiler compiler = new Compiler(provider.readStringFromUri, |
22 null, | 20 null, |
23 handler.diagnosticHandler, | 21 handler.diagnosticHandler, |
24 libraryRoot, | 22 libraryRoot, |
25 packageRoot, | 23 packageRoot, |
26 options); | 24 options); |
27 Uri uri = Uri.parse('memory:main.dart'); | 25 Uri uri = Uri.parse('memory:main.dart'); |
28 return compiler.run(uri).then((success) { | 26 return compiler.run(uri).then((success) { |
29 Expect.isTrue(success); | 27 Expect.isTrue(success); |
30 Map<String, String> result = new Map<String, String>(); | 28 Map<String, String> result = new Map<String, String>(); |
31 for (var element in compiler.backend.generatedCode.keys) { | 29 for (var element in compiler.backend.generatedCode.keys) { |
32 if (element.getCompilationUnit().script.uri != uri) continue; | 30 if (element.getCompilationUnit().script.uri != uri) continue; |
33 var name = element.name.slowToString(); | 31 var name = element.name; |
34 var code = compiler.backend.assembleCode(element); | 32 var code = compiler.backend.assembleCode(element); |
35 result[name] = code; | 33 result[name] = code; |
36 } | 34 } |
37 return result; | 35 return result; |
38 }); | 36 }); |
39 } | 37 } |
OLD | NEW |