@angular/core 14.1.0-next.0 → 14.1.0-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/esm2020/src/application_ref.mjs +31 -35
  2. package/esm2020/src/change_detection/differs/default_iterable_differ.mjs +3 -5
  3. package/esm2020/src/change_detection/differs/default_keyvalue_differ.mjs +3 -5
  4. package/esm2020/src/change_detection/differs/iterable_differs.mjs +3 -5
  5. package/esm2020/src/change_detection/differs/keyvalue_differs.mjs +2 -5
  6. package/esm2020/src/di/injector_compatibility.mjs +6 -16
  7. package/esm2020/src/di/jit/util.mjs +3 -2
  8. package/esm2020/src/di/reflective_key.mjs +3 -2
  9. package/esm2020/src/errors.mjs +1 -1
  10. package/esm2020/src/i18n/locale_data_api.mjs +3 -2
  11. package/esm2020/src/render3/component.mjs +3 -2
  12. package/esm2020/src/render3/features/inherit_definition_feature.mjs +3 -5
  13. package/esm2020/src/render3/interfaces/renderer.mjs +10 -1
  14. package/esm2020/src/render3/jit/directive.mjs +20 -3
  15. package/esm2020/src/render3/jit/module.mjs +2 -1
  16. package/esm2020/src/render3/ng_module_ref.mjs +10 -2
  17. package/esm2020/src/render3/view_ref.mjs +3 -5
  18. package/esm2020/src/sanitization/sanitization.mjs +4 -9
  19. package/esm2020/src/version.mjs +1 -1
  20. package/esm2020/src/zone/ng_zone.mjs +5 -4
  21. package/esm2020/testing/src/logger.mjs +3 -3
  22. package/esm2020/testing/src/ng_zone_mock.mjs +3 -3
  23. package/esm2020/testing/src/r3_test_bed_compiler.mjs +30 -25
  24. package/fesm2015/core.mjs +96 -91
  25. package/fesm2015/core.mjs.map +1 -1
  26. package/fesm2015/testing.mjs +131 -126
  27. package/fesm2015/testing.mjs.map +1 -1
  28. package/fesm2020/core.mjs +96 -91
  29. package/fesm2020/core.mjs.map +1 -1
  30. package/fesm2020/testing.mjs +131 -126
  31. package/fesm2020/testing.mjs.map +1 -1
  32. package/index.d.ts +15 -7
  33. package/package.json +1 -1
  34. package/testing/index.d.ts +1 -1
  35. package/schematics/utils/schematics_prompt.d.ts +0 -17
  36. package/schematics/utils/schematics_prompt.js +0 -45
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v14.1.0-next.0
2
+ * @license Angular v14.1.0-next.3
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -863,6 +863,68 @@ const NG_INJ_DEF = getClosureSafeProperty({ ɵinj: getClosureSafeProperty });
863
863
  const NG_INJECTABLE_DEF = getClosureSafeProperty({ ngInjectableDef: getClosureSafeProperty });
864
864
  const NG_INJECTOR_DEF = getClosureSafeProperty({ ngInjectorDef: getClosureSafeProperty });
865
865
 
