[dart2js] deferred load - gracefully handle missing constants

There is currently a bug in the algorithm that is causing us to miss some constants in the deferred loading table. While I'm investigating, I'm defaulting missing constants to the main output unit. This should prevent downstream errors and unblock users that are hitting this.

Change-Id: I3a7eaf1f9fc98accadba2a494e249002b59eacfc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139311
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
diff --git a/pkg/compiler/lib/src/deferred_load.dart b/pkg/compiler/lib/src/deferred_load.dart
index c029a08..3c49a8c 100644
--- a/pkg/compiler/lib/src/deferred_load.dart
+++ b/pkg/compiler/lib/src/deferred_load.dart
@@ -1466,7 +1466,10 @@
   /// Returns the [OutputUnit] where [constant] belongs.
   OutputUnit outputUnitForConstant(ConstantValue constant) {
     if (!isProgramSplit) return mainOutputUnit;
-    return _constantToUnit[constant];
+    OutputUnit unit = _constantToUnit[constant];
+    // TODO(sigmund): enforce unit is not null: it is sometimes null on some
+    // corner cases on internal apps.
+    return unit ?? mainOutputUnit;
   }
 
   OutputUnit outputUnitForConstantForTesting(ConstantValue constant) =>