MCPcopy Create free account
hub / github.com/angular/angular / collectI18nNodesFromDom

Function collectI18nNodesFromDom

packages/core/src/hydration/i18n.ts:475–618  ·  view source on GitHub ↗
(
  context: I18nHydrationContext,
  state: I18nHydrationState,
  nodeOrNodes: I18nNode | I18nNode[],
)

Source from the content-addressed store, hash-verified

473}
474
475function collectI18nNodesFromDom(
476 context: I18nHydrationContext,
477 state: I18nHydrationState,
478 nodeOrNodes: I18nNode | I18nNode[],
479) {
480 if (Array.isArray(nodeOrNodes)) {
481 let nextState = state;
482 for (const node of nodeOrNodes) {
483 // Whenever a node doesn't directly follow the previous RNode, it
484 // is given a path. We need to resume collecting nodes from that location
485 // until and unless we find another disjoint node.
486 const targetNode = tryLocateRNodeByPath(
487 context.hydrationInfo,
488 context.lView,
489 node.index - HEADER_OFFSET,
490 );
491 if (targetNode) {
492 nextState = forkHydrationState(state, targetNode as Node);
493 }
494 collectI18nNodesFromDom(context, nextState, node);
495 }
496 } else {
497 if (context.disconnectedNodes.has(nodeOrNodes.index - HEADER_OFFSET)) {
498 // i18n nodes can be considered disconnected if e.g. they were projected.
499 // In that case, we have to make sure to skip over them.
500 return;
501 }
502
503 switch (nodeOrNodes.kind) {
504 case I18nNodeKind.TEXT: {
505 // Claim a text node for hydration
506 const currentNode = appendI18nNodeToCollection(context, state, nodeOrNodes);
507 setCurrentNode(state, currentNode && getNextSibling(currentNode));
508 break;
509 }
510
511 case I18nNodeKind.ELEMENT: {
512 // Recurse into the current element's children...
513 collectI18nNodesFromDom(
514 context,
515 forkHydrationState(state, state.currentNode && getFirstChild(state.currentNode)),
516 nodeOrNodes.children,
517 );
518
519 // And claim the parent element itself.
520 const currentNode = appendI18nNodeToCollection(context, state, nodeOrNodes);
521 setCurrentNode(state, currentNode && getNextSibling(currentNode));
522 break;
523 }
524
525 case I18nNodeKind.PLACEHOLDER: {
526 const noOffsetIndex = nodeOrNodes.index - HEADER_OFFSET;
527 const {hydrationInfo} = context;
528 const containerSize = getNgContainerSize(hydrationInfo, noOffsetIndex);
529
530 switch (nodeOrNodes.type) {
531 case I18nPlaceholderType.ELEMENT: {
532 // Hydration expects to find the head of the element.

Callers 1

Calls 13

tryLocateRNodeByPathFunction · 0.90
getNextSiblingFunction · 0.90
getFirstChildFunction · 0.90
getNgContainerSizeFunction · 0.90
assertNotEqualFunction · 0.90
forkHydrationStateFunction · 0.85
setCurrentNodeFunction · 0.85
skipSiblingNodesFunction · 0.85
isArrayMethod · 0.80
hasMethod · 0.65

Tested by

no test coverage detected