866
+ /**
867
+ * @license
868
+ * Copyright Google LLC All Rights Reserved.
869
+ *
870
+ * Use of this source code is governed by an MIT-style license that can be
871
+ * found in the LICENSE file at https://angular.io/license
872
+ */
873
+ /**
874
+ * Base URL for the error details page.
875
+ *
876
+ * Keep the files below in full sync:
877
+ * - packages/compiler-cli/src/ngtsc/diagnostics/src/error_details_base_url.ts
878
+ * - packages/core/src/error_details_base_url.ts
879
+ */
880
+ const ERROR_DETAILS_PAGE_BASE_URL = 'https://angular.io/errors';
881
+
882
+ /**
883
+ * @license
884
+ * Copyright Google LLC All Rights Reserved.
885
+ *
886
+ * Use of this source code is governed by an MIT-style license that can be
887
+ * found in the LICENSE file at https://angular.io/license
888
+ */
889
+ /**
890
+ * Class that represents a runtime error.
891
+ * Formats and outputs the error message in a consistent way.
892
+ *
893
+ * Example:
894
+ * ```
895
+ * throw new RuntimeError(
896
+ * RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
897
+ * ngDevMode && 'Injector has already been destroyed.');
898
+ * ```
899
+ *
900
+ * Note: the `message` argument contains a descriptive error message as a string in development
901
+ * mode (when the `ngDevMode` is defined). In production mode (after tree-shaking pass), the
902
+ * `message` argument becomes `false`, thus we account for it in the typings and the runtime logic.
903
+ */
904
+ class RuntimeError extends Error {
905
+ constructor(code, message) {
906
+ super(formatRuntimeError(code, message));
907
+ this.code = code;
908
+ }
909
+ }
910
+ /**
911
+ * Called to format a runtime error.
912
+ * See additional info on the `message` argument type in the `RuntimeError` class description.
913
+ */
914
+ function formatRuntimeError(code, message) {
915
+ // Error code might be a negative number, which is a special marker that instructs the logic to
916
+ // generate a link to the error details page on angular.io.
917
+ const fullCode = `NG0${Math.abs(code)}`;
918
+ let errorMessage = `${fullCode}${message ? ': ' + message.trim() : ''}`;
919
+ if (ngDevMode && code < 0) {
920
+ const addPeriodSeparator = !errorMessage.match(/[.,;!?]$/);
921
+ const separator = addPeriodSeparator ? '.' : '';
922
+ errorMessage =
923
+ `${errorMessage}${separator} Find more at ${ERROR_DETAILS_PAGE_BASE_URL}/${fullCode}`;
924
+ }
925
+ return errorMessage;
926
+ }
927
+
866
928
  /**
867
929
  * @license
868
930
  * Copyright Google LLC All Rights Reserved.
@@ -1791,68 +1853,6 @@ function initNgDevMode() {
1791
1853
  return false;
1792
1854
  }
1793
1855
 
1794
- /**
1795
- * @license
1796
- * Copyright Google LLC All Rights Reserved.
1797
- *
1798
- * Use of this source code is governed by an MIT-style license that can be
1799
- * found in the LICENSE file at https://angular.io/license
1800
- */
1801
- /**
1802
- * Base URL for the error details page.
1803
- *
1804
- * Keep the files below in full sync:
1805
- * - packages/compiler-cli/src/ngtsc/diagnostics/src/error_details_base_url.ts
1806
- * - packages/core/src/error_details_base_url.ts
1807
- */
1808
- const ERROR_DETAILS_PAGE_BASE_URL = 'https://angular.io/errors';
1809
-
1810
- /**
1811
- * @license
1812
- * Copyright Google LLC All Rights Reserved.
1813
- *
1814
- * Use of this source code is governed by an MIT-style license that can be
1815
- * found in the LICENSE file at https://angular.io/license
1816
- */
1817
- /**
1818
- * Class that represents a runtime error.
1819
- * Formats and outputs the error message in a consistent way.
1820
- *
1821
- * Example:
1822
- * ```
1823
- * throw new RuntimeError(
1824
- * RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
1825
- * ngDevMode && 'Injector has already been destroyed.');
1826
- * ```
1827
- *
1828
- * Note: the `message` argument contains a descriptive error message as a string in development
1829
- * mode (when the `ngDevMode` is defined). In production mode (after tree-shaking pass), the
1830
- * `message` argument becomes `false`, thus we account for it in the typings and the runtime logic.
1831
- */
1832
- class RuntimeError extends Error {
1833
- constructor(code, message) {
1834
- super(formatRuntimeError(code, message));
1835
- this.code = code;
1836
- }
1837
- }
1838
- /**
1839
- * Called to format a runtime error.
1840
- * See additional info on the `message` argument type in the `RuntimeError` class description.
1841
- */
1842
- function formatRuntimeError(code, message) {
1843
- // Error code might be a negative number, which is a special marker that instructs the logic to
1844
- // generate a link to the error details page on angular.io.
1845
- const fullCode = `NG0${Math.abs(code)}`;
1846
- let errorMessage = `${fullCode}${message ? ': ' + message.trim() : ''}`;
1847
- if (ngDevMode && code < 0) {
1848
- const addPeriodSeparator = !errorMessage.match(/[.,;!?]$/);
1849
- const separator = addPeriodSeparator ? '.' : '';
1850
- errorMessage =
1851
- `${errorMessage}${separator} Find more at ${ERROR_DETAILS_PAGE_BASE_URL}/${fullCode}`;
1852
- }
1853
- return errorMessage;
1854
- }
1855
-
1856
1856
  /**
1857
1857
  * @license
1858
1858
  * Copyright Google LLC All Rights Reserved.
@@ -2046,10 +2046,8 @@ function setCurrentInjector(injector) {
2046
2046
  }
2047
2047
  function injectInjectorOnly(token, flags = InjectFlags.Default) {
2048
2048
  if (_currentInjector === undefined) {
2049
- const errorMessage = (typeof ngDevMode === 'undefined' || ngDevMode) ?
2050
- `inject() must be called from an injection context (a constructor, a factory function or a field initializer)` :
2051
- '';
2052
- throw new RuntimeError(-203 /* RuntimeErrorCode.MISSING_INJECTION_CONTEXT */, errorMessage);
2049
+ throw new RuntimeError(-203 /* RuntimeErrorCode.MISSING_INJECTION_CONTEXT */, ngDevMode &&
2050
+ `inject() must be called from an injection context (a constructor, a factory function or a field initializer)`);
2053
2051
  }
