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 | 6 |
7 import 'package:compiler/src/compiler.dart' show Compiler; | 7 import 'package:compiler/src/compiler.dart' show Compiler; |
8 import 'package:compiler/src/elements/elements.dart' show Element; | 8 import 'package:compiler/src/elements/elements.dart' show Element; |
9 import 'package:compiler/src/js_backend/backend.dart' as js show JavaScriptBacke
nd; | 9 import 'package:compiler/src/js_backend/backend.dart' as js |
| 10 show JavaScriptBackend; |
10 import 'package:compiler/src/commandline_options.dart' show Flags; | 11 import 'package:compiler/src/commandline_options.dart' show Flags; |
11 import 'package:test/test.dart'; | 12 import 'package:test/test.dart'; |
12 | 13 |
13 import '../memory_compiler.dart'; | 14 import '../memory_compiler.dart'; |
14 | 15 |
15 Future<String> compile(String code, {String entry: 'main', | 16 Future<String> compile(String code, |
16 bool useKernel: true}) async { | 17 {String entry: 'main', bool useKernel: true}) async { |
17 List<String> options = <String>[ | 18 List<String> options = <String>[ |
18 Flags.disableTypeInference, | 19 Flags.disableTypeInference, |
19 Flags.disableInlining, | 20 Flags.disableInlining, |
20 ]; | 21 ]; |
21 if (useKernel) options.add(Flags.useKernel); | 22 if (useKernel) options.add(Flags.useKernel); |
22 | 23 |
23 if (entry != 'main' && !code.contains('main')) { | 24 if (entry != 'main' && !code.contains('main')) { |
24 code = "$code\n\nmain() => $entry;"; | 25 code = "$code\n\nmain() => $entry;"; |
25 } | 26 } |
26 CompilationResult result = await runCompiler( | 27 CompilationResult result = await runCompiler( |
27 memorySourceFiles: {'main.dart': code}, | 28 memorySourceFiles: {'main.dart': code}, options: options); |
28 options: options); | |
29 expect(result.isSuccess, isTrue); | 29 expect(result.isSuccess, isTrue); |
30 Compiler compiler = result.compiler; | 30 Compiler compiler = result.compiler; |
31 Element element = compiler.mainApp.find(entry); | 31 Element element = compiler.mainApp.find(entry); |
32 js.JavaScriptBackend backend = compiler.backend; | 32 js.JavaScriptBackend backend = compiler.backend; |
33 return backend.getGeneratedCode(element); | 33 return backend.getGeneratedCode(element); |
34 } | 34 } |
35 | 35 |
36 Future check(String code, {String entry: 'main'}) async { | 36 Future check(String code, {String entry: 'main'}) async { |
37 var original = await compile(code, entry: entry, useKernel: false); | 37 var original = await compile(code, entry: entry, useKernel: false); |
38 var kernel = await compile(code, entry: entry, useKernel: true); | 38 var kernel = await compile(code, entry: entry, useKernel: true); |
39 expect(kernel, original); | 39 expect(kernel, original); |
40 } | 40 } |
OLD | NEW |