| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library tests.dart2js.interop_anonymous_unreachable_test; | 5 library tests.dart2js.interop_anonymous_unreachable_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
| 10 import 'compiler_helper.dart'; | 10 import 'compiler_helper.dart'; |
| 11 | 11 |
| 12 | |
| 13 main() { | 12 main() { |
| 14 test("unreachable code doesn't crash the compiler", () async { | 13 test("unreachable code doesn't crash the compiler", () async { |
| 15 // This test is a regression for Issue #24974 | 14 // This test is a regression for Issue #24974 |
| 16 String generated = await compile(""" | 15 String generated = await compile( |
| 16 """ |
| 17 import 'package:js/js.dart'; | 17 import 'package:js/js.dart'; |
| 18 | 18 |
| 19 @JS() @anonymous | 19 @JS() @anonymous |
| 20 class UniqueLongNameForTesting_A { | 20 class UniqueLongNameForTesting_A { |
| 21 external factory UniqueLongNameForTesting_A(); | 21 external factory UniqueLongNameForTesting_A(); |
| 22 } | 22 } |
| 23 main() {} | 23 main() {} |
| 24 """, returnAll: true); | 24 """, |
| 25 returnAll: true); |
| 25 | 26 |
| 26 // the code should not be included in the output either. | 27 // the code should not be included in the output either. |
| 27 expect(generated, isNot(contains("UniqueLongNameForTesting_A"))); | 28 expect(generated, isNot(contains("UniqueLongNameForTesting_A"))); |
| 28 }); | 29 }); |
| 29 | 30 |
| 30 group('tree-shaking interop types', () { | 31 group('tree-shaking interop types', () { |
| 31 String program = """ | 32 String program = """ |
| 32 import 'package:js/js.dart'; | 33 import 'package:js/js.dart'; |
| 33 | 34 |
| 34 // reachable and allocated | 35 // reachable and allocated |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 expect(generated.contains("UniqueLongNameForTesting_A"), isTrue); | 77 expect(generated.contains("UniqueLongNameForTesting_A"), isTrue); |
| 77 expect(generated.contains("UniqueLongNameForTesting_D"), isTrue); | 78 expect(generated.contains("UniqueLongNameForTesting_D"), isTrue); |
| 78 | 79 |
| 79 expect(generated.contains("UniqueLongNameForTesting_B"), isTrue); | 80 expect(generated.contains("UniqueLongNameForTesting_B"), isTrue); |
| 80 expect(generated.contains("UniqueLongNameForTesting_C"), isTrue); | 81 expect(generated.contains("UniqueLongNameForTesting_C"), isTrue); |
| 81 expect(generated.contains("UniqueLongNameForTesting_E"), isTrue); | 82 expect(generated.contains("UniqueLongNameForTesting_E"), isTrue); |
| 82 }); | 83 }); |
| 83 | 84 |
| 84 test('tree-shake when using flag', () async { | 85 test('tree-shake when using flag', () async { |
| 85 String generated = await compile(program, | 86 String generated = await compile(program, |
| 86 trustJSInteropTypeAnnotations: true, | 87 trustJSInteropTypeAnnotations: true, returnAll: true); |
| 87 returnAll: true); | |
| 88 expect(generated.contains("UniqueLongNameForTesting_A"), isTrue); | 88 expect(generated.contains("UniqueLongNameForTesting_A"), isTrue); |
| 89 expect(generated.contains("UniqueLongNameForTesting_D"), isTrue); | 89 expect(generated.contains("UniqueLongNameForTesting_D"), isTrue); |
| 90 | 90 |
| 91 expect(generated.contains("UniqueLongNameForTesting_B"), isFalse); | 91 expect(generated.contains("UniqueLongNameForTesting_B"), isFalse); |
| 92 expect(generated.contains("UniqueLongNameForTesting_C"), isFalse); | 92 expect(generated.contains("UniqueLongNameForTesting_C"), isFalse); |
| 93 expect(generated.contains("UniqueLongNameForTesting_E"), isFalse); | 93 expect(generated.contains("UniqueLongNameForTesting_E"), isFalse); |
| 94 }); | 94 }); |
| 95 }); | 95 }); |
| 96 | 96 |
| 97 group('tree-shaking other native types', () { | 97 group('tree-shaking other native types', () { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 119 expect(generated.contains("UniqueLongNameForTesting_A"), isTrue); | 119 expect(generated.contains("UniqueLongNameForTesting_A"), isTrue); |
| 120 // any js-interop type could be allocated by `get x` | 120 // any js-interop type could be allocated by `get x` |
| 121 expect(generated.contains("UniqueLongNameForTesting_B"), isTrue); | 121 expect(generated.contains("UniqueLongNameForTesting_B"), isTrue); |
| 122 // but we exclude other native types like HTMLAudioElement | 122 // but we exclude other native types like HTMLAudioElement |
| 123 expect(generated.contains("HTMLAudioElement"), isFalse); | 123 expect(generated.contains("HTMLAudioElement"), isFalse); |
| 124 }); | 124 }); |
| 125 | 125 |
| 126 test('allocation effect of dynamic excludes native types [flag]', () async { | 126 test('allocation effect of dynamic excludes native types [flag]', () async { |
| 127 // Trusting types doesn't make a difference. | 127 // Trusting types doesn't make a difference. |
| 128 String generated = await compile(program, | 128 String generated = await compile(program, |
| 129 trustJSInteropTypeAnnotations: true, | 129 trustJSInteropTypeAnnotations: true, returnAll: true); |
| 130 returnAll: true); | |
| 131 expect(generated.contains("UniqueLongNameForTesting_A"), isTrue); | 130 expect(generated.contains("UniqueLongNameForTesting_A"), isTrue); |
| 132 expect(generated.contains("UniqueLongNameForTesting_B"), isTrue); | 131 expect(generated.contains("UniqueLongNameForTesting_B"), isTrue); |
| 133 expect(generated.contains("HTMLAudioElement"), isFalse); | 132 expect(generated.contains("HTMLAudioElement"), isFalse); |
| 134 }); | 133 }); |
| 135 | 134 |
| 136 test('declared native types are included in allocation effect', () async { | 135 test('declared native types are included in allocation effect', () async { |
| 137 String program2 = """ | 136 String program2 = """ |
| 138 import 'dart:html'; | 137 import 'dart:html'; |
| 139 import 'package:js/js.dart'; | 138 import 'package:js/js.dart'; |
| 140 | 139 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 168 | 167 |
| 169 generated = await compile(program2, returnAll: true); | 168 generated = await compile(program2, returnAll: true); |
| 170 expect(generated.contains("UniqueLongNameForTesting_A"), isTrue); | 169 expect(generated.contains("UniqueLongNameForTesting_A"), isTrue); |
| 171 // This extra check is to make sure that we don't include HTMLAudioElement | 170 // This extra check is to make sure that we don't include HTMLAudioElement |
| 172 // just because of the is-check. It is optimized away in this case because | 171 // just because of the is-check. It is optimized away in this case because |
| 173 // we believe it was never instantiated. | 172 // we believe it was never instantiated. |
| 174 expect(generated.contains("HTMLAudioElement"), isFalse); | 173 expect(generated.contains("HTMLAudioElement"), isFalse); |
| 175 }); | 174 }); |
| 176 }); | 175 }); |
| 177 } | 176 } |
| OLD | NEW |