@angular/core 14.2.0 → 14.2.2

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.2.0
2
+ * @license Angular v14.2.2
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -4898,7 +4898,7 @@ function injectAttributeImpl(tNode, attrNameToInject) {
4898
4898
  return null;
4899
4899
  }
4900
4900
  function notFoundValueOrThrow(notFoundValue, token, flags) {
4901
- if (flags & InjectFlags.Optional) {
4901
+ if ((flags & InjectFlags.Optional) || notFoundValue !== undefined) {
4902
4902
  return notFoundValue;
4903
4903
  }
4904
4904
  else {
@@ -4915,7 +4915,7 @@ function notFoundValueOrThrow(notFoundValue, token, flags) {
4915
4915
  * @returns the value from the injector or throws an exception
4916
4916
  */
4917
4917
  function lookupTokenUsingModuleInjector(lView, token, flags, notFoundValue) {
4918
- if (flags & InjectFlags.Optional && notFoundValue === undefined) {
4918
+ if ((flags & InjectFlags.Optional) && notFoundValue === undefined) {
4919
4919
  // This must be set or the NullInjector will throw for optional deps
4920
4920
  notFoundValue = null;
4921
4921
  }
@@ -6101,10 +6101,6 @@ function _sanitizeUrl(url) {
6101
6101
  }
6102
6102
  return 'unsafe:' + url;
6103
6103
  }
6104
- function sanitizeSrcset(srcset) {
6105
- srcset = String(srcset);
6106
- return srcset.split(',').map((srcset) => _sanitizeUrl(srcset.trim())).join(', ');
6107
- }
6108
6104
 
6109
6105
  /**
6110
6106
  * @license
@@ -6151,12 +6147,10 @@ const INLINE_ELEMENTS = merge(OPTIONAL_END_TAG_INLINE_ELEMENTS, tagSet('a,abbr,a
6151
6147
  const VALID_ELEMENTS = merge(VOID_ELEMENTS, BLOCK_ELEMENTS, INLINE_ELEMENTS, OPTIONAL_END_TAG_ELEMENTS);
6152
6148
  // Attributes that have href and hence need to be sanitized
6153
6149
  const URI_ATTRS = tagSet('background,cite,href,itemtype,longdesc,poster,src,xlink:href');
6154
- // Attributes that have special href set hence need to be sanitized
6155
- const SRCSET_ATTRS = tagSet('srcset');
6156
6150
  const HTML_ATTRS = tagSet('abbr,accesskey,align,alt,autoplay,axis,bgcolor,border,cellpadding,cellspacing,class,clear,color,cols,colspan,' +
6157
6151
  'compact,controls,coords,datetime,default,dir,download,face,headers,height,hidden,hreflang,hspace,' +
6158
6152
  'ismap,itemscope,itemprop,kind,label,lang,language,loop,media,muted,nohref,nowrap,open,preload,rel,rev,role,rows,rowspan,rules,' +
6159
- 'scope,scrolling,shape,size,sizes,span,srclang,start,summary,tabindex,target,title,translate,type,usemap,' +
6153
+ 'scope,scrolling,shape,size,sizes,span,srclang,srcset,start,summary,tabindex,target,title,translate,type,usemap,' +
6160
6154
  'valign,value,vspace,width');
6161
6155
  // Accessibility attributes as per WAI-ARIA 1.1 (W3C Working Draft 14 December 2018)
6162
6156
  const ARIA_ATTRS = tagSet('aria-activedescendant,aria-atomic,aria-autocomplete,aria-busy,aria-checked,aria-colcount,aria-colindex,' +
@@ -6172,7 +6166,7 @@ const ARIA_ATTRS = tagSet('aria-activedescendant,aria-atomic,aria-autocomplete,a
6172
6166
  // NB: Sanitization does not allow <form> elements or other active elements (<button> etc). Those
6173
6167
  // can be sanitized, but they increase security surface area without a legitimate use case, so they
6174
6168
  // are left out here.
6175
- const VALID_ATTRS = merge(URI_ATTRS, SRCSET_ATTRS, HTML_ATTRS, ARIA_ATTRS);
6169
+ const VALID_ATTRS = merge(URI_ATTRS, HTML_ATTRS, ARIA_ATTRS);
6176
6170
  // Elements whose content should not be traversed/preserved, if the elements themselves are invalid.
6177
6171
  //
6178
6172
  // Typically, `<invalid>Some content</invalid>` would traverse (and in this case preserve)
@@ -6255,8 +6249,6 @@ class SanitizingHtmlSerializer {
6255
6249
  // TODO(martinprobst): Special case image URIs for data:image/...
6256
6250
  if (URI_ATTRS[lower])
6257
6251
  value = _sanitizeUrl(value);
6258
- if (SRCSET_ATTRS[lower])
6259
- value = sanitizeSrcset(value);
6260
6252
  this.buf.push(' ', attrName, '="', encodeEntities(value), '"');
6261
6253
  }
6262
6254
  this.buf.push('>');
@@ -7643,7 +7635,7 @@ class Version {
7643
7635
  /**
7644
7636
  * @publicApi
7645
7637
  */
7646
- const VERSION = new Version('14.2.0');
7638
+ const VERSION = new Version('14.2.2');
7647
7639
 
7648
7640
  /**
7649
7641
  * @license
@@ -7946,7 +7938,7 @@ function getTemplateLocationDetails(lView) {
7946
7938
  * that the `CommonModule` should also be included.
7947
7939
  */
7948
7940
  const KNOWN_CONTROL_FLOW_DIRECTIVES = new Map([
7949
- ['ngIf', 'NgIf'], ['ngFor', 'NgForOf'], ['ngSwitchCase', 'NgSwitchCase'],
7941
+ ['ngIf', 'NgIf'], ['ngFor', 'NgFor'], ['ngSwitchCase', 'NgSwitchCase'],
7950
7942
  ['ngSwitchDefault', 'NgSwitchDefault']
7951
7943
  ]);
7952
7944
  /**
@@ -8695,16 +8687,16 @@ function getRootView(componentOrLView) {
8695
8687
  return lView;
8696
8688
  }
8697
8689
  /**
8698
- * Returns the `RootContext` instance that is associated with
8699
- * the application where the target is situated. It does this by walking the parent views until it
8700
- * gets to the root view, then getting the context off of that.
8690
+ * Returns the context information associated with the application where the target is situated. It
8691
+ * does this by walking the parent views until it gets to the root view, then getting the context
8692
+ * off of that.
8701
8693
  *
8702
8694
  * @param viewOrComponent the `LView` or component to get the root context for.
8703
8695
  */
8704
8696
  function getRootContext(viewOrComponent) {
8705
8697
  const rootView = getRootView(viewOrComponent);
8706
8698
  ngDevMode &&
8707
- assertDefined(rootView[CONTEXT], 'RootView has no context. Perhaps it is disconnected?');
8699
+ assertDefined(rootView[CONTEXT], 'Root view has no context. Perhaps it is disconnected?');
8708
8700
  return rootView[CONTEXT];
8709
8701
  }
8710
8702
  /**
@@ -12408,28 +12400,6 @@ function refreshView(tView, lView, templateFn, context) {
12408
12400
  leaveView();
12409
12401
  }
12410
12402
  }
12411
- function renderComponentOrTemplate(tView, lView, templateFn, context) {
12412
- const rendererFactory = lView[RENDERER_FACTORY];
12413
- // Check no changes mode is a dev only mode used to verify that bindings have not changed
12414
- // since they were assigned. We do not want to invoke renderer factory functions in that mode
12415
- // to avoid any possible side-effects.
12416
- const checkNoChangesMode = !!ngDevMode && isInCheckNoChangesMode();
12417
- const creationModeIsActive = isCreationMode(lView);
12418
- try {
12419
- if (!checkNoChangesMode && !creationModeIsActive && rendererFactory.begin) {
12420
- rendererFactory.begin();
12421
- }
12422
- if (creationModeIsActive) {
12423
- renderView(tView, lView, context);
12424
- }
12425
- refreshView(tView, lView, templateFn, context);
12426
- }
12427
- finally {
12428
- if (!checkNoChangesMode && !creationModeIsActive && rendererFactory.end) {
12429
- rendererFactory.end();
12430
- }
12431
- }
12432
- }
12433
12403
  function executeTemplate(tView, lView, templateFn, rf, context) {
12434
12404
  const prevSelectedIndex = getSelectedIndex();
12435
12405
  const isUpdatePhase = rf & 2 /* RenderFlags.Update */;
@@ -12500,7 +12470,7 @@ function saveResolvedLocalsInData(viewData, tNode, localRefExtractor = getNative
12500
12470
  * @param def ComponentDef
12501
12471
  * @returns TView
12502
12472
  */
12503
- function getOrCreateTComponentView(def) {
12473
+ function getOrCreateComponentTView(def) {
12504
12474
  const tView = def.tView;
12505
12475
  // Create a TView if there isn't one, or recreate it if the first create pass didn't
12506
12476
  // complete successfully since we can't know for sure whether it's in a usable shape.
@@ -13209,7 +13179,7 @@ function configureViewWithDirective(tView, tNode, lView, directiveIndex, def) {
13209
13179
  }
13210
13180
  function addComponentLogic(lView, hostTNode, def) {
13211
13181
  const native = getNativeByTNode(hostTNode, lView);
13212
- const tView = getOrCreateTComponentView(def);
13182
+ const tView = getOrCreateComponentTView(def);
13213
13183
  // Only component views should be added to the view tree directly. Embedded views are
13214
13184
  // accessed through their containers because they may be removed / re-added later.
13215
13185
  const rendererFactory = lView[RENDERER_FACTORY];
@@ -13536,63 +13506,32 @@ function markViewDirty(lView) {
13536
13506
  }
13537
13507
  return null;
13538
13508
  }
13539
- function tickRootContext(rootContext) {
13540
- for (let i = 0; i < rootContext.components.length; i++) {
13541
- const rootComponent = rootContext.components[i];
13542
- const lView = readPatchedLView(rootComponent);
13543
- // We might not have an `LView` if the component was destroyed.
13544
- if (lView !== null) {
13545
- const tView = lView[TVIEW];
13546
- renderComponentOrTemplate(tView, lView, tView.template, rootComponent);
13547
- }
13548
- }
13549
- }
13550
- function detectChangesInternal(tView, lView, context) {
13509
+ function detectChangesInternal(tView, lView, context, notifyErrorHandler = true) {
13551
13510
  const rendererFactory = lView[RENDERER_FACTORY];
13552
- if (rendererFactory.begin)
13511
+ // Check no changes mode is a dev only mode used to verify that bindings have not changed
13512
+ // since they were assigned. We do not want to invoke renderer factory functions in that mode
13513
+ // to avoid any possible side-effects.
13514
+ const checkNoChangesMode = !!ngDevMode && isInCheckNoChangesMode();
13515
+ if (!checkNoChangesMode && rendererFactory.begin)
13553
13516
  rendererFactory.begin();
13554
13517
  try {
13555
13518
  refreshView(tView, lView, tView.template, context);
13556
13519
  }
13557
13520
  catch (error) {
13558
- handleError(lView, error);
13521
+ if (notifyErrorHandler) {
13522
+ handleError(lView, error);
13523
+ }
13559
13524
  throw error;
13560
13525
  }
13561
13526
  finally {
13562
- if (rendererFactory.end)
13527
+ if (!checkNoChangesMode && rendererFactory.end)
13563
13528
  rendererFactory.end();
13564
13529
  }
13565
13530
  }
13566
- /**
13567
- * Synchronously perform change detection on a root view and its components.
13568
- *
13569
- * @param lView The view which the change detection should be performed on.
13570
- */
13571
- function detectChangesInRootView(lView) {
13572
- tickRootContext(lView[CONTEXT]);
13573
- }
13574
- function checkNoChangesInternal(tView, view, context) {
13575
- setIsInCheckNoChangesMode(true);
13576
- try {
13577
- detectChangesInternal(tView, view, context);
13578
- }
13579
- finally {
13580
- setIsInCheckNoChangesMode(false);
13581
- }
13582
- }
13583
- /**
13584
- * Checks the change detector on a root view and its components, and throws if any changes are
13585
- * detected.
13586
- *
13587
- * This is used in development mode to verify that running change detection doesn't
13588
- * introduce other changes.
13589
- *
13590
- * @param lView The view which the change detection should be checked on.
13591
- */
13592
- function checkNoChangesInRootView(lView) {
13531
+ function checkNoChangesInternal(tView, lView, context, notifyErrorHandler = true) {
13593
13532
  setIsInCheckNoChangesMode(true);
13594
13533
  try {
13595
- detectChangesInRootView(lView);
13534
+ detectChangesInternal(tView, lView, context, notifyErrorHandler);
13596
13535
  }
13597
13536
  finally {
13598
13537
  setIsInCheckNoChangesMode(false);
@@ -14085,11 +14024,17 @@ class RootViewRef extends ViewRef {
14085
14024
  this._view = _view;
14086
14025
  }
14087
14026
  detectChanges() {
14088
- detectChangesInRootView(this._view);
14027
+ const lView = this._view;
14028
+ const tView = lView[TVIEW];
14029
+ const context = lView[CONTEXT];
14030
+ detectChangesInternal(tView, lView, context, false);
14089
14031
  }
14090
14032
  checkNoChanges() {
14091
14033
  if (ngDevMode) {
14092
- checkNoChangesInRootView(this._view);
14034
+ const lView = this._view;
14035
+ const tView = lView[TVIEW];
14036
+ const context = lView[CONTEXT];
14037
+ checkNoChangesInternal(tView, lView, context, false);
14093
14038
  }
14094
14039
  }
14095
14040
  get context() {
@@ -14156,7 +14101,7 @@ class ChainedInjector {
14156
14101
  }
14157
14102
  }
14158
14103
  /**
14159
- * Render3 implementation of {@link viewEngine_ComponentFactory}.
14104
+ * ComponentFactory interface implementation.
14160
14105
  */
14161
14106
  class ComponentFactory extends ComponentFactory$1 {
14162
14107
  /**
@@ -14206,10 +14151,9 @@ class ComponentFactory extends ComponentFactory$1 {
14206
14151
  createElementNode(rendererFactory.createRenderer(null, this.componentDef), elementName, getNamespace(elementName));
14207
14152
  const rootFlags = this.componentDef.onPush ? 32 /* LViewFlags.Dirty */ | 256 /* LViewFlags.IsRoot */ :
14208
14153
  16 /* LViewFlags.CheckAlways */ | 256 /* LViewFlags.IsRoot */;
14209
- const rootContext = createRootContext();
14210
14154
  // Create the root view. Uses empty TView and ContentTemplate.
14211
14155
  const rootTView = createTView(0 /* TViewType.Root */, null, null, 1, 0, null, null, null, null, null);
14212
- const rootLView = createLView(null, rootTView, rootContext, rootFlags, null, null, rendererFactory, hostRenderer, sanitizer, rootViewInjector, null);
14156
+ const rootLView = createLView(null, rootTView, null, rootFlags, null, null, rendererFactory, hostRenderer, sanitizer, rootViewInjector, null);
14213
14157
  // rootView is the parent when bootstrapping
14214
14158
  // TODO(misko): it looks like we are entering view here but we don't really need to as
14215
14159
  // `renderView` does that. However as the code is written it is needed because
@@ -14253,7 +14197,8 @@ class ComponentFactory extends ComponentFactory$1 {
14253
14197
  // TODO: should LifecycleHooksFeature and other host features be generated by the compiler and
14254
14198
  // executed here?
14255
14199
  // Angular 5 reference: https://stackblitz.com/edit/lifecycle-hooks-vcref
14256
- component = createRootComponent(componentView, this.componentDef, rootLView, rootContext, [LifecycleHooksFeature]);
14200
+ component =
14201
+ createRootComponent(componentView, this.componentDef, rootLView, [LifecycleHooksFeature]);
14257
14202
  renderView(rootTView, rootLView, null);
14258
14203
  }
14259
14204
  finally {
@@ -14359,7 +14304,7 @@ function createRootComponentView(rNode, def, rootView, rendererFactory, hostRend
14359
14304
  }
14360
14305
  }
14361
14306
  const viewRenderer = rendererFactory.createRenderer(rNode, def);
14362
- const componentView = createLView(rootView, getOrCreateTComponentView(def), null, def.onPush ? 32 /* LViewFlags.Dirty */ : 16 /* LViewFlags.CheckAlways */, rootView[index], tNode, rendererFactory, viewRenderer, sanitizer || null, null, null);
14307
+ const componentView = createLView(rootView, getOrCreateComponentTView(def), null, def.onPush ? 32 /* LViewFlags.Dirty */ : 16 /* LViewFlags.CheckAlways */, rootView[index], tNode, rendererFactory, viewRenderer, sanitizer || null, null, null);
14363
14308
  if (tView.firstCreatePass) {
14364
14309
  diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, rootView), tView, def.type);
14365
14310
  markAsComponentHost(tView, tNode);
@@ -14373,12 +14318,13 @@ function createRootComponentView(rNode, def, rootView, rendererFactory, hostRend
14373
14318
  * Creates a root component and sets it up with features and host bindings.Shared by
14374
14319
  * renderComponent() and ViewContainerRef.createComponent().
14375
14320
  */
14376
- function createRootComponent(componentView, componentDef, rootLView, rootContext, hostFeatures) {
14321
+ function createRootComponent(componentView, componentDef, rootLView, hostFeatures) {
14377
14322
  const tView = rootLView[TVIEW];
14378
14323
  // Create directive instance with factory() and store at next index in viewData
14379
14324
  const component = instantiateRootComponent(tView, rootLView, componentDef);
14380
- rootContext.components.push(component);
14381
- componentView[CONTEXT] = component;
14325
+ // Root view only contains an instance of this component,
14326
+ // so we use a reference to that component instance as a context.
14327
+ componentView[CONTEXT] = rootLView[CONTEXT] = component;
14382
14328
  if (hostFeatures !== null) {
14383
14329
  for (const feature of hostFeatures) {
14384
14330
  feature(component, componentDef);
@@ -14402,9 +14348,6 @@ function createRootComponent(componentView, componentDef, rootLView, rootContext
14402
14348
  }
14403
14349
  return component;
14404
14350
  }
14405
- function createRootContext() {
14406
- return { components: [] };
14407
- }
14408
14351
  /**
14409
14352
  * Used to enable lifecycle hooks on the root component.
14410
14353
  *
@@ -21249,9 +21192,6 @@ function walkIcuTree(tView, tIcu, lView, sharedUpdateOpCodes, create, remove, up
21249
21192
  if (URI_ATTRS[lowerAttrName]) {
21250
21193
  generateBindingUpdateOpCodes(update, attr.value, newIndex, attr.name, 0, _sanitizeUrl);
21251
21194
  }
21252
- else if (SRCSET_ATTRS[lowerAttrName]) {
21253
- generateBindingUpdateOpCodes(update, attr.value, newIndex, attr.name, 0, sanitizeSrcset);
21254
- }
21255
21195
  else {
21256
21196
  generateBindingUpdateOpCodes(update, attr.value, newIndex, attr.name, 0, null);
21257
21197
  }
@@ -22220,7 +22160,7 @@ function getOwningComponent(elementOrDir) {
22220
22160
  */
22221
22161
  function getRootComponents(elementOrDir) {
22222
22162
  const lView = readPatchedLView(elementOrDir);
22223
- return lView !== null ? [...getRootContext(lView).components] : [];
22163
+ return lView !== null ? [getRootContext(lView)] : [];
22224
22164
  }
22225
22165
  /**
22226
22166
  * Retrieves an `Injector` associated with an element, component or directive instance.