Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1274)

Unified Diff: pkg/analyzer2dart/test/tree_shaker_test.dart

Issue 611153003: Propertly tree shake factory constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer2dart/test/tree_shaker_test.dart
diff --git a/pkg/analyzer2dart/test/tree_shaker_test.dart b/pkg/analyzer2dart/test/tree_shaker_test.dart
index 938b334e3dfc6d424797e2ba99f56b61dd1d16dc..c094f09c76dc97ba8100a55791cbe040975e7f12 100644
--- a/pkg/analyzer2dart/test/tree_shaker_test.dart
+++ b/pkg/analyzer2dart/test/tree_shaker_test.dart
@@ -179,6 +179,74 @@ main() {
helper.assertNoField('B.f1');
helper.assertNoField('B.f2');
});
+
+ test('Ordinary constructor with initializer list', () {
+ var helper = new TreeShakerTestHelper('''
+class A {
+ A() : x = f();
+ var x;
+ foo() {}
+}
+f() {}
+main() {
+ new A().foo();
+}
+''');
+ helper.assertHasMethod('A.foo');
+ helper.assertHasFunction('f');
+ });
+
+ test('Redirecting constructor', () {
+ var helper = new TreeShakerTestHelper('''
+class A {
+ A.a1() : this.a2();
+ A.a2();
+ foo() {}
+}
+main() {
+ new A.a1().foo();
+}
+''');
+ helper.assertHasMethod('A.foo');
+ });
+
+ test('Factory constructor', () {
+ var helper = new TreeShakerTestHelper('''
+class A {
+ factory A() {
+ return new B();
+ }
+ foo() {}
+}
+class B {
+ B();
+ foo() {}
+}
+main() {
+ new A().foo();
+}
+''');
+ helper.assertHasMethod('B.foo');
+ helper.assertNoMethod('A.foo');
+ });
+
+ test('Redirecting factory constructor', () {
+ var helper = new TreeShakerTestHelper('''
+class A {
+ factory A() = B;
+ foo() {}
+}
+class B {
+ B();
+ foo() {}
+}
+main() {
+ new A().foo();
+}
+''');
+ helper.assertHasMethod('B.foo');
+ helper.assertNoMethod('A.foo');
+ });
}
class TreeShakerTestHelper {
« pkg/analyzer2dart/lib/src/tree_shaker.dart ('K') | « pkg/analyzer2dart/lib/src/tree_shaker.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698