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

Function collectNativeNodes

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

Source from the content-addressed store, hash-verified

26import {getLViewParent, unwrapRNode} from './util/view_utils';
27
28export function collectNativeNodes(
29 tView: TView,
30 lView: LView,
31 tNode: TNode | null,
32 result: any[],
33 isProjection: boolean = false,
34): any[] {
35 if (tView.type === TViewType.Foreign) {
36 const headTNode = tView.firstChild!;
37 const tailTNode = headTNode.next!;
38 const head = unwrapRNode(lView[headTNode.index]);
39 const tail = unwrapRNode(lView[tailTNode.index]);
40
41 let current: RNode | null = head;
42 while (current !== null) {
43 result.push(current);
44 if (current === tail) break;
45 current = current.nextSibling;
46 }
47 return result;
48 }
49
50 while (tNode !== null) {
51 // Let declarations don't have corresponding DOM nodes so we skip over them.
52 if (tNode.type === TNodeType.LetDeclaration) {
53 tNode = isProjection ? tNode.projectionNext : tNode.next;
54 continue;
55 }
56
57 ngDevMode &&
58 assertTNodeType(
59 tNode,
60 TNodeType.AnyRNode | TNodeType.AnyContainer | TNodeType.Projection | TNodeType.Icu,
61 );
62
63 const lNode = lView[tNode.index];
64 if (lNode !== null) {
65 if (isLContainer(lNode)) {
66 const anchor = lNode[NATIVE];
67 // If this is a dynamic container (ViewContainerRef on an element), the HOST element is a
68 // distinct element node and must be pushed first (before the views are collected) to
69 // preserve DOM order.
70 if (anchor !== lNode[HOST]) {
71 result.push(unwrapRNode(lNode));
72 }
73
74 // Collect the root nodes from the views in this container.
75 if (!(lNode[FLAGS] & LContainerFlags.LogicalOnly)) {
76 collectNativeNodesInLContainer(lNode, result);
77 }
78
79 // The container's anchor comment node is always physically positioned after any views
80 // rendered inside the container, so we always push it here at the end.
81 result.push(anchor);
82 } else {
83 result.push(unwrapRNode(lNode));
84 }
85 }

Callers 6

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

Calls 10

unwrapRNodeFunction · 0.90
assertTNodeTypeFunction · 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