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

Function createTNodeAndAddOpCode

packages/core/src/render3/i18n/i18n_parse.ts:273–322  ·  view source on GitHub ↗

* Allocate space in i18n Range add create OpCode instruction to create a text or comment node. * * @param tView Current `TView` needed to allocate space in i18n range. * @param rootTNode Root `TNode` of the i18n block. This node determines if the new TNode will be * added as part of the `i18

(
  tView: TView,
  rootTNode: TNode | null,
  existingTNodes: TNode[],
  lView: LView,
  createOpCodes: I18nCreateOpCodes,
  text: string | null,
  isICU: boolean,
)

Source from the content-addressed store, hash-verified

271 * @param isICU true if a `Comment` node for ICU (instead of `Text`) node should be created.
272 */
273function createTNodeAndAddOpCode(
274 tView: TView,
275 rootTNode: TNode | null,
276 existingTNodes: TNode[],
277 lView: LView,
278 createOpCodes: I18nCreateOpCodes,
279 text: string | null,
280 isICU: boolean,
281): TNode {
282 const i18nNodeIdx = allocExpando(tView, lView, 1, null);
283 let opCode = i18nNodeIdx << I18nCreateOpCode.SHIFT;
284 let parentTNode = getCurrentParentTNode();
285
286 if (rootTNode === parentTNode) {
287 // FIXME(misko): A null `parentTNode` should represent when we fall of the `LView` boundary.
288 // (there is no parent), but in some circumstances (because we are inconsistent about how we set
289 // `previousOrParentTNode`) it could point to `rootTNode` So this is a work around.
290 parentTNode = null;
291 }
292 if (parentTNode === null) {
293 // If we don't have a parent that means that we can eagerly add nodes.
294 // If we have a parent than these nodes can't be added now (as the parent has not been created
295 // yet) and instead the `parentTNode` is responsible for adding it. See
296 // `TNode.insertBeforeIndex`
297 opCode |= I18nCreateOpCode.APPEND_EAGERLY;
298 }
299 if (isICU) {
300 opCode |= I18nCreateOpCode.COMMENT;
301 ensureIcuContainerVisitorLoaded(loadIcuContainerVisitor);
302 }
303 createOpCodes.push(opCode, text === null ? '' : text);
304 // We store `{{?}}` so that when looking at debug `TNodeType.template` we can see where the
305 // bindings are.
306 const tNode = createTNodeAtIndex(
307 tView,
308 i18nNodeIdx,
309 isICU ? TNodeType.Icu : TNodeType.Text,
310 text === null ? (ngDevMode ? '{{?}}' : '') : text,
311 null,
312 );
313 addTNodeAndUpdateInsertBeforeIndex(existingTNodes, tNode);
314 const tNodeIdx = tNode.index;
315 setCurrentTNode(tNode, false /* Text nodes are self closing */);
316 if (parentTNode !== null && rootTNode !== parentTNode) {
317 // We are a child of deeper node (rather than a direct child of `i18nStart` instruction.)
318 // We have to make sure to add ourselves to the parent.
319 setTNodeInsertBeforeIndex(parentTNode, tNodeIdx);
320 }
321 return tNode;
322}
323
324/**
325 * Processes text node in i18n block.

Calls 8

allocExpandoFunction · 0.90
getCurrentParentTNodeFunction · 0.90
createTNodeAtIndexFunction · 0.90
setCurrentTNodeFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected