@angular/core 16.0.0 → 16.0.1

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 (40) hide show
  1. package/esm2022/src/application_ref.mjs +60 -55
  2. package/esm2022/src/di/injectable.mjs +2 -1
  3. package/esm2022/src/di/metadata.mjs +6 -5
  4. package/esm2022/src/di/metadata_attr.mjs +2 -1
  5. package/esm2022/src/errors.mjs +1 -1
  6. package/esm2022/src/hydration/annotate.mjs +1 -1
  7. package/esm2022/src/hydration/api.mjs +2 -2
  8. package/esm2022/src/hydration/skip_hydration.mjs +12 -1
  9. package/esm2022/src/hydration/utils.mjs +9 -3
  10. package/esm2022/src/linker/element_ref.mjs +1 -1
  11. package/esm2022/src/linker/view_container_ref.mjs +16 -6
  12. package/esm2022/src/metadata/di.mjs +5 -4
  13. package/esm2022/src/metadata/directives.mjs +7 -7
  14. package/esm2022/src/metadata/ng_module.mjs +2 -1
  15. package/esm2022/src/render/api.mjs +1 -1
  16. package/esm2022/src/render3/definition.mjs +6 -3
  17. package/esm2022/src/render3/instructions/element_validation.mjs +2 -2
  18. package/esm2022/src/render3/instructions/shared.mjs +7 -3
  19. package/esm2022/src/render3/interfaces/document.mjs +6 -4
  20. package/esm2022/src/render3/interfaces/node.mjs +1 -1
  21. package/esm2022/src/render3/node_manipulation.mjs +7 -1
  22. package/esm2022/src/transfer_state.mjs +8 -7
  23. package/esm2022/src/util/assert.mjs +2 -5
  24. package/esm2022/src/version.mjs +1 -1
  25. package/esm2022/testing/src/logger.mjs +3 -3
  26. package/esm2022/testing/src/test_bed.mjs +4 -4
  27. package/fesm2022/core.mjs +181 -133
  28. package/fesm2022/core.mjs.map +1 -1
  29. package/fesm2022/rxjs-interop.mjs +1 -1
  30. package/fesm2022/rxjs-interop.mjs.map +1 -1
  31. package/fesm2022/testing.mjs +112 -71
  32. package/fesm2022/testing.mjs.map +1 -1
  33. package/index.d.ts +36 -30
  34. package/package.json +1 -1
  35. package/rxjs-interop/index.d.ts +1 -1
  36. package/schematics/migrations/guard-and-resolve-interfaces/bundle.js +13 -13
  37. package/schematics/migrations/remove-module-id/bundle.js +14 -14
  38. package/schematics/ng-generate/standalone-migration/bundle.js +415 -361
  39. package/schematics/ng-generate/standalone-migration/bundle.js.map +3 -3
  40. package/testing/index.d.ts +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v16.0.0
2
+ * @license Angular v16.0.1
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -941,10 +941,7 @@ function throwError(msg, actual, expected, comparison) {
941
941
  (comparison == null ? '' : ` [Expected=> ${expected} ${comparison} ${actual} <=Actual]`));
942
942
  }
