| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Test of the graph segmentation algorithm used by deferred loading | 5 // Test of the graph segmentation algorithm used by deferred loading |
| 6 // to determine which elements can be deferred and which libraries | 6 // to determine which elements can be deferred and which libraries |
| 7 // much be included in the initial download (loaded eagerly). | 7 // much be included in the initial download (loaded eagerly). |
| 8 | 8 |
| 9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:compiler/src/compiler.dart'; | 10 import 'package:compiler/src/compiler.dart'; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // lib2. | 77 // lib2. |
| 78 // | 78 // |
| 79 // Both lib1 and lib2 import lib3 directly and | 79 // Both lib1 and lib2 import lib3 directly and |
| 80 // both use lib3.foo3. Therefore a shared output unit for lib1 and lib2 should | 80 // both use lib3.foo3. Therefore a shared output unit for lib1 and lib2 should |
| 81 // be created. | 81 // be created. |
| 82 // | 82 // |
| 83 // lib1 and lib2 also import lib4 deferred, but lib1 uses lib4.bar1 and lib2 | 83 // lib1 and lib2 also import lib4 deferred, but lib1 uses lib4.bar1 and lib2 |
| 84 // uses lib4.bar2. So two output units should be created for lib4, one for each | 84 // uses lib4.bar2. So two output units should be created for lib4, one for each |
| 85 // import. | 85 // import. |
| 86 const Map MEMORY_SOURCE_FILES = const { | 86 const Map MEMORY_SOURCE_FILES = const { |
| 87 "main.dart":""" | 87 "main.dart": """ |
| 88 import "dart:async"; | 88 import "dart:async"; |
| 89 import 'lib1.dart' deferred as lib1; | 89 import 'lib1.dart' deferred as lib1; |
| 90 import 'lib2.dart' deferred as lib2; | 90 import 'lib2.dart' deferred as lib2; |
| 91 | 91 |
| 92 void main() { | 92 void main() { |
| 93 lib1.loadLibrary().then((_) { | 93 lib1.loadLibrary().then((_) { |
| 94 lib1.foo1(); | 94 lib1.foo1(); |
| 95 new lib1.C(); | 95 new lib1.C(); |
| 96 lib2.loadLibrary().then((_) { | 96 lib2.loadLibrary().then((_) { |
| 97 lib2.foo2(); | 97 lib2.foo2(); |
| 98 }); | 98 }); |
| 99 }); | 99 }); |
| 100 } | 100 } |
| 101 """, | 101 """, |
| 102 "lib1.dart":""" | 102 "lib1.dart": """ |
| 103 library lib1; | 103 library lib1; |
| 104 import "dart:async"; | 104 import "dart:async"; |
| 105 import "dart:html"; | 105 import "dart:html"; |
| 106 | 106 |
| 107 import "lib3.dart" as l3; | 107 import "lib3.dart" as l3; |
| 108 import "lib4.dart" deferred as lib4_1; | 108 import "lib4.dart" deferred as lib4_1; |
| 109 | 109 |
| 110 class C {} | 110 class C {} |
| 111 | 111 |
| 112 foo1() { | 112 foo1() { |
| 113 new InputElement(); | 113 new InputElement(); |
| 114 lib4_1.loadLibrary().then((_) { | 114 lib4_1.loadLibrary().then((_) { |
| 115 lib4_1.bar1(); | 115 lib4_1.bar1(); |
| 116 }); | 116 }); |
| 117 return () {return 1 + l3.foo3();} (); | 117 return () {return 1 + l3.foo3();} (); |
| 118 } | 118 } |
| 119 """, | 119 """, |
| 120 "lib2.dart":""" | 120 "lib2.dart": """ |
| 121 library lib2; | 121 library lib2; |
| 122 import "dart:async"; | 122 import "dart:async"; |
| 123 import "lib3.dart" as l3; | 123 import "lib3.dart" as l3; |
| 124 import "lib4.dart" deferred as lib4_2; | 124 import "lib4.dart" deferred as lib4_2; |
| 125 | 125 |
| 126 foo2() { | 126 foo2() { |
| 127 lib4_2.loadLibrary().then((_) { | 127 lib4_2.loadLibrary().then((_) { |
| 128 lib4_2.bar2(); | 128 lib4_2.bar2(); |
| 129 }); | 129 }); |
| 130 return () {return 2+l3.foo3();} (); | 130 return () {return 2+l3.foo3();} (); |
| 131 } | 131 } |
| 132 """, | 132 """, |
| 133 "lib3.dart":""" | 133 "lib3.dart": """ |
| 134 library lib3; | 134 library lib3; |
| 135 | 135 |
| 136 foo3() { | 136 foo3() { |
| 137 return () {return 3;} (); | 137 return () {return 3;} (); |
| 138 } | 138 } |
| 139 """, | 139 """, |
| 140 "lib4.dart":""" | 140 "lib4.dart": """ |
| 141 library lib4; | 141 library lib4; |
| 142 | 142 |
| 143 bar1() { | 143 bar1() { |
| 144 return "hello"; | 144 return "hello"; |
| 145 } | 145 } |
| 146 | 146 |
| 147 bar2() { | 147 bar2() { |
| 148 return 2; | 148 return 2; |
| 149 } | 149 } |
| 150 """, | 150 """, |
| 151 }; | 151 }; |
| OLD | NEW |