@angular/core 14.0.2 → 14.0.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v14.0.2
2
+ * @license Angular v14.0.3
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -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);
@@ -2155,10 +2153,7 @@ function injectArgs(types) {
2155
2153
  const arg = resolveForwardRef(types[i]);
2156
2154
  if (Array.isArray(arg)) {
2157
2155
  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);
2156
+ throw new RuntimeError(900 /* RuntimeErrorCode.INVALID_DIFFER_INPUT */, ngDevMode && 'Arguments array must have arguments.');
2162
2157
  }
2163
2158
  let type = undefined;
2164
2159
  let flags = InjectFlags.Default;
@@ -6489,10 +6484,8 @@ function ɵɵsanitizeResourceUrl(unsafeResourceUrl) {
6489
6484
  if (allowSanitizationBypassAndThrow(unsafeResourceUrl, "ResourceURL" /* BypassType.ResourceUrl */)) {
6490
6485
  return trustedScriptURLFromStringBypass(unwrapSafeValue(unsafeResourceUrl));
6491
6486
  }
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);
6487
+ throw new RuntimeError(904 /* RuntimeErrorCode.UNSAFE_VALUE_IN_RESOURCE_URL */, ngDevMode &&
6488
+ 'unsafe value used in a resource URL context (see https://g.co/ng/security#xss)');
6496
6489
  }
6497
6490
  /**
6498
6491
  * A `script` sanitizer which only lets trusted javascript through.
@@ -6514,10 +6507,7 @@ function ɵɵsanitizeScript(unsafeScript) {
6514
6507
  if (allowSanitizationBypassAndThrow(unsafeScript, "Script" /* BypassType.Script */)) {
6515
6508
  return trustedScriptFromStringBypass(unwrapSafeValue(unsafeScript));
6516
6509
  }
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);
6510
+ throw new RuntimeError(905 /* RuntimeErrorCode.UNSAFE_VALUE_IN_SCRIPT */, ngDevMode && 'unsafe value used in a script context');
6521
6511
  }
6522
6512
  /**
6523
6513
  * A template tag function for promoting the associated constant literal to a
@@ -14387,10 +14377,8 @@ function ɵɵInheritDefinitionFeature(definition) {
14387
14377
  }
14388
14378
  else {
14389
14379
  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);
14380
+ throw new RuntimeError(903 /* RuntimeErrorCode.INVALID_INHERITANCE */, ngDevMode &&
14381
+ `Directives cannot inherit Components. Directive ${stringifyForError(definition.type)} is attempting to extend component ${stringifyForError(superType)}`);
14394
14382
  }
14395
14383
  // Don't use getComponentDef/getDirectiveDef. This logic relies on inheritance.
14396
14384
  superDef = superType.ɵdir;
@@ -22087,7 +22075,7 @@ class Version {
22087
22075
  /**
22088
22076
  * @publicApi
22089
22077
  */
22090
- const VERSION = new Version('14.0.2');
22078
+ const VERSION = new Version('14.0.3');
22091
22079
 
22092
22080
  /**
22093
22081
  * @license
@@ -22425,8 +22413,7 @@ class ViewRef {
22425
22413
  }
22426
22414
  attachToViewContainerRef() {
22427
22415
  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);
22416
+ throw new RuntimeError(902 /* RuntimeErrorCode.VIEW_ALREADY_ATTACHED */, ngDevMode && 'This view is already attached directly to the ApplicationRef!');
22430
22417
  }
22431
22418
  this._attachedToViewContainer = true;
22432
22419
  }
@@ -22436,8 +22423,7 @@ class ViewRef {
22436
22423
  }
22437
22424
  attachToAppRef(appRef) {
22438
22425
  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);
22426
+ throw new RuntimeError(902 /* RuntimeErrorCode.VIEW_ALREADY_ATTACHED */, ngDevMode && 'This view is already attached to a ViewContainer!');
22441
22427
  }
22442
22428
  this._appRef = appRef;
22443
22429
  }
