| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, 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 // Smoke test of the dart2js compiler API. | |
| 6 library dummy_compiler; | |
| 7 | |
| 8 import 'dart:async'; | |
| 9 import "package:async_helper/async_helper.dart"; | |
| 10 | |
| 11 import 'package:compiler/compiler.dart'; | |
| 12 | |
| 13 import '../compiler/dart2js/mock_libraries.dart'; | |
| 14 | |
| 15 String libProvider(Uri uri) { | |
| 16 if (uri.path.endsWith(".platform")) { | |
| 17 return DEFAULT_PLATFORM_CONFIG; | |
| 18 } | |
| 19 if (uri.path.endsWith("/core.dart")) { | |
| 20 return buildLibrarySource(DEFAULT_CORE_LIBRARY); | |
| 21 } else if (uri.path.endsWith('core_patch.dart')) { | |
| 22 return DEFAULT_PATCH_CORE_SOURCE; | |
| 23 } else if (uri.path.endsWith('internal.dart')) { | |
| 24 return buildLibrarySource(DEFAULT_INTERNAL_LIBRARY); | |
| 25 } else if (uri.path.endsWith('interceptors.dart')) { | |
| 26 return buildLibrarySource(DEFAULT_INTERCEPTORS_LIBRARY); | |
| 27 } else if (uri.path.endsWith('js_helper.dart')) { | |
| 28 return buildLibrarySource(DEFAULT_JS_HELPER_LIBRARY); | |
| 29 } else if (uri.path.endsWith('isolate_helper.dart')) { | |
| 30 return buildLibrarySource(DEFAULT_ISOLATE_HELPER_LIBRARY); | |
| 31 } else if (uri.path.endsWith('/async.dart')) { | |
| 32 return buildLibrarySource(DEFAULT_ASYNC_LIBRARY); | |
| 33 } else { | |
| 34 return "library lib${uri.path.replaceAll('/', '.')};"; | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 Future<String> provider(Uri uri) { | |
| 39 String source; | |
| 40 if (uri.scheme == "main") { | |
| 41 source = "main() {}"; | |
| 42 } else if (uri.scheme == "lib") { | |
| 43 source = libProvider(uri); | |
| 44 } else { | |
| 45 throw "unexpected URI $uri"; | |
| 46 } | |
| 47 return new Future.value(source); | |
| 48 } | |
| 49 | |
| 50 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { | |
| 51 if (uri == null) { | |
| 52 print('$kind: $message'); | |
| 53 } else { | |
| 54 print('$uri:$begin:$end: $kind: $message'); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 main() { | |
| 59 asyncStart(); | |
| 60 Future<CompilationResult> result = compile( | |
| 61 new Uri(scheme: 'main'), | |
| 62 new Uri(scheme: 'lib', path: '/'), | |
| 63 new Uri(scheme: 'package', path: '/'), | |
| 64 provider, | |
| 65 handler); | |
| 66 result.then((CompilationResult result) { | |
| 67 if (!result.isSuccess) { | |
| 68 throw 'Compilation failed'; | |
| 69 } | |
| 70 }, onError: (e, s) { | |
| 71 throw 'Compilation failed: $e\n$s'; | |
| 72 }).then(asyncSuccess); | |
| 73 } | |
| OLD | NEW |