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

Function getFirstNativeNodeForI18nNode

packages/core/src/hydration/i18n.ts:297–317  ·  view source on GitHub ↗

* Helper function to get the first native node to begin hydrating * the given i18n node.

(lView: LView, node: I18nNode)

Source from the content-addressed store, hash-verified

295 * the given i18n node.
296 */
297function getFirstNativeNodeForI18nNode(lView: LView, node: I18nNode) {
298 const tView = lView[TVIEW];
299 const maybeTNode = tView.data[node.index];
300
301 if (isTNodeShape(maybeTNode)) {
302 // If the node is backed by an actual TNode, we can simply delegate.
303 return getFirstNativeNode(lView, maybeTNode);
304 } else if (node.kind === I18nNodeKind.ICU) {
305 // A nested ICU container won't have an actual TNode. In that case, we can use
306 // an iterator to find the first child.
307 const icuIterator = createIcuIterator(maybeTNode as TIcu, lView);
308 let rNode: RNode | null = icuIterator();
309
310 // If the ICU container has no nodes, then we use the ICU anchor as the node.
311 return rNode ?? unwrapRNode(lView[node.index]);
312 } else {
313 // Otherwise, the node is a text or trivial element in an ICU container,
314 // and we can just use the RNode directly.
315 return unwrapRNode(lView[node.index]) ?? null;
316 }
317}
318
319/**
320 * Describes shared data available during the hydration process.

Callers 1

serializeI18nNodeFunction · 0.85

Calls 4

isTNodeShapeFunction · 0.90
getFirstNativeNodeFunction · 0.90
createIcuIteratorFunction · 0.90
unwrapRNodeFunction · 0.90

Tested by

no test coverage detected