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