943
943
  function assertDomNode(node) {
944
- // If we're in a worker, `Node` will not be defined.
945
- if (!(typeof Node !== 'undefined' && node instanceof Node) &&
946
- !(typeof node === 'object' && node != null &&
947
- node.constructor.name === 'WebWorkerRenderNode')) {
944
+ if (!(node instanceof Node)) {
948
945
  throwError(`The provided value must be an instance of a DOM Node but got ${stringify(node)}`);
949
946
  }
950
947
  }
@@ -2042,6 +2039,7 @@ function formatError(text, obj, injectorErrorName, source = null) {
2042
2039
  /**
2043
2040
  * Inject decorator and metadata.
2044
2041
  *
2042
+ * @Annotation
2045
2043
  * @publicApi
2046
2044
  */
2047
2045
  const Inject = attachInjectFlag(
@@ -2051,7 +2049,7 @@ makeParamDecorator('Inject', (token) => ({ token })), -1 /* DecoratorFlags.Injec
2051
2049
  /**
2052
2050
  * Optional decorator and metadata.
2053
2051
  *
2054
-
2052
+ * @Annotation
2055
2053
  * @publicApi
2056
2054
  */
2057
2055
  const Optional =
@@ -2061,7 +2059,7 @@ attachInjectFlag(makeParamDecorator('Optional'), 8 /* InternalInjectFlags.Option
2061
2059
  /**
2062
2060
  * Self decorator and metadata.
2063
2061
  *
2064
-
2062
+ * @Annotation
2065
2063
  * @publicApi
2066
2064
  */
2067
2065
  const Self =
@@ -2071,7 +2069,7 @@ attachInjectFlag(makeParamDecorator('Self'), 2 /* InternalInjectFlags.Self */);
2071
2069
  /**
2072
2070
  * `SkipSelf` decorator and metadata.
2073
2071
  *
2074
-
2072
+ * @Annotation
2075
2073
  * @publicApi
2076
2074
  */
2077
2075
  const SkipSelf =
@@ -2081,7 +2079,7 @@ attachInjectFlag(makeParamDecorator('SkipSelf'), 4 /* InternalInjectFlags.SkipSe
2081
2079
  /**
2082
2080
  * Host decorator and metadata.
2083
2081
  *
2084
-
2082
+ * @Annotation
2085
2083
  * @publicApi
2086
2084
  */
2087
2085
  const Host =
@@ -3156,7 +3154,7 @@ function getComponentId(componentDef) {
3156
3154
  // Example:
3157
3155
  // https://github.com/angular/components/blob/d9f82c8f95309e77a6d82fd574c65871e91354c2/src/material/core/option/option.ts#L248
3158
3156
  // https://github.com/angular/components/blob/285f46dc2b4c5b127d356cb7c4714b221f03ce50/src/material/legacy-core/option/option.ts#L32
3159
- const hashSelectors = [
3157
+ const hashSelectors = JSON.stringify([
3160
3158
  componentDef.selectors,
3161
3159
  componentDef.ngContentSelectors,
3162
3160
  componentDef.hostVars,
@@ -3166,12 +3164,15 @@ function getComponentId(componentDef) {
3166
3164
  componentDef.decls,
3167
3165
  componentDef.encapsulation,
3168
3166
  componentDef.standalone,
3167
+ componentDef.exportAs,
3168
+ componentDef.inputs,
3169
+ componentDef.outputs,
3169
3170
  // We cannot use 'componentDef.type.name' as the name of the symbol will change and will not
3170
3171
  // match in the server and browser bundles.
3171
3172
  Object.getOwnPropertyNames(componentDef.type.prototype),
3172
3173
  !!componentDef.contentQueries,
3173
3174
  !!componentDef.viewQuery,
3174
- ].join('|');
3175
+ ]);
3175
3176
  for (const char of hashSelectors) {
3176
3177
  hash = Math.imul(31, hash) + char.charCodeAt(0) << 0;
3177
3178
  }
@@ -6083,6 +6084,7 @@ function ɵɵinjectAttribute(attrNameToInject) {
6083
6084
  /**
6084
6085
  * Attribute decorator and metadata.
6085
6086
  *
6087
+ * @Annotation
6086
6088
  * @publicApi
6087
6089
  */
6088
6090
  const Attribute = makeParamDecorator('Attribute', (attributeName) => ({ attributeName, __NG_ELEMENT_ID__: () => ɵɵinjectAttribute(attributeName) }));
@@ -6383,7 +6385,7 @@ function isPropertyValid(element, propName, tagName, schemas) {
6383
6385
  if (schemas === null)
6384
6386
  return true;
6385
6387
  // The property is considered valid if the element matches the schema, it exists on the element,
6386
- // or it is synthetic, and we are in a browser context (web worker nodes should be skipped).
6388
+ // or it is synthetic.
6387
6389
  if (matchingSchemas(schemas, tagName) || propName in element || isAnimationProp(propName)) {
6388
6390
  return true;
6389
6391
  }
@@ -6525,6 +6527,59 @@ function matchingSchemas(schemas, tagName) {
6525
6527
  return false;
6526
6528
  }
6527
6529
 
6530
+ /**
6531
+ * The name of an attribute that can be added to the hydration boundary node
6532
+ * (component host node) to disable hydration for the content within that boundary.
6533
+ */
6534
+ const SKIP_HYDRATION_ATTR_NAME = 'ngSkipHydration';
6535
+ /**
6536
+ * Helper function to check if a given node has the 'ngSkipHydration' attribute
6537
+ */
6538
+ function hasNgSkipHydrationAttr(tNode) {
6539
+ const SKIP_HYDRATION_ATTR_NAME_LOWER_CASE = SKIP_HYDRATION_ATTR_NAME.toLowerCase();
6540
+ const attrs = tNode.mergedAttrs;
6541
+ if (attrs === null)
6542
+ return false;
6543
+ // only ever look at the attribute name and skip the values
6544
+ for (let i = 0; i < attrs.length; i += 2) {
6545
+ const value = attrs[i];
6546
+ // This is a marker, which means that the static attributes section is over,
6547
+ // so we can exit early.
6548
+ if (typeof value === 'number')
6549
+ return false;
6550
+ if (typeof value === 'string' && value.toLowerCase() === SKIP_HYDRATION_ATTR_NAME_LOWER_CASE) {
6551
+ return true;
6552
+ }
6553
+ }
6554
+ return false;
6555
+ }
6556
+ /**
6557
+ * Checks whether a TNode has a flag to indicate that it's a part of
6558
+ * a skip hydration block.
6559
+ */
6560
+ function hasInSkipHydrationBlockFlag(tNode) {
6561
+ return (tNode.flags & 128 /* TNodeFlags.inSkipHydrationBlock */) === 128 /* TNodeFlags.inSkipHydrationBlock */;
6562
+ }
6563
+ /**
6564
+ * Helper function that determines if a given node is within a skip hydration block
6565
+ * by navigating up the TNode tree to see if any parent nodes have skip hydration
6566
+ * attribute.
6567
+ *
6568
+ * TODO(akushnir): this function should contain the logic of `hasInSkipHydrationBlockFlag`,
6569
+ * there is no need to traverse parent nodes when we have a TNode flag (which would also
6570
+ * make this lookup O(1)).
6571
+ */
6572
+ function isInSkipHydrationBlock(tNode) {
6573
+ let currentTNode = tNode.parent;
6574
+ while (currentTNode) {
6575
+ if (hasNgSkipHydrationAttr(currentTNode)) {
6576
+ return true;
6577
+ }
6578
+ currentTNode = currentTNode.parent;
6579
+ }
6580
+ return false;
6581
+ }
6582
+
6528
6583
  /**
6529
6584
  * Flags for renderer-specific style modifiers.
6530
6585
  * @publicApi
@@ -7824,6 +7879,11 @@ function applyProjectionRecursive(renderer, action, lView, tProjectionNode, pare
7824
7879
  else {
7825
7880
  let nodeToProject = nodeToProjectOrRNodes;
7826
7881
  const projectedComponentLView = componentLView[PARENT];
7882
+ // If a parent <ng-content> is located within a skip hydration block,
7883
+ // annotate an actual node that is being projected with the same flag too.
7884
+ if (hasInSkipHydrationBlockFlag(tProjectionNode)) {
7885
+ nodeToProject.flags |= 128 /* TNodeFlags.inSkipHydrationBlock */;
7886
+ }
7827
7887
  applyNodes(renderer, action, nodeToProject, projectedComponentLView, parentRElement, beforeNode, true);
7828
7888
  }
7829
7889
  }
@@ -8124,7 +8184,7 @@ function ɵɵvalidateIframeAttribute(attrValue, tagName, attrName) {
8124
8184
  * When running ivy outside of a browser environment, it is necessary to call `setDocument()` to
8125
8185
  * tell ivy what the global `document` is.
8126
8186
  *
8127
- * Angular does this for us in each of the standard platforms (`Browser`, `Server`, and `WebWorker`)
8187
+ * Angular does this for us in each of the standard platforms (`Browser` and `Server`)
8128
8188
  * by calling `setDocument()` when providing the `DOCUMENT` token.
8129
8189
  */
8130
8190
  let DOCUMENT = undefined;
@@ -8151,12 +8211,13 @@ function getDocument() {
8151
8211
  else if (typeof document !== 'undefined') {
8152
8212
  return document;
8153
8213
  }
8214
+ throw new RuntimeError(210 /* RuntimeErrorCode.MISSING_DOCUMENT */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
8215
+ `The document object is not available in this context. Make sure the DOCUMENT injection token is provided.`);
8154
8216
  // No "document" can be found. This should only happen if we are running ivy outside Angular and
8155
8217
  // the current platform is not a browser. Since this is not a supported scenario at the moment
8156
8218
  // this should not happen in Angular apps.
8157
8219
  // Once we support running ivy outside of Angular we will need to publish `setDocument()` as a
8158
- // public API. Meanwhile we just return `undefined` and let the application fail.
8159
- return undefined;
8220
+ // public API.
8160
8221
  }
8161
8222
 
8162
8223
  /**
@@ -9862,7 +9923,9 @@ function makeStateKey(key) {
9862
9923
  }
9863
9924
  function initTransferState() {
9864
9925
  const transferState = new TransferState();
9865
- transferState.store = retrieveTransferredState(getDocument(), inject$1(APP_ID));
9926
+ if (inject$1(PLATFORM_ID) === 'browser') {
9927
+ transferState.store = retrieveTransferredState(getDocument(), inject$1(APP_ID));
9928
+ }
9866
9929
  return transferState;
9867
9930
  }
9868
9931
  /**
@@ -9951,17 +10014,16 @@ function retrieveTransferredState(doc, appId) {
9951
10014
  // Locate the script tag with the JSON data transferred from the server.
9952
10015
  // The id of the script tag is set to the Angular appId + 'state'.
9953
10016
  const script = doc.getElementById(appId + '-state');
9954
- let initialState = {};
9955
- if (script && script.textContent) {
10017
+ if (script?.textContent) {
9956
10018
  try {
9957
10019
  // Avoid using any here as it triggers lint errors in google3 (any is not allowed).
9958
- initialState = JSON.parse(unescapeTransferStateContent(script.textContent));
10020
+ return JSON.parse(unescapeTransferStateContent(script.textContent));
9959
10021
  }
9960
10022
  catch (e) {
9961
10023
  console.warn('Exception while restoring TransferState for app ' + appId, e);
9962
10024
  }
9963
10025
  }
9964
- return initialState;
10026
+ return {};
9965
10027
  }
9966
10028
 
9967
10029
  /** Encodes that the node lookup should start from the host node of this component. */
@@ -10080,6 +10142,12 @@ function getComponentLViewForHydration(viewRef) {
10080
10142
  if (isRootView(lView)) {
10081
10143
  lView = lView[HEADER_OFFSET];
10082
10144
  }
10145
+ // If a `ViewContainerRef` was injected in a component class, this resulted
10146
+ // in an LContainer creation at that location. In this case, the component
10147
+ // LView is in the LContainer's `HOST` slot.
10148
+ if (isLContainer(lView)) {
10149
+ lView = lView[HOST];
10150
+ }
10083
10151
  return lView;
10084
10152
  }
10085
10153
  function getTextNodeContent(node) {
@@ -10375,7 +10443,7 @@ class Version {
10375
10443
  /**
10376
10444
  * @publicApi
10377
10445
  */
10378
- const VERSION = new Version('16.0.0');
10446
+ const VERSION = new Version('16.0.1');
10379
10447
 
10380
10448
  // This default value is when checking the hierarchy for a token.
10381
10449
  //
@@ -10481,48 +10549,6 @@ class ErrorHandler {
10481
10549
  }
10482
10550
  }
10483
10551
 
10484
- /**
10485
- * The name of an attribute that can be added to the hydration boundary node
10486
- * (component host node) to disable hydration for the content within that boundary.
10487
- */
10488
- const SKIP_HYDRATION_ATTR_NAME = 'ngSkipHydration';
10489
- /**
10490
- * Helper function to check if a given node has the 'ngSkipHydration' attribute
10491
- */
10492
- function hasNgSkipHydrationAttr(tNode) {
10493
- const SKIP_HYDRATION_ATTR_NAME_LOWER_CASE = SKIP_HYDRATION_ATTR_NAME.toLowerCase();
10494
- const attrs = tNode.mergedAttrs;
10495
- if (attrs === null)
10496
- return false;
10497
- // only ever look at the attribute name and skip the values
10498
- for (let i = 0; i < attrs.length; i += 2) {
10499
- const value = attrs[i];
10500
- // This is a marker, which means that the static attributes section is over,
10501
- // so we can exit early.
10502
- if (typeof value === 'number')
10503
- return false;
10504
- if (typeof value === 'string' && value.toLowerCase() === SKIP_HYDRATION_ATTR_NAME_LOWER_CASE) {
10505
- return true;
10506
- }
10507
- }
10508
- return false;
10509
- }
10510
- /**
10511
- * Helper function that determines if a given node is within a skip hydration block
10512
- * by navigating up the TNode tree to see if any parent nodes have skip hydration
10513
- * attribute.
10514
- */
10515
- function isInSkipHydrationBlock(tNode) {
10516
- let currentTNode = tNode.parent;
10517
- while (currentTNode) {
10518
- if (hasNgSkipHydrationAttr(currentTNode)) {
10519
- return true;
10520
- }
10521
- currentTNode = currentTNode.parent;
10522
- }
10523
- return false;
10524
- }
10525
-
10526
10552
  /**
10527
10553
  * Internal token that specifies whether DOM reuse logic
10528
10554
  * during hydration is enabled.
@@ -10912,6 +10938,7 @@ function getInjectableMetadata(type, srcMeta) {
10912
10938
  /**
10913
10939
  * Injectable decorator and metadata.
10914
10940
  *
10941
+ * @Annotation
10915
10942
  * @publicApi
10916
10943
  */
10917
10944
  const Injectable = makeDecorator('Injectable', undefined, undefined, undefined, (type, meta) => compileInjectable(type, meta));
@@ -11468,6 +11495,10 @@ function createTNode(tView, tParent, type, index, value, attrs) {
11468
11495
  ngDevMode && ngDevMode.tNode++;
11469
11496
  ngDevMode && tParent && assertTNodeForTView(tParent, tView);
11470
11497
  let injectorIndex = tParent ? tParent.injectorIndex : -1;
11498
+ let flags = 0;
11499
+ if (isInSkipHydrationBlock$1()) {
11500
+ flags |= 128 /* TNodeFlags.inSkipHydrationBlock */;
11501
+ }
11471
11502
  const tNode = {
11472
11503
  type,
11473
11504
  index,
@@ -11478,7 +11509,7 @@ function createTNode(tView, tParent, type, index, value, attrs) {
11478
11509
  directiveStylingLast: -1,
11479
11510
  componentOffset: -1,
11480
11511
  propertyBindings: null,
11481
- flags: 0,
11512
+ flags,
11482
11513
  providerIndexes: 0,
11483
11514
  value: value,
11484
11515
  attrs: attrs,
@@ -23466,7 +23497,11 @@ const R3ViewContainerRef = class ViewContainerRef extends VE_ViewContainerRef {
23466
23497
  }
23467
23498
  const hydrationInfo = findMatchingDehydratedView(this._lContainer, templateRef.ssrId);
23468
23499
  const viewRef = templateRef.createEmbeddedViewImpl(context || {}, injector, hydrationInfo);
23469
- this.insertImpl(viewRef, index, !!hydrationInfo);
23500
+ // If there is a matching dehydrated view, but the host TNode is located in the skip
23501
+ // hydration block, this means that the content was detached (as a part of the skip
23502
+ // hydration logic) and it needs to be appended into the DOM.
23503
+ const skipDomInsertion = !!hydrationInfo && !hasInSkipHydrationBlockFlag(this._hostTNode);
23504
+ this.insertImpl(viewRef, index, skipDomInsertion);
23470
23505
  return viewRef;
23471
23506
  }
23472
23507
  createComponent(componentFactoryOrType, indexOrOptions, injector, projectableNodes, environmentInjector) {
@@ -23540,7 +23575,11 @@ const R3ViewContainerRef = class ViewContainerRef extends VE_ViewContainerRef {
23540
23575
  const dehydratedView = findMatchingDehydratedView(this._lContainer, componentDef?.id ?? null);
23541
23576
  const rNode = dehydratedView?.firstChild ?? null;
23542
23577
  const componentRef = componentFactory.create(contextInjector, projectableNodes, rNode, environmentInjector);
23543
- this.insertImpl(componentRef.hostView, index, !!dehydratedView);
23578
+ // If there is a matching dehydrated view, but the host TNode is located in the skip
23579
+ // hydration block, this means that the content was detached (as a part of the skip
23580
+ // hydration logic) and it needs to be appended into the DOM.
23581
+ const skipDomInsertion = !!dehydratedView && !hasInSkipHydrationBlockFlag(this._hostTNode);
23582
+ this.insertImpl(componentRef.hostView, index, skipDomInsertion);
23544
23583
  return componentRef;
23545
23584
  }
23546
23585
  insert(viewRef, index) {
@@ -23714,8 +23753,10 @@ function locateOrCreateAnchorNode(lContainer, hostLView, hostTNode, slotValue) {
23714
23753
  return;
23715
23754
  const hydrationInfo = hostLView[HYDRATION];
23716
23755
  const noOffsetIndex = hostTNode.index - HEADER_OFFSET;
23717
- const isNodeCreationMode = !hydrationInfo || isInSkipHydrationBlock(hostTNode) ||
23718
- isDisconnectedNode(hydrationInfo, noOffsetIndex);
23756
+ // TODO(akushnir): this should really be a single condition, refactor the code
23757
+ // to use `hasInSkipHydrationBlockFlag` logic inside `isInSkipHydrationBlock`.
23758
+ const skipHydration = isInSkipHydrationBlock(hostTNode) || hasInSkipHydrationBlockFlag(hostTNode);
23759
+ const isNodeCreationMode = !hydrationInfo || skipHydration || isDisconnectedNode(hydrationInfo, noOffsetIndex);
23719
23760
  // Regular creation mode.
23720
23761
  if (isNodeCreationMode) {
23721
23762
  return createAnchorNode(lContainer, hostLView, hostTNode, slotValue);
@@ -26127,7 +26168,7 @@ class TestBedImpl {
26127
26168
  }
26128
26169
  configureCompiler(config) {
26129
26170
  if (config.useJit != null) {
26130
- throw new Error('the Render3 compiler JiT mode is not configurable !');
26171
+ throw new Error('JIT compiler is not configurable via TestBed APIs.');
26131
26172
  }
26132
26173
  if (config.providers !== undefined) {
26133
26174
  this.compiler.setCompilerProviders(config.providers);
@@ -26135,7 +26176,7 @@ class TestBedImpl {
26135
26176
  return this;
26136
26177
  }
26137
26178
  configureTestingModule(moduleDef) {
26138
- this.assertNotInstantiated('R3TestBed.configureTestingModule', 'configure the test module');
26179
+ this.assertNotInstantiated('TestBed.configureTestingModule', 'configure the test module');
26139
26180
  // Trigger module scoping queue flush before executing other TestBed operations in a test.
26140
26181
  // This is needed for the first test invocation to ensure that globally declared modules have
26141
26182
  // their components scoped properly. See the `checkGlobalCompilationFinished` function
@@ -26189,7 +26230,7 @@ class TestBedImpl {
26189
26230
  return this;
26190
26231
  }
26191
26232
  overrideTemplateUsingTestingModule(component, template) {
26192
- this.assertNotInstantiated('R3TestBed.overrideTemplateUsingTestingModule', 'Cannot override template when the test module has already been instantiated');
26233
+ this.assertNotInstantiated('TestBed.overrideTemplateUsingTestingModule', 'Cannot override template when the test module has already been instantiated');
26193
26234
  this.compiler.overrideTemplateUsingTestingModule(component, template);
26194
26235
  return this;
26195
26236
  }