| 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..f0bd9861fc8b867b0d0d048048e7b3b1b976e2d0
|
| --- /dev/null
|
| +++ b/tests/compiler/dart2js/interop_anonymous_unreachable_test.dart
|
| @@ -0,0 +1,85 @@
|
| +// 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 are not 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"));
|
| +
|
| + // It would be nice to tree-shake these. That might only work if we use a
|
| + // different approach for js-interop and trust the declared return types of
|
| + // external APIs. The downside of that is that side-casts between interop
|
| + // types would no longer work unless both types were included independently.
|
| + // See tests/html/js_typed_interop_side_cast_test for an example.
|
| + expect(generated, contains("UniqueLongNameForTesting_B"));
|
| + expect(generated, contains("UniqueLongNameForTesting_C"));
|
| + expect(generated, contains("UniqueLongNameForTesting_E"));
|
| + });
|
| +}
|
|
|