Index: tests/compiler/dart2js/interop_anonymous_unreachable_test.dart |
diff --git a/tests/compiler/dart2js/interop_anonymous_unreachable_test.dart b/tests/compiler/dart2js/interop_anonymous_unreachable_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e2c8e203a77959a24d944c4c1db1ea6b8c9cf4c1 |
--- /dev/null |
+++ b/tests/compiler/dart2js/interop_anonymous_unreachable_test.dart |
@@ -0,0 +1,79 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library tests.dart2js.interop_anonymous_unreachable_test; |
+ |
+import 'dart:async'; |
+ |
+import 'package:test/test.dart'; |
+import 'compiler_helper.dart'; |
+ |
+ |
+main() { |
+ test("unreachable code doesn't crash the compiler", () async { |
+ // This test is a regression for Issue #24974 |
+ String generated = await compile(""" |
+ import 'package:js/js.dart'; |
+ |
+ @JS() @anonymous |
+ class UniqueLongNameForTesting_A { |
+ external factory UniqueLongNameForTesting_A(); |
+ } |
+ main() {} |
+ """, returnAll: true); |
+ |
+ // the code should not be included in the output either. |
+ expect(generated, isNot(contains("UniqueLongNameForTesting_A"))); |
+ }); |
+ |
+ test('interop types can be tree-shaken', () async { |
+ String generated = await compile(""" |
+ import 'package:js/js.dart'; |
+ |
+ // reachable and allocated |
+ @JS() @anonymous |
+ class UniqueLongNameForTesting_A { |
+ external bool get x; |
+ external UniqueLongNameForTesting_D get d; |
+ external UniqueLongNameForTesting_E get e; |
+ external factory UniqueLongNameForTesting_A( |
+ {UniqueLongNameForTesting_B arg0}); |
+ } |
+ |
+ // visible through the parameter above, but not used. |
+ @JS() @anonymous |
+ class UniqueLongNameForTesting_B { |
+ external factory UniqueLongNameForTesting_B(); |
+ } |
+ |
+ // unreachable |
+ @JS() @anonymous |
+ class UniqueLongNameForTesting_C { |
+ external factory UniqueLongNameForTesting_C(); |
+ } |
+ |
+ // visible and reached through `d`. |
+ @JS() @anonymous |
+ class UniqueLongNameForTesting_D { |
+ external factory UniqueLongNameForTesting_D(); |
+ } |
+ |
+ // visible through `e`, but not reached. |
+ @JS() @anonymous |
+ class UniqueLongNameForTesting_E { |
+ external factory UniqueLongNameForTesting_E(); |
+ } |
+ |
+ main() { |
+ print(new UniqueLongNameForTesting_A().x); |
+ print(new UniqueLongNameForTesting_A().d); |
+ } |
+ """, returnAll: true); |
+ expect(generated, contains("UniqueLongNameForTesting_A")); |
+ expect(generated, contains("UniqueLongNameForTesting_D")); |
+ expect(generated, isNot(contains("UniqueLongNameForTesting_B"))); |
+ expect(generated, isNot(contains("UniqueLongNameForTesting_C"))); |
+ expect(generated, isNot(contains("UniqueLongNameForTesting_E"))); |
+ }); |
+} |