@@ -24716,7 +24702,7 @@ function patchModuleCompilation() {
24716
24702
  function isModuleWithProviders$1(value) {
24717
24703
  return value.ngModule !== undefined;
24718
24704
  }
24719
- function isNgModule(value) {
24705
+ function isNgModule$1(value) {
24720
24706
  return !!getNgModuleDef(value);
24721
24707
  }
24722
24708
 
@@ -25139,7 +25125,7 @@ function patchComponentDefWithScope(componentDef, transitiveScopes) {
25139
25125
  * (either a NgModule or a standalone component / directive / pipe).
25140
25126
  */
25141
25127
  function transitiveScopesFor(type) {
25142
- if (isNgModule(type)) {
25128
+ if (isNgModule$1(type)) {
25143
25129
  return transitiveScopesForNgModule(type);
25144
25130
  }
25145
25131
  else if (isStandalone(type)) {
@@ -25223,7 +25209,7 @@ function transitiveScopesForNgModule(moduleType) {
25223
25209
  const exportedType = exported;
25224
25210
  // Either the type is a module, a pipe, or a component/directive (which may not have a
25225
25211
  // ɵcmp as it might be compiled asynchronously).
25226
- if (isNgModule(exportedType)) {
25212
+ if (isNgModule$1(exportedType)) {
25227
25213
  // When this module exports another, the exported module's exported directives and pipes are
25228
25214
  // added to both the compilation and exported scopes of this module.
25229
25215
  const exportedScope = transitiveScopesFor(exportedType);
@@ -25523,7 +25509,7 @@ class R3TestBedCompiler {
25523
25509
  // module's provider list.
25524
25510
  this.providerOverridesByModule = new Map();
25525
25511
  this.providerOverridesByToken = new Map();
25526
- this.moduleProvidersOverridden = new Set();
25512
+ this.scopesWithOverriddenProviders = new Set();
25527
25513
  this.testModuleRef = null;
25528
25514
  class DynamicTestModule {
25529
25515
  }
@@ -25694,7 +25680,7 @@ class R3TestBedCompiler {
25694
25680
  this.queueTypesFromModulesArray([moduleType]);
25695
25681
  this.compileTypesSync();
25696
25682
  this.applyProviderOverrides();
25697
- this.applyProviderOverridesToModule(moduleType);
25683
+ this.applyProviderOverridesInScope(moduleType);
25698
25684
  this.applyTransitiveScopes();
25699
25685
  }
25700
25686
  /**
@@ -25705,7 +25691,7 @@ class R3TestBedCompiler {
25705
25691
  this.queueTypesFromModulesArray([moduleType]);
25706
25692
  yield this.compileComponents();
25707
25693
  this.applyProviderOverrides();
25708
- this.applyProviderOverridesToModule(moduleType);
25694
+ this.applyProviderOverridesInScope(moduleType);
25709
25695
  this.applyTransitiveScopes();
25710
25696
  });
25711
25697
  }
@@ -25807,51 +25793,53 @@ class R3TestBedCompiler {
25807
25793
  this.seenComponents.clear();
25808
25794
  this.seenDirectives.clear();
25809
25795
  }
25810
- applyProviderOverridesToModule(moduleType) {
25796
+ /**
25797
+ * Applies provider overrides to a given type (either an NgModule or a standalone component)
25798
+ * and all imported NgModules and standalone components recursively.
25799
+ */
25800
+ applyProviderOverridesInScope(type) {
25811
25801
  var _a;
25812
- if (this.moduleProvidersOverridden.has(moduleType)) {
25802
+ const hasScope = isStandaloneComponent(type) || isNgModule(type);
25803
+ // The function can be re-entered recursively while inspecting dependencies
25804
+ // of an NgModule or a standalone component. Exit early if we come across a
25805
+ // type that can not have a scope (directive or pipe) or the type is already
25806
+ // processed earlier.
25807
+ if (!hasScope || this.scopesWithOverriddenProviders.has(type)) {
25813
25808
  return;
25814
25809
  }
25815
- this.moduleProvidersOverridden.add(moduleType);
25810
+ this.scopesWithOverriddenProviders.add(type);
25816
25811
  // NOTE: the line below triggers JIT compilation of the module injector,
25817
25812
  // which also invokes verification of the NgModule semantics, which produces
25818
25813
  // detailed error messages. The fact that the code relies on this line being
25819
25814
  // present here is suspicious and should be refactored in a way that the line
25820
25815
  // below can be moved (for ex. after an early exit check below).
25821
- const injectorDef = moduleType[ɵNG_INJ_DEF];
25816
+ const injectorDef = type[ɵNG_INJ_DEF];
25822
25817
  // No provider overrides, exit early.
25823
25818
  if (this.providerOverridesByToken.size === 0)
25824
25819
  return;
25825
- if (isStandaloneComponent(moduleType)) {
25820
+ if (isStandaloneComponent(type)) {
25826
25821
  // Visit all component dependencies and override providers there.
25827
- const def = getComponentDef(moduleType);
25822
+ const def = getComponentDef(type);
25828
25823
  const dependencies = maybeUnwrapFn((_a = def.dependencies) !== null && _a !== void 0 ? _a : []);
25829
25824
  for (const dependency of dependencies) {
25830
- // Proceed with examining dependencies recursively
25831
- // when a dependency is a standalone component or an NgModule.
25832
- // In AOT, the `dependencies` might also contain regular (NgModule-based)
25833
- // Component, Directive and Pipes. Skip them here, they are handled in a
25834
- // different location (in the `configureTestingModule` function).
25835
- if (isStandaloneComponent(dependency) || hasNgModuleDef(dependency)) {
25836
- this.applyProviderOverridesToModule(dependency);
25837
- }
25825
+ this.applyProviderOverridesInScope(dependency);
25838
25826
  }
25839
25827
  }
25840
25828
  else {
25841
25829
  const providers = [
25842
25830
  ...injectorDef.providers,
25843
- ...(this.providerOverridesByModule.get(moduleType) || [])
25831
+ ...(this.providerOverridesByModule.get(type) || [])
25844
25832
  ];
25845
25833
  if (this.hasProviderOverrides(providers)) {
25846
- this.maybeStoreNgDef(ɵNG_INJ_DEF, moduleType);
25847
- this.storeFieldOfDefOnType(moduleType, ɵNG_INJ_DEF, 'providers');
25834
+ this.maybeStoreNgDef(ɵNG_INJ_DEF, type);
25835
+ this.storeFieldOfDefOnType(type, ɵNG_INJ_DEF, 'providers');
25848
25836
  injectorDef.providers = this.getOverriddenProviders(providers);
25849
25837
  }
25850
25838
  // Apply provider overrides to imported modules recursively
25851
- const moduleDef = moduleType[ɵNG_MOD_DEF];
25839
+ const moduleDef = type[ɵNG_MOD_DEF];
25852
25840
  const imports = maybeUnwrapFn(moduleDef.imports);
25853
25841
  for (const importedModule of imports) {
25854
- this.applyProviderOverridesToModule(importedModule);
25842
+ this.applyProviderOverridesInScope(importedModule);
25855
25843
  }
25856
25844
  // Also override the providers on any ModuleWithProviders imports since those don't appear in
25857
25845
  // the moduleDef.
@@ -26089,7 +26077,7 @@ class R3TestBedCompiler {
26089
26077
  });
26090
26078
  });
26091
26079
  this.initialNgDefs.clear();
26092
- this.moduleProvidersOverridden.clear();
26080
+ this.scopesWithOverriddenProviders.clear();
26093
26081
  this.restoreComponentResolutionQueue();
26094
26082
  // Restore the locale ID to the default value, this shouldn't be necessary but we never know
26095
26083
  ɵsetLocaleId(ɵDEFAULT_LOCALE_ID);
@@ -26116,7 +26104,7 @@ class R3TestBedCompiler {
26116
26104
  providers,
26117
26105
  }, /* allowDuplicateDeclarationsInRoot */ true);
26118
26106
  // clang-format on
26119
- this.applyProviderOverridesToModule(this.testModuleType);
26107
+ this.applyProviderOverridesInScope(this.testModuleType);
26120
26108
  }
26121
26109
  get injector() {
26122
26110
  if (this._injector !== null) {
@@ -26217,6 +26205,9 @@ function getComponentDef(value) {
26217
26205
  function hasNgModuleDef(value) {
26218
26206
  return value.hasOwnProperty('ɵmod');
26219
26207
  }
26208
+ function isNgModule(value) {
26209
+ return hasNgModuleDef(value);
26210
+ }
26220
26211
  function maybeUnwrapFn(maybeFn) {
26221
26212
  return maybeFn instanceof Function ? maybeFn() : maybeFn;
26222
26213
  }