MCPcopy Index your code
hub / github.com/angular/angular / createTNodeAndAddOpCode

Function createTNodeAndAddOpCode

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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…