docs: function applyProviderOverridesToNgModule(def) {
      var _a = calcHasOverrides(def), hasOverrides = _a.hasOverrides, hasDeprecatedOverrides = _a.hasDeprecatedOverrides;
      if (!hasOverrides) {
          return def;
      }
      // clone the whole view definition,
      // as it maintains references between the nodes that are hard to update.
      def = def.factory(function () { return NOOP; });
      applyProviderOverrides(def);
      return def;
      function calcHasOverrides(def) {
          var hasOverrides = false;
          var hasDeprecatedOverrides = false;
          if (providerOverrides.size === 0) {
              return { hasOverrides: hasOverrides, hasDeprecatedOverrides: hasDeprecatedOverrides };
          }
          def.providers.forEach(function (node) {
              var override = providerOverrides.get(node.token);
              if ((node.flags & 3840 /* CatProviderNoDirective */) && override) {
                  hasOverrides = true;
                  hasDeprecatedOverrides = hasDeprecatedOverrides || override.deprecatedBehavior;
              }
          });
          def.modules.forEach(function (module) {
              providerOverridesWithScope.forEach(function (override, token) {
                  if (token.ngInjectableDef.providedIn === module) {
                      hasOverrides = true;
                      hasDeprecatedOverrides = hasDeprecatedOverrides || override.deprecatedBehavior;
                  }
              });
          });
          return { hasOverrides: hasOverrides, hasDeprecatedOverrides: hasDeprecatedOverrides };
      }
      function applyProviderOverrides(def) {
          for (var i = 0; i < def.providers.length; i++) {
              var provider = def.providers[i];
              if (hasDeprecatedOverrides) {
                  // We had a bug where me made
                  // all providers lazy. Keep this logic behind a flag
                  // for migrating existing users.
                  provider.flags |= 4096 /* LazyProvider */;
              }
              var override = providerOverrides.get(provider.token);
              if (override) {
                  provider.flags = (provider.flags & ~3840 /* CatProviderNoDirective */) | override.flags;
                  provider.deps = splitDepsDsl(override.deps);
                  provider.value = override.value;
              }
          }
          if (providerOverridesWithScope.size > 0) {
              var moduleSet_1 = new Set(def.modules);
              providerOverridesWithScope.forEach(function (override, token) {
                  if (moduleSet_1.has(token.ngInjectableDef.providedIn)) {
                      var provider = {
                          token: token,
                          flags: override.flags | (hasDeprecatedOverrides ? 4096 /* LazyProvider */ : 0 /* None */),
                          deps: splitDepsDsl(override.deps),
                          value: override.value,
                          index: def.providers.length,
                      };
                      def.providers.push(provider);
                      def.providersByKey[tokenKey(token)] = provider;
                  }
              });
          }
      }
  }