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