2054
2052
  else if (_currentInjector === null) {
2055
2053
  return injectRootLimpMode(token, undefined, flags);
@@ -2065,22 +2063,17 @@ function ɵɵinject(token, flags = InjectFlags.Default) {
2065
2063
  * Throws an error indicating that a factory function could not be generated by the compiler for a
2066
2064
  * particular class.
2067
2065
  *
2068
- * This instruction allows the actual error message to be optimized away when ngDevMode is turned
2069
- * off, saving bytes of generated code while still providing a good experience in dev mode.
2070
- *
2071
2066
  * The name of the class is not mentioned here, but will be in the generated factory function name
2072
2067
  * and thus in the stack trace.
2073
2068
  *
2074
2069
  * @codeGenApi
2075
2070
  */
2076
2071
  function ɵɵinvalidFactoryDep(index) {
2077
- const msg = ngDevMode ?
2072
+ throw new RuntimeError(202 /* RuntimeErrorCode.INVALID_FACTORY_DEPENDENCY */, ngDevMode &&
2078
2073
  `This constructor is not compatible with Angular Dependency Injection because its dependency at index ${index} of the parameter list is invalid.
2079
2074
  This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator.
2080
2075
 
2081
- Please check that 1) the type for the parameter at index ${index} is correct and 2) the correct Angular decorators are defined for this class and its ancestors.` :
2082
- 'invalid';
2083
- throw new Error(msg);
2076
+ Please check that 1) the type for the parameter at index ${index} is correct and 2) the correct Angular decorators are defined for this class and its ancestors.`);
2084
2077
  }
2085
2078
  /**
2086
2079
  * Injects a token from the currently active injector.
@@ -2155,10 +2148,7 @@ function injectArgs(types) {
2155
2148
  const arg = resolveForwardRef(types[i]);
2156
2149
  if (Array.isArray(arg)) {
2157
2150
  if (arg.length === 0) {
2158
- const errorMessage = (typeof ngDevMode === 'undefined' || ngDevMode) ?
2159
- 'Arguments array must have arguments.' :
2160
- '';
2161
- throw new RuntimeError(900 /* RuntimeErrorCode.INVALID_DIFFER_INPUT */, errorMessage);
2151
+ throw new RuntimeError(900 /* RuntimeErrorCode.INVALID_DIFFER_INPUT */, ngDevMode && 'Arguments array must have arguments.');
2162
2152
  }
2163
2153
  let type = undefined;
2164
2154
  let flags = InjectFlags.Default;
@@ -3265,8 +3255,17 @@ var RendererStyleFlags3;
3265
3255
  function isProceduralRenderer(renderer) {
3266
3256
  return !!(renderer.listen);
3267
3257
  }
3258
+ let renderer3Enabled = false;
3259
+ function enableRenderer3() {
3260
+ renderer3Enabled = true;
3261
+ }
3268
3262
  const domRendererFactory3 = {
3269
3263
  createRenderer: (hostElement, rendererType) => {
3264
+ if (!renderer3Enabled) {
3265
+ throw new Error(ngDevMode ?
3266
+ `Renderer3 is not supported. This problem is likely caused by some component in the hierarchy was constructed without a correct parent injector.` :
3267
+ 'Renderer3 disabled');
3268
+ }
3270
3269
  return getDocument();
3271
3270
  }
3272
3271
  };
@@ -5481,7 +5480,7 @@ function reflectDependency(dep) {
5481
5480
  }
5482
5481
  else if (param instanceof Attribute) {
5483
5482
  if (param.attributeName === undefined) {
5484
- throw new Error(`Attribute name must be defined.`);
5483
+ throw new RuntimeError(204 /* RuntimeErrorCode.INVALID_INJECTION_TOKEN */, ngDevMode && `Attribute name must be defined.`);
5485
5484
  }
5486
5485
  meta.attribute = param.attributeName;
5487
5486
  }
@@ -6489,10 +6488,8 @@ function ɵɵsanitizeResourceUrl(unsafeResourceUrl) {
6489
6488
  if (allowSanitizationBypassAndThrow(unsafeResourceUrl, "ResourceURL" /* BypassType.ResourceUrl */)) {
6490
6489
  return trustedScriptURLFromStringBypass(unwrapSafeValue(unsafeResourceUrl));
6491
6490
  }
6492
- const errorMessage = (typeof ngDevMode === 'undefined' || ngDevMode) ?
6493
- 'unsafe value used in a resource URL context (see https://g.co/ng/security#xss)' :
6494
- '';
6495
- throw new RuntimeError(904 /* RuntimeErrorCode.UNSAFE_VALUE_IN_RESOURCE_URL */, errorMessage);
6491
+ throw new RuntimeError(904 /* RuntimeErrorCode.UNSAFE_VALUE_IN_RESOURCE_URL */, ngDevMode &&
6492
+ 'unsafe value used in a resource URL context (see https://g.co/ng/security#xss)');
6496
6493
  }
6497
6494
  /**
6498
6495
  * A `script` sanitizer which only lets trusted javascript through.
@@ -6514,10 +6511,7 @@ function ɵɵsanitizeScript(unsafeScript) {
6514
6511
  if (allowSanitizationBypassAndThrow(unsafeScript, "Script" /* BypassType.Script */)) {
6515
6512
  return trustedScriptFromStringBypass(unwrapSafeValue(unsafeScript));
6516
6513
  }
6517
- const errorMessage = (typeof ngDevMode === 'undefined' || ngDevMode) ?
6518
- 'unsafe value used in a script context' :
6519
- '';
6520
- throw new RuntimeError(905 /* RuntimeErrorCode.UNSAFE_VALUE_IN_SCRIPT */, errorMessage);
6514
+ throw new RuntimeError(905 /* RuntimeErrorCode.UNSAFE_VALUE_IN_SCRIPT */, ngDevMode && 'unsafe value used in a script context');
6521
6515
  }
6522
6516
  /**
6523
6517
  * A template tag function for promoting the associated constant literal to a
@@ -10129,7 +10123,7 @@ class ReflectiveKey {
10129
10123
  this.token = token;
10130
10124
  this.id = id;
10131
10125
  if (!token) {
10132
- throw new Error('Token must be defined!');
10126
+ throw new RuntimeError(208 /* RuntimeErrorCode.MISSING_INJECTION_TOKEN */, ngDevMode && 'Token must be defined!');
10133
10127
  }
10134
10128
  this.displayName = stringify(this.token);
10135
10129
  }
@@ -14200,6 +14194,7 @@ const NULL_INJECTOR = {
14200
14194
  function renderComponent(componentType /* Type as workaround for: Microsoft/TypeScript/issues/4881 */, opts = {}) {
14201
14195
  ngDevMode && publishDefaultGlobalUtils();
14202
14196
  ngDevMode && assertComponentType(componentType);
14197
+ enableRenderer3();
14203
14198
  const rendererFactory = opts.rendererFactory || domRendererFactory3;
14204
14199
  const sanitizer = opts.sanitizer || null;
14205
14200
  const componentDef = getComponentDef$1(componentType);
@@ -14387,10 +14382,8 @@ function ɵɵInheritDefinitionFeature(definition) {
14387
14382
  }
14388
14383
  else {
14389
14384
  if (superType.ɵcmp) {
14390
- const errorMessage = (typeof ngDevMode === 'undefined' || ngDevMode) ?
14391
- `Directives cannot inherit Components. Directive ${stringifyForError(definition.type)} is attempting to extend component ${stringifyForError(superType)}` :
14392
- '';
14393
- throw new RuntimeError(903 /* RuntimeErrorCode.INVALID_INHERITANCE */, errorMessage);
14385
+ throw new RuntimeError(903 /* RuntimeErrorCode.INVALID_INHERITANCE */, ngDevMode &&
14386
+ `Directives cannot inherit Components. Directive ${stringifyForError(definition.type)} is attempting to extend component ${stringifyForError(superType)}`);
14394
14387
  }
14395
14388
  // Don't use getComponentDef/getDirectiveDef. This logic relies on inheritance.
14396
14389
  superDef = superType.ɵdir;
@@ -19511,7 +19504,7 @@ function findLocaleData(locale) {
19511
19504
  if (parentLocale === 'en') {
19512
19505
  return localeEn;
19513
19506
  }
19514
- throw new Error(`Missing locale data for the locale "${locale}".`);
19507
+ throw new RuntimeError(701 /* RuntimeErrorCode.MISSING_LOCALE_DATA */, ngDevMode && `Missing locale data for the locale "${locale}".`);
19515
19508
  }
19516
19509
  /**
19517
19510
  * Retrieves the default currency code for the given locale.
@@ -22087,7 +22080,7 @@ class Version {
22087
22080
  /**
22088
22081
  * @publicApi
22089
22082
  */
22090
- const VERSION = new Version('14.1.0-next.0');
22083
+ const VERSION = new Version('14.1.0-next.3');
22091
22084
 
22092
22085
  /**
22093
22086
  * @license
@@ -22425,8 +22418,7 @@ class ViewRef {
22425
22418
  }
22426
22419
  attachToViewContainerRef() {
22427
22420
  if (this._appRef) {
22428
- const errorMessage = ngDevMode ? 'This view is already attached directly to the ApplicationRef!' : '';
22429
- throw new RuntimeError(902 /* RuntimeErrorCode.VIEW_ALREADY_ATTACHED */, errorMessage);
22421
+ throw new RuntimeError(902 /* RuntimeErrorCode.VIEW_ALREADY_ATTACHED */, ngDevMode && 'This view is already attached directly to the ApplicationRef!');
22430
22422
  }
22431
22423
  this._attachedToViewContainer = true;
22432
22424
  }
@@ -22436,8 +22428,7 @@ class ViewRef {
22436
22428
  }
22437
22429
  attachToAppRef(appRef) {
22438
22430
  if (this._attachedToViewContainer) {
22439
- const errorMessage = ngDevMode ? 'This view is already attached to a ViewContainer!' : '';
22440
- throw new RuntimeError(902 /* RuntimeErrorCode.VIEW_ALREADY_ATTACHED */, errorMessage);
22431
+ throw new RuntimeError(902 /* RuntimeErrorCode.VIEW_ALREADY_ATTACHED */, ngDevMode && 'This view is already attached to a ViewContainer!');
22441
22432
  }
22442
22433
  this._appRef = appRef;
22443
22434
  }
@@ -22758,10 +22749,18 @@ class EnvironmentNgModuleRefAdapter extends NgModuleRef$1 {
22758
22749
  /**
22759
22750
  * Create a new environment injector.
22760
22751
  *
22752
+ * Learn more about environment injectors in
22753
+ * [this guide](guide/standalone-components#environment-injectors).
22754
+ *
22755
+ * @param providers An array of providers.
22756
+ * @param parent A parent environment injector.
22757
+ * @param debugName An optional name for this injector instance, which will be used in error
22758
+ * messages.
22759
+ *
22761
22760
  * @publicApi
22762
22761
  * @developerPreview
22763
22762
  */
22764
- function createEnvironmentInjector(providers, parent = null, debugName = null) {
22763
+ function createEnvironmentInjector(providers, parent, debugName = null) {
22765
22764
  const adapter = new EnvironmentNgModuleRefAdapter(providers, parent, debugName);
22766
22765
  return adapter.injector;
22767
22766
  }
@@ -24716,7 +24715,7 @@ function patchModuleCompilation() {
24716
24715
  function isModuleWithProviders$1(value) {
24717
24716
  return value.ngModule !== undefined;
24718
24717
  }
24719
- function isNgModule(value) {
24718
+ function isNgModule$1(value) {
24720
24719
  return !!getNgModuleDef(value);
24721
24720
  }
24722
24721
 
@@ -25105,6 +25104,7 @@ function setScopeOnDeclaredComponents(moduleType, ngModule) {
25105
25104
  const declarations = flatten$1(ngModule.declarations || EMPTY_ARRAY);
25106
25105
  const transitiveScopes = transitiveScopesFor(moduleType);
25107
25106
  declarations.forEach(declaration => {
25107
+ declaration = resolveForwardRef(declaration);
25108
25108
  if (declaration.hasOwnProperty(NG_COMP_DEF)) {
25109
25109
  // A `ɵcmp` field exists - go ahead and patch the component directly.
25110
25110
  const component = declaration;
@@ -25138,7 +25138,7 @@ function patchComponentDefWithScope(componentDef, transitiveScopes) {
25138
25138
  * (either a NgModule or a standalone component / directive / pipe).
25139
25139
  */
25140
25140
  function transitiveScopesFor(type) {
25141
- if (isNgModule(type)) {
25141
+ if (isNgModule$1(type)) {
25142
25142
  return transitiveScopesForNgModule(type);
25143
25143
  }
25144
25144
  else if (isStandalone(type)) {
@@ -25222,7 +25222,7 @@ function transitiveScopesForNgModule(moduleType) {
25222
25222
  const exportedType = exported;
25223
25223
  // Either the type is a module, a pipe, or a component/directive (which may not have a
25224
25224
  // ɵcmp as it might be compiled asynchronously).
25225
- if (isNgModule(exportedType)) {
25225
+ if (isNgModule$1(exportedType)) {
25226
25226
  // When this module exports another, the exported module's exported directives and pipes are
25227
25227
  // added to both the compilation and exported scopes of this module.
25228
25228
  const exportedScope = transitiveScopesFor(exportedType);
@@ -25522,7 +25522,7 @@ class R3TestBedCompiler {
25522
25522
  // module's provider list.
25523
25523
  this.providerOverridesByModule = new Map();
25524
25524
  this.providerOverridesByToken = new Map();
25525
- this.moduleProvidersOverridden = new Set();
25525
+ this.scopesWithOverriddenProviders = new Set();
25526
25526
  this.testModuleRef = null;
25527
25527
  class DynamicTestModule {
25528
25528
  }
@@ -25693,7 +25693,7 @@ class R3TestBedCompiler {
25693
25693
  this.queueTypesFromModulesArray([moduleType]);
25694
25694
  this.compileTypesSync();
25695
25695
  this.applyProviderOverrides();
25696
- this.applyProviderOverridesToModule(moduleType);
25696
+ this.applyProviderOverridesInScope(moduleType);
25697
25697
  this.applyTransitiveScopes();
25698
25698
  }
25699
25699
  /**
@@ -25704,7 +25704,7 @@ class R3TestBedCompiler {
25704
25704
  this.queueTypesFromModulesArray([moduleType]);
25705
25705
  yield this.compileComponents();
25706
25706
  this.applyProviderOverrides();
25707
- this.applyProviderOverridesToModule(moduleType);
25707
+ this.applyProviderOverridesInScope(moduleType);
25708
25708
  this.applyTransitiveScopes();
25709
25709
  });
25710
25710
  }
@@ -25806,51 +25806,53 @@ class R3TestBedCompiler {
25806
25806
  this.seenComponents.clear();
25807
25807
  this.seenDirectives.clear();
25808
25808
  }
25809
- applyProviderOverridesToModule(moduleType) {
25809
+ /**
25810
+ * Applies provider overrides to a given type (either an NgModule or a standalone component)
25811
+ * and all imported NgModules and standalone components recursively.
25812
+ */
25813
+ applyProviderOverridesInScope(type) {
25810
25814
  var _a;
25811
- if (this.moduleProvidersOverridden.has(moduleType)) {
25815
+ const hasScope = isStandaloneComponent(type) || isNgModule(type);
25816
+ // The function can be re-entered recursively while inspecting dependencies
25817
+ // of an NgModule or a standalone component. Exit early if we come across a
25818
+ // type that can not have a scope (directive or pipe) or the type is already
25819
+ // processed earlier.
25820
+ if (!hasScope || this.scopesWithOverriddenProviders.has(type)) {
25812
25821
  return;
25813
25822
  }
25814
- this.moduleProvidersOverridden.add(moduleType);
25823
+ this.scopesWithOverriddenProviders.add(type);
25815
25824
  // NOTE: the line below triggers JIT compilation of the module injector,
25816
25825
  // which also invokes verification of the NgModule semantics, which produces
25817
25826
  // detailed error messages. The fact that the code relies on this line being
25818
25827
  // present here is suspicious and should be refactored in a way that the line
25819
25828
  // below can be moved (for ex. after an early exit check below).
25820
- const injectorDef = moduleType[ɵNG_INJ_DEF];
25829
+ const injectorDef = type[ɵNG_INJ_DEF];
25821
25830
  // No provider overrides, exit early.
25822
25831
  if (this.providerOverridesByToken.size === 0)
25823
25832
  return;
25824
- if (isStandaloneComponent(moduleType)) {
25833
+ if (isStandaloneComponent(type)) {
25825
25834
  // Visit all component dependencies and override providers there.
25826
- const def = getComponentDef(moduleType);
25835
+ const def = getComponentDef(type);
25827
25836
  const dependencies = maybeUnwrapFn((_a = def.dependencies) !== null && _a !== void 0 ? _a : []);
25828
25837
  for (const dependency of dependencies) {
25829
- // Proceed with examining dependencies recursively
25830
- // when a dependency is a standalone component or an NgModule.
25831
- // In AOT, the `dependencies` might also contain regular (NgModule-based)
25832
- // Component, Directive and Pipes. Skip them here, they are handled in a
25833
- // different location (in the `configureTestingModule` function).
25834
- if (isStandaloneComponent(dependency) || hasNgModuleDef(dependency)) {
25835
- this.applyProviderOverridesToModule(dependency);
25836
- }
25838
+ this.applyProviderOverridesInScope(dependency);
25837
25839
  }
25838
25840
  }
25839
25841
  else {
25840
25842
  const providers = [
25841
25843
  ...injectorDef.providers,
25842
- ...(this.providerOverridesByModule.get(moduleType) || [])
25844
+ ...(this.providerOverridesByModule.get(type) || [])
25843
25845
  ];
25844
25846
  if (this.hasProviderOverrides(providers)) {
25845
- this.maybeStoreNgDef(ɵNG_INJ_DEF, moduleType);
25846
- this.storeFieldOfDefOnType(moduleType, ɵNG_INJ_DEF, 'providers');
25847
+ this.maybeStoreNgDef(ɵNG_INJ_DEF, type);
25848
+ this.storeFieldOfDefOnType(type, ɵNG_INJ_DEF, 'providers');
25847
25849
  injectorDef.providers = this.getOverriddenProviders(providers);
25848
25850
  }
25849
25851
  // Apply provider overrides to imported modules recursively
25850
- const moduleDef = moduleType[ɵNG_MOD_DEF];
25852
+ const moduleDef = type[ɵNG_MOD_DEF];
25851
25853
  const imports = maybeUnwrapFn(moduleDef.imports);
25852
25854
  for (const importedModule of imports) {
25853
- this.applyProviderOverridesToModule(importedModule);
25855
+ this.applyProviderOverridesInScope(importedModule);
25854
25856
  }
25855
25857
  // Also override the providers on any ModuleWithProviders imports since those don't appear in
25856
25858
  // the moduleDef.
@@ -26088,7 +26090,7 @@ class R3TestBedCompiler {
26088
26090
  });
26089
26091
  });
26090
26092
  this.initialNgDefs.clear();
26091
- this.moduleProvidersOverridden.clear();
26093
+ this.scopesWithOverriddenProviders.clear();
26092
26094
  this.restoreComponentResolutionQueue();
26093
26095
  // Restore the locale ID to the default value, this shouldn't be necessary but we never know
26094
26096
  ɵsetLocaleId(ɵDEFAULT_LOCALE_ID);
@@ -26115,7 +26117,7 @@ class R3TestBedCompiler {
26115
26117
  providers,
26116
26118
  }, /* allowDuplicateDeclarationsInRoot */ true);
26117
26119
  // clang-format on
26118
- this.applyProviderOverridesToModule(this.testModuleType);
26120
+ this.applyProviderOverridesInScope(this.testModuleType);
26119
26121
  }
26120
26122
  get injector() {
26121
26123
  if (this._injector !== null) {
@@ -26216,6 +26218,9 @@ function getComponentDef(value) {
26216
26218
  function hasNgModuleDef(value) {
26217
26219
  return value.hasOwnProperty('ɵmod');
26218
26220
  }
26221
+ function isNgModule(value) {
26222
+ return hasNgModuleDef(value);
26223
+ }
26219
26224
  function maybeUnwrapFn(maybeFn) {
26220
26225
  return maybeFn instanceof Function ? maybeFn() : maybeFn;
26221
26226
  }