MCPcopy
hub / github.com/angular/angular / collectNativeNodes

Function collectNativeNodes

packages/core/src/render3/collect_native_nodes.ts:20–75  ·  view source on GitHub ↗
(
  tView: TView,
  lView: LView,
  tNode: TNode | null,
  result: any[],
  isProjection: boolean = false,
)

Source from the content-addressed store, hash-verified

18import {getLViewParent, unwrapRNode} from './util/view_utils';
19
20export function collectNativeNodes(
21 tView: TView,
22 lView: LView,
23 tNode: TNode | null,
24 result: any[],
25 isProjection: boolean = false,
26): any[] {
27 while (tNode !== null) {
28 // Let declarations don't have corresponding DOM nodes so we skip over them.
29 if (tNode.type === TNodeType.LetDeclaration) {
30 tNode = isProjection ? tNode.projectionNext : tNode.next;
31 continue;
32 }
33
34 ngDevMode &&
35 assertTNodeType(
36 tNode,
37 TNodeType.AnyRNode | TNodeType.AnyContainer | TNodeType.Projection | TNodeType.Icu,
38 );
39
40 const lNode = lView[tNode.index];
41 if (lNode !== null) {
42 result.push(unwrapRNode(lNode));
43 }
44
45 // A given lNode can represent either a native node or a LContainer (when it is a host of a
46 // ViewContainerRef). When we find a LContainer we need to descend into it to collect root nodes
47 // from the views in this container.
48 if (isLContainer(lNode)) {
49 collectNativeNodesInLContainer(lNode, result);
50 }
51
52 const tNodeType = tNode.type;
53 if (tNodeType & TNodeType.ElementContainer) {
54 collectNativeNodes(tView, lView, tNode.child, result);
55 } else if (tNodeType & TNodeType.Icu) {
56 const nextRNode = icuContainerIterate(tNode as TIcuContainerNode, lView);
57 let rNode: RNode | null;
58 while ((rNode = nextRNode())) {
59 result.push(rNode);
60 }
61 } else if (tNodeType & TNodeType.Projection) {
62 const nodesInSlot = getProjectionNodes(lView, tNode);
63 if (Array.isArray(nodesInSlot)) {
64 result.push(...nodesInSlot);
65 } else {
66 const parentView = getLViewParent(lView[DECLARATION_COMPONENT_VIEW])!;
67 ngDevMode && assertParentView(parentView);
68 collectNativeNodes(parentView[TVIEW], parentView, nodesInSlot, result, true);
69 }
70 }
71 tNode = isProjection ? tNode.projectionNext : tNode.next;
72 }
73
74 return result;
75}
76
77/**

Callers 5

rootNodesMethod · 0.90
deferBlockFinderFunction · 0.90
forLoopFinderFunction · 0.90
calcNumRootNodesFunction · 0.90

Calls 10

assertTNodeTypeFunction · 0.90
unwrapRNodeFunction · 0.90
isLContainerFunction · 0.90
icuContainerIterateFunction · 0.90
getProjectionNodesFunction · 0.90
getLViewParentFunction · 0.90
assertParentViewFunction · 0.90
isArrayMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…