[dart2js] Add test for empty holders in an output unit.
Change-Id: I364366c2a5e9ce5895dbc4096d17ad04374b69d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202310
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
diff --git a/tests/web/deferred/empty_holders/empty_holders_test.dart b/tests/web/deferred/empty_holders/empty_holders_test.dart
new file mode 100644
index 0000000..b8efe4de
--- /dev/null
+++ b/tests/web/deferred/empty_holders/empty_holders_test.dart
@@ -0,0 +1,20 @@
+// Copyright (c) 2021, 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.
+
+import "lib1.dart" deferred as lib1;
+import "lib2.dart" deferred as lib2;
+import "package:expect/expect.dart";
+
+// Compiling lib_shared will result in a single part file which only uses
+// the static state holder.
+void main() {
+ lib1.loadLibrary().then((_) {
+ lib1.update();
+ Expect.equals(lib1.value(), 'lib1');
+ });
+ lib2.loadLibrary().then((_) {
+ lib2.update();
+ Expect.equals(lib2.value(), 'lib2');
+ });
+}
diff --git a/tests/web/deferred/empty_holders/lib1.dart b/tests/web/deferred/empty_holders/lib1.dart
new file mode 100644
index 0000000..ff8c078
--- /dev/null
+++ b/tests/web/deferred/empty_holders/lib1.dart
@@ -0,0 +1,11 @@
+// Copyright (c) 2021, 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.
+
+import 'lib_shared.dart';
+
+void update() {
+ staticString = 'lib1';
+}
+
+String? value() => staticString;
diff --git a/tests/web/deferred/empty_holders/lib2.dart b/tests/web/deferred/empty_holders/lib2.dart
new file mode 100644
index 0000000..8a3c8c1
--- /dev/null
+++ b/tests/web/deferred/empty_holders/lib2.dart
@@ -0,0 +1,11 @@
+// Copyright (c) 2021, 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.
+
+import 'lib_shared.dart';
+
+void update() {
+ staticString = 'lib2';
+}
+
+String? value() => staticString;
diff --git a/tests/web/deferred/empty_holders/lib_shared.dart b/tests/web/deferred/empty_holders/lib_shared.dart
new file mode 100644
index 0000000..057837f
--- /dev/null
+++ b/tests/web/deferred/empty_holders/lib_shared.dart
@@ -0,0 +1,5 @@
+// Copyright (c) 2021, 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.
+
+String? staticString;