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