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

Function createTNodeAndAddOpCode

packages/core/src/render3/i18n/i18n_parse.ts:262–311  ·  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

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