| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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:uri'); | 5 #import('dart:uri'); |
| 6 #import('parser_helper.dart'); | 6 #import('parser_helper.dart'); |
| 7 #import('mock_compiler.dart'); | 7 #import('mock_compiler.dart'); |
| 8 #import("../../../lib/compiler/compiler.dart"); | 8 #import("../../../lib/compiler/compiler.dart"); |
| 9 #import("../../../lib/compiler/implementation/leg.dart", prefix:'leg'); | 9 #import("../../../lib/compiler/implementation/leg.dart", prefix:'leg'); |
| 10 #import("../../../lib/compiler/implementation/dart_backend/dart_backend.dart"); | 10 #import("../../../lib/compiler/implementation/dart_backend/dart_backend.dart"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 Window get window() => __window; | 44 Window get window() => __window; |
| 45 abstract class Window { | 45 abstract class Window { |
| 46 abstract Navigator get navigator; | 46 abstract Navigator get navigator; |
| 47 } | 47 } |
| 48 abstract class Navigator { | 48 abstract class Navigator { |
| 49 abstract String get userAgent; | 49 abstract String get userAgent; |
| 50 } | 50 } |
| 51 '''; | 51 '''; |
| 52 | 52 |
| 53 testDart2Dart(String src, [void continuation(String s), bool minify = false, | 53 testDart2Dart(String src, [void continuation(String s), bool minify = false, |
| 54 bool cutDeclarationTypes = false]) { | 54 bool stripTypes = false]) { |
| 55 // If continuation is not provided, check that source string remains the same. | 55 // If continuation is not provided, check that source string remains the same. |
| 56 if (continuation === null) { | 56 if (continuation === null) { |
| 57 continuation = (s) { Expect.equals(src, s); }; | 57 continuation = (s) { Expect.equals(src, s); }; |
| 58 } | 58 } |
| 59 testDart2DartWithLibrary(src, '', continuation, minify, cutDeclarationTypes); | 59 testDart2DartWithLibrary(src, '', continuation, minify, stripTypes); |
| 60 } | 60 } |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * Library name is assumed to be 'mylib' in 'mylib.dart' file. | 63 * Library name is assumed to be 'mylib' in 'mylib.dart' file. |
| 64 */ | 64 */ |
| 65 testDart2DartWithLibrary( | 65 testDart2DartWithLibrary( |
| 66 String srcMain, String srcLibrary, | 66 String srcMain, String srcLibrary, |
| 67 [void continuation(String s), bool minify = false, | 67 [void continuation(String s), bool minify = false, |
| 68 bool cutDeclarationTypes = false]) { | 68 bool stripTypes = false]) { |
| 69 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); | 69 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); |
| 70 | 70 |
| 71 final scriptUri = fileUri('script.dart'); | 71 final scriptUri = fileUri('script.dart'); |
| 72 final libUri = fileUri('mylib.dart'); | 72 final libUri = fileUri('mylib.dart'); |
| 73 | 73 |
| 74 provider(uri) { | 74 provider(uri) { |
| 75 if (uri == scriptUri) return new Future.immediate(srcMain); | 75 if (uri == scriptUri) return new Future.immediate(srcMain); |
| 76 if (uri.toString() == libUri.toString()) { | 76 if (uri.toString() == libUri.toString()) { |
| 77 return new Future.immediate(srcLibrary); | 77 return new Future.immediate(srcLibrary); |
| 78 } | 78 } |
| 79 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); | 79 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); |
| 80 if (uri.path.endsWith('/io.dart')) return new Future.immediate(ioLib); | 80 if (uri.path.endsWith('/io.dart')) return new Future.immediate(ioLib); |
| 81 // TODO(smok): The file should change to html_dartium at some point. | 81 // TODO(smok): The file should change to html_dartium at some point. |
| 82 if (uri.path.endsWith('/html_dart2js.dart')) return new Future.immediate(htm
lLib); | 82 if (uri.path.endsWith('/html_dart2js.dart')) return new Future.immediate(htm
lLib); |
| 83 return new Future.immediate(''); | 83 return new Future.immediate(''); |
| 84 } | 84 } |
| 85 | 85 |
| 86 handler(uri, begin, end, message, kind) { | 86 handler(uri, begin, end, message, kind) { |
| 87 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { | 87 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { |
| 88 Expect.fail('$uri: $begin-$end: $message [$kind]'); | 88 Expect.fail('$uri: $begin-$end: $message [$kind]'); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 final options = <String>['--output-type=dart']; | 92 final options = <String>['--output-type=dart']; |
| 93 if (minify) options.add('--minify'); | 93 if (minify) options.add('--minify'); |
| 94 if (cutDeclarationTypes) options.add('--force-cut-declaration-types'); | 94 if (stripTypes) options.add('--force-strip=types'); |
| 95 | 95 |
| 96 compile( | 96 compile( |
| 97 scriptUri, | 97 scriptUri, |
| 98 fileUri('libraryRoot'), | 98 fileUri('libraryRoot'), |
| 99 fileUri('packageRoot'), | 99 fileUri('packageRoot'), |
| 100 provider, | 100 provider, |
| 101 handler, | 101 handler, |
| 102 options).then(continuation); | 102 options).then(continuation); |
| 103 } | 103 } |
| 104 | 104 |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 | 745 |
| 746 main() { | 746 main() { |
| 747 String localvar; | 747 String localvar; |
| 748 foo("5"); | 748 foo("5"); |
| 749 } | 749 } |
| 750 '''; | 750 '''; |
| 751 var expectedResult = | 751 var expectedResult = |
| 752 ' foo( arg){}main(){var localvar;foo("5");}'; | 752 ' foo( arg){}main(){var localvar;foo("5");}'; |
| 753 testDart2Dart(src, | 753 testDart2Dart(src, |
| 754 (String result) { Expect.equals(expectedResult, result); }, | 754 (String result) { Expect.equals(expectedResult, result); }, |
| 755 cutDeclarationTypes: true); | 755 stripTypes: true); |
| 756 } | 756 } |
| 757 | 757 |
| 758 testPlatformLibraryMemberNamesAreFixed() { | 758 testPlatformLibraryMemberNamesAreFixed() { |
| 759 var src = ''' | 759 var src = ''' |
| 760 #import('dart:html'); | 760 #import('dart:html'); |
| 761 | 761 |
| 762 class A { | 762 class A { |
| 763 static String get userAgent => window.navigator.userAgent; | 763 static String get userAgent => window.navigator.userAgent; |
| 764 } | 764 } |
| 765 | 765 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 testInterfaceDefaultAnotherLib(); | 801 testInterfaceDefaultAnotherLib(); |
| 802 testStaticAccessIoLib(); | 802 testStaticAccessIoLib(); |
| 803 testLocalFunctionPlaceholder(); | 803 testLocalFunctionPlaceholder(); |
| 804 testMinification(); | 804 testMinification(); |
| 805 testClosureLocalsMinified(); | 805 testClosureLocalsMinified(); |
| 806 testParametersMinified(); | 806 testParametersMinified(); |
| 807 testTypeVariablesInDifferentLibraries(); | 807 testTypeVariablesInDifferentLibraries(); |
| 808 testDeclarationTypePlaceholders(); | 808 testDeclarationTypePlaceholders(); |
| 809 testPlatformLibraryMemberNamesAreFixed(); | 809 testPlatformLibraryMemberNamesAreFixed(); |
| 810 } | 810 } |
| OLD | NEW |