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

Function serializeI18nNode

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

* Process the given i18n node for serialization. * Returns the first RNode for the i18n node to begin hydration.

(
  lView: LView,
  serializedI18nBlock: SerializedI18nBlock,
  context: HydrationContext,
  node: I18nNode,
)

Source from the content-addressed store, hash-verified

250 * Returns the first RNode for the i18n node to begin hydration.
251 */
252function serializeI18nNode(
253 lView: LView,
254 serializedI18nBlock: SerializedI18nBlock,
255 context: HydrationContext,
256 node: I18nNode,
257): Node | null {
258 const maybeRNode = unwrapRNode(lView[node.index]!);
259 if (!maybeRNode || isDisconnectedRNode(maybeRNode)) {
260 serializedI18nBlock.disconnectedNodes.add(node.index - HEADER_OFFSET);
261 return null;
262 }
263
264 const rNode = maybeRNode as Node;
265 switch (node.kind) {
266 case I18nNodeKind.TEXT: {
267 processTextNodeBeforeSerialization(context, rNode);
268 break;
269 }
270
271 case I18nNodeKind.ELEMENT:
272 case I18nNodeKind.PLACEHOLDER: {
273 serializeI18nBlock(lView, serializedI18nBlock, context, node.children);
274 break;
275 }
276
277 case I18nNodeKind.ICU: {
278 const currentCase = lView[node.currentCaseLViewIndex] as number | null;
279 if (currentCase != null) {
280 // i18n uses a negative value to signal a change to a new case, so we
281 // need to invert it to get the proper value.
282 const caseIdx = currentCase < 0 ? ~currentCase : currentCase;
283 serializedI18nBlock.caseQueue.push(caseIdx);
284 serializeI18nBlock(lView, serializedI18nBlock, context, node.cases[caseIdx]);
285 }
286 break;
287 }
288 }
289
290 return getFirstNativeNodeForI18nNode(lView, node) as Node | null;
291}
292
293/**
294 * Helper function to get the first native node to begin hydrating

Callers 1

serializeI18nBlockFunction · 0.85

Calls 7

unwrapRNodeFunction · 0.90
isDisconnectedRNodeFunction · 0.90
serializeI18nBlockFunction · 0.85
addMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected