code: private List<JSModule> makeWeakModule(List<JSModule> modulesInDepOrder) {
      boolean hasWeakModule = false;
      for (JSModule module : modulesInDepOrder) {
        if (module.getName().equals(JSModule.WEAK_MODULE_NAME)) {
          hasWeakModule = true;
          Set<JSModule> allOtherModules = new HashSet<>(modulesInDepOrder);
          allOtherModules.remove(module);
          checkState(
              module.getAllDependencies().containsAll(allOtherModules),
              "A weak module already exists but it does not depend on every other module.");
          checkState(
              module.getAllDependencies().size() == allOtherModules.size(),
              "The weak module cannot have extra dependencies.");
          break;
        }
      }
      if (hasWeakModule) {
        // All weak files (and only weak files) should be in the weak module.
        for (JSModule module : modulesInDepOrder) {
          for (CompilerInput input : module.getInputs()) {
            if (module.getName().equals(JSModule.WEAK_MODULE_NAME)) {
              checkState(
                  input.getSourceFile().isWeak(),
                  "A weak module already exists but strong sources were found in it.");
            } else {
              checkState(
                  !input.getSourceFile().isWeak(),
                  "A weak module already exists but weak sources were found in other modules.");
            }
          }
        }
      } else {
        JSModule weakModule = new JSModule(JSModule.WEAK_MODULE_NAME);
        for (JSModule module : modulesInDepOrder) {
          weakModule.addDependency(module);
        }
        modulesInDepOrder = new ArrayList<>(modulesInDepOrder);
        modulesInDepOrder.add(weakModule);
      }
      return modulesInDepOrder;
    }
docs: If a weak module doesn't already exist, creates a weak module depending on every other module.
  
  <p>Does not move any sources into the weak module.
  
  @return a new list of modules that includes the weak module, if it was newly created, or the
  same list if the weak module already existed
  @throws IllegalStateException if a weak module already exists but doesn't fulfill the above
  conditions